打开应用程序时,用于在 Flutter 中发布的“flutter build apk”崩溃
“flutter build apk” for release in Flutter crashed when open the Apps
我已经在没有 flavor
的情况下设置构建应用程序发布,如 pro-guard、图标、清单等。我将目录 /android
迁移到 AndroidX
,因为如果没有,则在 运行 flutter build apk
时无法构建应用程序版本。所以我迁移它并成功。如下所示:
rifafauzi6@Anonymous-X456UR:/media/rifafauzi6/NM/Materi/BackUp Aplikasi Android/Flutter Project/vallery$ flutter build apk
You are building a fat APK that includes binaries for android-arm, android-arm64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Initializing gradle... 1.3s
Resolving dependencies... 2.9s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 59.6s
Built build/app/outputs/apk/release/app-release.apk (16.1MB).
然后成功后,我用两种方式安装:
使用 flutter 安装
rifafauzi6@Anonymous-X456UR:/media/rifafauzi6/NM/Materi/BackUp Aplikasi Android/Flutter Project/vallery$ flutter install
Initializing gradle... 1.3s
Resolving dependencies... 2.5s
Installing app.apk to SM A600G...
Installing build/app/outputs/apk/app.apk... 16.4s
使用手册,转到该目录并安装它。
我已经尝试 flutter build apk --split-per-abi
然后像上面一样我也用两种方式安装它。但是在显示启动画面之前打开应用程序时仍然崩溃。这是目录 main
:
中发布应用程序的清单
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my_package">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Vallery"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_vallery">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
这是flutter doctor -v
的输出:
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Linux, locale en_US.UTF-8)
• Flutter version 1.7.8+hotfix.4 at /media/rifafauzi6/NM/Materi/flutter
• Framework revision 20e59316b8 (8 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/rifafauzi6/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Android Studio (version 3.5)
• Android Studio at /opt/android-studio
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.38.0)
• VS Code at /usr/share/code
• Flutter extension version 3.3.0
[✓] Connected device (1 available)
• SM A600G • 5200e3e7f01e45f3 • android-arm • Android 9 (API 28)
• No issues found!
有人可以帮助我吗?因为我需要在上传到 Play 商店之前先将它安装(发布 apk)到真实设备中。
这是因为 proguard 等发布应用的设置项目而崩溃
尝试
flutter build apk --no-shrink
更新
flutter build apk --release --split-per-abi --no-shrink
这解决了我的问题
如果您生成了发布版本并且在您的 Android 设备上安装 apk 时它崩溃了,请确保您正确地按照 https://flutter.dev/docs/deployment/android 中提到的说明进行操作。
这涉及在 app/build.gradle
中进行必要的更改
正在添加 key.properties
文件
然后最终生成您的发布 apk。
对我来说是 gradle 版本。我变了
classpath 'com.android.tools.build:gradle:4.1.1'
至
classpath 'com.android.tools.build:gradle:3.5.0'
在android/build.gradle
.
在我的案例中,当我将下面的代码放入我的 build.gradle 文件时,发布模式 apk 应用崩溃问题修复
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
我已经在没有 flavor
的情况下设置构建应用程序发布,如 pro-guard、图标、清单等。我将目录 /android
迁移到 AndroidX
,因为如果没有,则在 运行 flutter build apk
时无法构建应用程序版本。所以我迁移它并成功。如下所示:
rifafauzi6@Anonymous-X456UR:/media/rifafauzi6/NM/Materi/BackUp Aplikasi Android/Flutter Project/vallery$ flutter build apk
You are building a fat APK that includes binaries for android-arm, android-arm64.
If you are deploying the app to the Play Store, it's recommended to use app bundles or split the APK to reduce the APK size.
To generate an app bundle, run:
flutter build appbundle --target-platform android-arm,android-arm64
Learn more on: https://developer.android.com/guide/app-bundle
To split the APKs per ABI, run:
flutter build apk --target-platform android-arm,android-arm64 --split-per-abi
Learn more on: https://developer.android.com/studio/build/configure-apk-splits#configure-abi-split
Initializing gradle... 1.3s
Resolving dependencies... 2.9s
Running Gradle task 'assembleRelease'...
Running Gradle task 'assembleRelease'... Done 59.6s
Built build/app/outputs/apk/release/app-release.apk (16.1MB).
然后成功后,我用两种方式安装:
使用 flutter 安装
rifafauzi6@Anonymous-X456UR:/media/rifafauzi6/NM/Materi/BackUp Aplikasi Android/Flutter Project/vallery$ flutter install
Initializing gradle... 1.3s
Resolving dependencies... 2.5s
Installing app.apk to SM A600G...
Installing build/app/outputs/apk/app.apk... 16.4s
使用手册,转到该目录并安装它。
我已经尝试 flutter build apk --split-per-abi
然后像上面一样我也用两种方式安装它。但是在显示启动画面之前打开应用程序时仍然崩溃。这是目录 main
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my_package">
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
calls FlutterMain.startInitialization(this); in its onCreate method.
In most cases you can leave this as-is, but you if you want to provide
additional functionality it is fine to subclass or reimplement
FlutterApplication and put your custom class here. -->
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="Vallery"
android:usesCleartextTraffic="true"
android:icon="@mipmap/ic_vallery">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
android:theme="@style/LaunchTheme"
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
android:hardwareAccelerated="true"
android:windowSoftInputMode="adjustResize">
<!-- This keeps the window background of the activity showing
until Flutter renders its first frame. It can be removed if
there is no splash screen (such as the default splash screen
defined in @style/LaunchTheme). -->
<meta-data
android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
android:value="true" />
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
这是flutter doctor -v
的输出:
[✓] Flutter (Channel stable, v1.7.8+hotfix.4, on Linux, locale en_US.UTF-8)
• Flutter version 1.7.8+hotfix.4 at /media/rifafauzi6/NM/Materi/flutter
• Framework revision 20e59316b8 (8 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /home/rifafauzi6/Android/Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.2
• Java binary at: /opt/android-studio/jre/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Android Studio (version 3.5)
• Android Studio at /opt/android-studio
• Flutter plugin version 39.0.3
• Dart plugin version 191.8423
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] VS Code (version 1.38.0)
• VS Code at /usr/share/code
• Flutter extension version 3.3.0
[✓] Connected device (1 available)
• SM A600G • 5200e3e7f01e45f3 • android-arm • Android 9 (API 28)
• No issues found!
有人可以帮助我吗?因为我需要在上传到 Play 商店之前先将它安装(发布 apk)到真实设备中。
这是因为 proguard 等发布应用的设置项目而崩溃
尝试
flutter build apk --no-shrink
更新
flutter build apk --release --split-per-abi --no-shrink
这解决了我的问题
如果您生成了发布版本并且在您的 Android 设备上安装 apk 时它崩溃了,请确保您正确地按照 https://flutter.dev/docs/deployment/android 中提到的说明进行操作。
这涉及在 app/build.gradle
正在添加 key.properties
文件
然后最终生成您的发布 apk。
对我来说是 gradle 版本。我变了
classpath 'com.android.tools.build:gradle:4.1.1'
至
classpath 'com.android.tools.build:gradle:3.5.0'
在android/build.gradle
.
在我的案例中,当我将下面的代码放入我的 build.gradle 文件时,发布模式 apk 应用崩溃问题修复
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig signingConfigs.release
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}