分享

Flutter Android 打包App

 黄三岁大爱人生 2021-01-25

1、检查App Manifest

更改应用名称和应用图标

<app dir>/android/app/src/main/AndroidManifest.xml

  1. //是用来设置所有activity属于哪个application的,默认是android.app.Application。
  2. android:name='io.flutter.app.FlutterApplication'
  3. //app 显示名
  4. android:label='test_app'
  5. //app 图标
  6. android:icon='@mipmap/ic_launcher'>

2、查看构建配置

<app dir>/android/app/build.gradle

  1. defaultConfig:
  2. applicationId: 指定始终唯一的 (Application Id)appid
  3. versionCode & versionName: 指定应用程序版本号和版本号字符串。
  4. minSdkVersion & targetSdkVersion: 指定最低的API级别以及应用程序设计运行的API级别。

3、添加启动图标

<app dir>/android/app/src/main/res/mipmap-****

4、app签名

1)、创建keystore

如果存在keystore请跳至下一步。

keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

改为

keytool -genkey -v -keystore e:\key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key

2)、引用应用程序中的keystore

创建 <app dir>/android/key.properties 文件

storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile=<location of the key store file, e.g. /Users/<user name>/key.jks>

3)、gradle中配置签名

<app dir>/android/app/build.gradle

  1. android {
  2. 上添加
  3. def keystorePropertiesFile = rootProject.file('key.properties')
  4. def keystoreProperties = new Properties()
  5. keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
  1. buildTypes {
  2. release {
  3. // TODO: Add your own signing config for the release build.
  4. // Signing with the debug keys for now, so `flutter run --release` works.
  5. signingConfig signingConfigs.debug
  6. }
  7. }
  8. 替换为
  9. signingConfigs {
  10. release {
  11. keyAlias keystoreProperties['keyAlias']
  12. keyPassword keystoreProperties['keyPassword']
  13. storeFile file(keystoreProperties['storeFile'])
  14. storePassword keystoreProperties['storePassword']
  15. }
  16. }
  17. buildTypes {
  18. release {
  19. signingConfig signingConfigs.release
  20. }
  21. }

5、打包apk

flutter build apk

打好包的发布apk位于 <app dir>/build/app/outputs/apk/release/app-release.apk

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多