打包命令
flutter build apk --release --dart-define=APP_CHANNEL=guanwang --target-platform android-arm64,android-arm --split-per-abi -v
命令解析
| 命令 | 解释 |
|---|---|
| --release | release包 |
| --dart-define | 修改dart文件String.fromEnvironment('APP_CHANNEL', defaultValue: 'ios');获取的值 |
| --target-platform android-arm64,android-arm | 打包打入android-arm64-v8a,android-armeabi-v7a |
| --split-per-abi | 拆分成target-platform规定的不同包 |
| -v,--verbose | 命令运行时输出详细信息 |
遇到的问题
执行命令的时候输出
[ ] FAILURE: Build failed with an exception.
[ ] * What went wrong:
[ ] A problem occurred evaluating root project 'android'.
[ ] > A problem occurred configuring project ':app'.
[ ] > Conflicting configuration : 'armeabi-v7a,arm64-v8a' in ndk abiFilters cannot be present when splits abi
filters are set : armeabi-v7a,arm64-v8a
[ ] * Try:
[ ] > Run with --stacktrace option to get the stack trace.
[ ] > Run with --info or --debug option to get more log output.
[ ] > Run with --scan to get full insights.
[ ] * Get more help at https://help.gradle.org
[ ] BUILD FAILED in 4s
错误原因:是在Android项目里配置了ndk的abiFilters内容,和打包命令--split-per-abi冲突了。
解决办法:注释defaultConfig中ndk节点的内容
defaultConfig {
ndk {
//屏蔽掉下面一行
//abiFilters 'armeabi-v7a', 'arm64-v8a'/*'armeabi','x86', 'x86_64', 'mips', 'mips64',*/
}
}