flutter打包

1. 打開terminal

2. 輸入命令:keytool -genkey -v -keystore C:/20190628/android -keyalg RSA -keysize 2048 -validity 10000 -alias key

注:C:/20190628/android key保存路徑android

3. 填充信息

4. android文件夾下建立一個名爲key.properties的文件

 

5. Key.properties文件中添加

 

storePassword=<password from previous step> //輸入上一步建立KEY時輸入的 密鑰庫 密碼

keyPassword=<password from previous step> //輸入上一步建立KEY時輸入的 密鑰 密碼

keyAlias=key

storeFile=C:/20190628/android/file //key.jks的存放路徑

 

6. /android/app/build.gradle文件,在android {這一行前面,加入以下代碼

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

keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

 

7. 把以下代碼進行替換

 

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

 

替換成app

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

8. 生成apk,直接在終端輸入

flutter build apk

9. Flutter install 安裝到虛擬機上

注:大坑!gradle

請將key.properties文件中值後全部字符刪除,不然會報錯ui

相關文章
相關標籤/搜索