一、生成androd签名证书
Android studio的Build > Grenerate Signed Bundle
选择apk
点击Create New
录入对应的签名信息;点击确定
对应盘符下就会生成一个签名文件
二、拷贝签名到项目目录
将签名文件拷入项目的app目录下
三、配置 greadle.properties
在greadle.properties中增加如下配置(对应上一步生成的签名证书的别名,密码)
MYAPP_RELEASE_KEY_ALIAS=android_keystore # 别名
MYAPP_RELEASE_KEY_PASSWORD=123456 # 别名密码
MYAPP_RELEASE_STORE_PASSWORD=123456 # 证书密码
MYAPP_RELEASE_STORE_FILE=android_keystore.jks # 证书路径
四、配置build.gradle(Module:app)
在android下增加如下配置(注意release中配置的value一定要对应到上一步greadle.properties中配置的key,否则编译报错)
android {
# 省略其他配置 ....
# 新增配置
signingConfigs{
release{
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
# 省略其他配置 ....
# 新增配置
signingConfig signingConfigs.release
}
}
# 省略其他配置 ....
}
五、解决 Compatible side by side NDK version was not found.
配置完成后
使用android studio运行gradlew assembleRelease
打包发布android与flutter混合开发项目提示
D:learnFlutterflutter_hybridFlutterhybridandroid>gradlew assembleRelease
Compatible side by side NDK version was not found.
Unable to strip library 'D:learnFlutterflutter_hybridFlutterhybridandroidappuildintermediatesmerged_native_libs
eleaseoutlibarm64-v8alibapp.so' due to missing strip tool for ABI 'ARM64_V8A'. Packaging it as is.
Unable to strip library 'D:learnFlutterflutter_hybridFlutterhybridandroidappuildintermediatesmerged_native_libs
eleaseoutlibarmeabi-v7alibflutter.so' due to missing strip tool for ABI 'ARMEABI_V7A'. Packaging it as is.
62 actionable tasks: 59 executed, 3 up-to-date
Android studio的File->Project Structure窗口下进行NDK的相关下载
等待下载完成
现在完成后会自动同步ndk路径
点击OK后gradle会自动同步
六、解决 Compatible side by side NDK version was not found.
有提示了另一个错误
Compatible side by side NDK version was not found.
Unable to strip library 'D:learnFlutterflutter_hybridFlutterhybridandroidappuildintermediatesmerged_native_libs
eleaseoutlibarm64-v8alibapp.so' due to missing strip tool for ABI 'ARM64_V8A'. Packaging it as is.
Unable to strip library 'D:learnFlutterflutter_hybridFlutterhybridandroidappuildintermediatesmerged_native_libs
eleaseoutlibarmeabi-v7alibflutter.so' due to missing strip tool for ABI 'ARMEABI_V7A'. Packaging it as is.
62 actionable tasks: 59 executed, 3 up-to-date
D:learnFlutterflutter_hybridFlutterhybridandroid>gradlew assembleRelease
62 actionable tasks: 8 executed, 54 up-to-date
根据android官网提示进行ndk版本配置
到安装的ndk目录下找到souce.propertites打开
根据
在build.properties中配置ndk版本
配置完成gradle自动同步
七、最后执行 gradlew assembleRelease打包
终于没有提到错误了
D:learnFlutterflutter_hybridFlutterhybridandroid>gradlew assembleRelease
62 actionable tasks: 5 executed, 57 up-to-date
在project 目录下也看见了久违的app-release.apk
最后就可以将这个apk发到真机安装了