Flutter_app

mac下Android Studio中flutter打包apk

2019-07-12  本文已影响0人  xmb

参考文章:# AndroidStudio中Flutter打包APK

步骤:

  1. 生成签名文件:
keytool -genkey -v -keystore ~/sign.jks -keyalg RSA -keysize 2048 -validity 10000 -alias sign

结果:

输入密钥库口令:  
再次输入新口令: 
您的名字与姓氏是什么?
  [Unknown]:  yuanzhiying
您的组织单位名称是什么?
  [Unknown]:  gongsi
您的组织名称是什么?
  [Unknown]:  gongsi
您所在的城市或区域名称是什么?
  [Unknown]:  beijing
您所在的省/市/自治区名称是什么?
  [Unknown]:  beijing
该单位的双字母国家/地区代码是什么?
  [Unknown]:  CN
CN=yuanzhiying, OU=gongsi, O=gongsi, L=beijing, ST=beijing, C=CN是否正确?
  [否]:  Y

正在为以下对象生成 2,048 位RSA密钥对和自签名证书 (SHA256withRSA) (有效期为 10,000 天):
     CN=yuanzhiying, OU=gongsi, O=gongsi, L=beijing, ST=beijing, C=CN
[正在存储/Users/yuanzhiying/sign.jks]
WX20190712-135013@2x.png
  1. 查看证书的SHA1
keytool -list -v -keystore ~/sign.jks -alias sign -storepass 123456 -keypass 123456
  1. Android Studioflutter项目目录/android/app下创建文件夹key,将生成的sign.jks文件拖放到key文件夹下。
    WX20190712-135553@2x.png
  2. flutter项目目录androidnew - File创建文件key.properties,并添加以下内容:
storePassword=123456
keyPassword=123456
keyAlias=sign
storeFile=key/sign.jks
WX20190712-135918@2x.png
  1. 打开/android/app/build.gradle文件,把以下内容
android {

替换为

def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

android {

然后再把以下内容

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.debug
        }
    }

替换为

    signingConfigs {
        release {
            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    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
        }
    }
  1. android studio项目下的terminal中,执行打包命令:
flutter build apk
  1. apk包所在位置:
    ~/AndroidStudioProjects/moka_flutter/build/app/outputs/apk/release/app-release.apk

注意事项:
打包的apk直接忘模拟器拖放,会报错:
the apk failed to install.error: could not parse error string
可能原因:apkarm下才正常,而模拟器是x86的,所以报错。

上一篇下一篇

猜你喜欢

热点阅读