赞
踩
打包之前需要先不配置不然会报错 Execution failed for task ‘:app:mergeReleaseResources’.
APP目录下的build.gradle
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
如图
在android/app/src目录下的build.gradle配置
在这两个地方配置就可以 比如安卓应用商店是安卓targetSdkVersion api 30
defaultConfig {
applicationId "com.example.tianxi_user"
minSdkVersion flutter.minSdkVersion //最低兼容的安卓版本,flutter中默认是16
targetSdkVersion flutter.targetSdkVersion //应用适配的安卓版本 flutter中默认是33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
ndk {
//设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so)
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a", "x86","x86_64"
// biFilters "armeabi", "armeabi-v7a", "arm64-v8a","x86","x86_64"
}
}
flutter\packages\flutter_tools\gradle flutter.gradle 修改这里的配置 class FlutterExtension { /** Sets the compileSdkVersion used by default in Flutter app projects. */ static int compileSdkVersion = 33 /** Sets the minSdkVersion used by default in Flutter app projects. */ static int minSdkVersion = 16 /** Sets the targetSdkVersion used by default in Flutter app projects. */ static int targetSdkVersion = 33 /** * Sets the ndkVersion used by default in Flutter app projects. * Chosen as default version of the AGP version below as found in * https://developer.android.com/studio/projects/install-ndk#default-ndk-per-agp */ static String ndkVersion = "23.1.7779620" /** * Specifies the relative directory to the Flutter project directory. * In an app project, this is ../.. since the app's build.gradle is under android/app. */ String source /** Allows to override the target file. Otherwise, the target is lib/main.dart. */ String target }
使用 keytool 生成签名证书,placement certificate
keytool -genkey -v -keystore xxx(项目名).keystore -alias xxx(项目名) -keyalg RSA -keysize 2048 -validity 10000 -storepass (storePassword密码) -keypass (keyPassword密码)
根据提示生成证书keystore
android { ... signingConfigs { release { keyAlias 'text' keyPassword '***' storeFile file('text.keystore ') storePassword '***' } } buildTypes { ... release { signingConfig signingConfigs.release } } }
填入 keystore 的密码。
最后使用 flutter build apk --release 进行签名打包。
现在很多安卓应用商店只支持64位 安卓api30以上的。这里要调整下
只支持64位:flutter build apk --target-platform android-arm64
支持32位:flutter build apk --target-platform=android-arm
同时支持64位和32位:flutter build apk
在Android Studio中 打开安卓目录
修改文件,把下面代码注释,在flutter中运行的时候放开
subprojects {
// // 把这行注释掉,在flutter运行的时候,记得取消这行的注释
// project.buildDir = "${rootProject.buildDir}/${project.name}"
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。