link

  1. IOS 3 minutes to achieve custom Xcode initialization template, improve development efficiency
  2. Make your own Pod library from 0

Note:

  • The packaging process documented here is all done on VSCode, as is Android Studio.
  • This time use Gradle configuration packaging

1. Check & install JDK

  • Check the current JDK version numberjava -version

If the current Java version is displayed, the JDK is successfully installed or has been installed before. If the JDK has been installed, skip the following installation steps

  • Install the JDK

If brew cask install oracle-JDK is displayed, the installation is successful. Because I need to update Homebrew, I use the download and install method from the official website.

  1. JDK official website download address, download the corresponding version, mine is MBP, so choosemacOS Installer
  2. After the installation is successful, open the environment configuration file with terminal:vim .bash_profile, an increase ofexport JAVA_HOME=$(/usr/libexec/java_home)

  1. Save and exitesc -> wq.
  2. performsource .bash_profileUpdate the configuration file and make it take effect
  3. Check the JDK version number to see if it is successful

2. Generate the signature certificate.jks

The main functions of using a signature are:

  1. Application upgrade: The system will only allow the installation of upgraded applications if the same certificate is signed. If you use a different certificate, your application will be required to use a different package name, which in this case is equivalent to installing a completely new application. If you want to upgrade the application, the signing certificate must be the same, and the package name must be the same!
  2. Application modularization: The Android system can allow multiple applications with the same certificate signature to run in a process. The system actually treats them as a single application. At this point, our application can be deployed as modules, and users can independently upgrade one of the modules.
  3. Code or data sharing: Android provides signature-based permissions so that one application can expose its functionality to another application signed with the same certificate. By signing multiple applications with the same certificate, you can share code and data between applications in a secure way with signature-based permission checks.

** Note ** : Once you have signed your Apk online, you must not lose your signature file, password, alias, etc., or you will run away.

Replace the path where the certificate was generated with your own and run the following command on the terminal

JKS -keyalg RSA -keysize 2048 -validity 10000 -alias signCopy the code
  1. Genkey: generates a key
  2. Keystore:
  3. < store path >/sign. JKS: store 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

According to the steps, according to the actual situation, enter the content, after generating the signature certificate path is your command path above

3. Configure the package file

  • Import the certificate created above. If the key folder does not exist, create one
< > flutter project/android/app/key/sign JKSCopy the code
  • Create the key.properties file
< Flutter project >/android/key.propertiesCopy the code

Add configuration, you can copy the existing properties file, change the name and corresponding content,

storePassword=android
keyPassword=123456
keyAlias=sign
storeFile=key/sign.jks
Copy the code
  1. StorePassword:
  2. KeyPassword: generates the keystore password for the signature certificate input
  3. KeyAlias: alias of the certificate
  4. StoreFile: path of the certificate relative to key.properties
  • Configure the build.gradle file
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

    signingConfigs {
        release {
            keyAlias 'sign'
            keyPassword 'android'
            storeFile file('key/sign.jks')
            storePassword 'android'
        }
    }
Copy the code

4, VSCode final directory configuration

The Flutter package generates APK

  • Enter in terminal in VSCodeflutter build apk, if the final display✓ Built * * *“, the package is successfully packaged
  • build/app/outputs/flutter-apk/app-release.apkIs the subpath in the project, by this point, APK packaging has been successful.