The packaging process recorded this time is all completed on Android Studio. It is recommended not to refer to the packaging process in the official document directly, or it will be very likely to make mistakes

The Android Studio terminal generates the signature file

JKS -keyalg RSA -keysize 2048 -validity validity time -alias AliasCopy the code

Example: the keytool - genkey - v - keystore D: / flutterPackageSignature/key JKS keyalg RSA - keysize 2048 - gnosis.xml.validity 10000 - alias sign

  1. Genkey: generates a key
  2. Keystore:
  3. < path where the certificate is stored >/key. JKS: path and name of the certificate
  4. Keyalg rsa-keysize 2048: encrypts signatures using the 2048-bit RSA algorithm
  5. Validity 10000: validity period, in this case 10000 days
  6. Alias sign: indicates the alias sign

Enter the correct command and press Enter to request your password (don’t forget your password)

Run at this time the correct command will not surprisingly in D: / flutterPackageSignature generated in a key. The JKS file, note that this file don’t upload to share with others

Project configuration

  1. Import the signature file key.jks

Create the key folder in the /android/app folder of the Flutter project and copy the sign. JKS file into the folder.

  1. Configuration/android/app/build. Gradle file

In the flutter/android/app/build. Gradle android before joining in the file

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

Add release to Android’s signingConfigs

SigningConfigs {release {keyAlias 'sign' // alias keyPassword 'generates the password entered when signing' storeFile ' The file (' D: / flutterPackageSignature signfile. JKS ') / / signature file path storePassword 'sign the generated input password'}} buildTypes {release { signingConfig signingConfigs.release } }Copy the code
  1. Create the key.properties file

  • StorePassword = Password used when the keystore was created
  • KeyPassword = The password for the key you just created
  • KeyAlias = sign (alias)
  • storeFile=D:/flutterPackageSignature/key.jks

Generated apk

After the configuration, enter the command to generate APK on the project terminal

Flutter build APk –target-platform Android-arm –split-per-abi

or

Flutter build apk this command packs a larger APK than the one above

or

Flutter build AppBundle

When shown in the figure, the package is successful, and after Build, it is the road strength stored in APK

Some potholes encountered during the generation of APK

BUG1

As shown in figure, when a bug in the picture, we can check project/android/gradle. The properties files, to see if the android exists. EnableR8 = true (it is best not to add android enableR8 this lines, but sometimes will be generated by default, So we can fix this bug by changing true to false.)

BUG2

To sum up, bug1 is solved when we change true to false, but bug2 appears in the figure

Solution: Replace the old part in the image below with the new part

BUG3

We need to change BuildScript Repositories and AllProjects Repositories in order to exchange for Ali’s image

Ah in the mirror

maven { url 'https://maven.aliyun.com/repository/google' }
maven { url 'https://maven.aliyun.com/repository/jcenter' }
maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
Copy the code

BUG 4

This class is basically Gradle configuration that needs to be changed.

  1. Replace the mirror by referring to BUG3
  2. Turn over the wall in global mode

Refer to the reference

Flutter project packaged into APK: juejin. Cn/post / 689411…

Flutter package APK: wcdxg.com/2020/04/29/…

Flutter packaging apk:www.jianshu.com/p/fabcfd621…

Flutter android true machine or packaging APK diseases record: xie. Infoq. Cn/article/limited…