Steps to package apk and ipa in Flutter Mac environment

Mac naturally supports downloading Xcode and AndroidStudio, which is very friendly for development. Please configure the environment first when playing ipa on Windows. (My computer has downloaded Xcode, AndroidStudio, and VSCode at the same time, and usually develops on the lighter VSCode)

1. How to pack the apk package (the packaging process is slightly complicated)

1. Check & install JDK (full name: Java Development Kit), first open System Preferences under mac to see if there is a Java icon, (or check the current JDK version number, if the current java version number is displayed, it means that the JDK installation is  java -version,successful , or it has been installed before, if it has already been installed, you can ignore the following installation steps) Download and install address:

1.1 Recommended method one installation https://www.java.com/zh-CN/download/

1.2 You can choose the terminal to install brew cask install oracle-jdk, if brew cask install oracle-jdk is displayed, the installation is successful. Because I need to update Homebrew, I use the way to download and install from the official website

  1. JDK official website download address , download the corresponding version, mine is MBP, so I chose macOS Installer
  2. After the installation is successful, open the environment configuration file with the terminal: vim .bash_profile, add export JAVA_HOME=$(/usr/libexec/java_home)
  3. save and exit esc -> wq
  4. Execute  source .bash_profile the update configuration file and take effect
  5. Check the version number of JDK to see if it is successful

2. Generate a signed certificate.jks

Create a keystore
If you have created a keystore before, you can skip this step. If not, create one by opening a terminal and running the following command:

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

2.1 The current Android keystore (product under Eclipse), which has been upgraded to jks, needs to execute the following command:

After -alias, you need to replace it with your own alias (usually the project name)

keytool -importkeystore -srckeystore /Users/用户名/key.jks -destkeystore /Users/用户名/key.jks -deststoretype pkcs12

(Reminder: Username needs to be replaced with your own)

genkey : generate key 

<Storage path>/sign.jks : The storage path and name of the certificate

keyalg RSA -keysize 2048 : use 2048-bit RSA algorithm to encrypt the signature

validity 10000: Validity time, here is 10000 days

alias sign : alias sign

3. Reference jks in the application

To reference jks in the application,
first create a file key.properties
path <app dir>/android/key.properties, which <app dir>is the file path of your app,

key.propertiesfor the file name

 Enter the corresponding configuration in this file

storePassword=<生成keystore时设置的密码>
keyPassword=<生成keystore时设置的密码>
keyAlias=key //注意key为自己随意起的别名替换为自己的
storeFile=<location of the key store file, e.g. /Users/<user name>/key.jks>即生成文件的key.jks的文件路径


Configure the signature configuration file path in gradle to <app dir>/android/app/build.gradleconfigure for the application

4.build.gradle配置jks相关引用路径和打包设置,一般是把jks添加到app文件夹下方便使用

 5. The build.gradle file needs the following modifications

 signingConfigs {
        debug {
            //jks中key的别名
            keyAlias 'key'
            //jks中key的密码
            keyPassword '123456'
            //jks的文件路径,可以是绝对路径也可以是相对路径
            storeFile file('../key.jks')
            //jks的密码
            storePassword '123456'
        }
        release {
            //jks中key的别名
            keyAlias 'key'
            //jks中key的密码
            keyPassword '123456'
            //jks的文件路径,可以是绝对路径也可以是相对路径
            storeFile file('../key.jks')
            //jks的密码
            storePassword '123456'
        }
    }
buildTypes {
        debug {
            // 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

            //关闭混淆, 否则在运行release包后可能出现运行崩溃, TODO后续进行混淆配置
            minifyEnabled false //删除无用代码
            shrinkResources false //删除无用资源
        }
        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

            //关闭混淆, 否则在运行release包后可能出现运行崩溃, TODO后续进行混淆配置
            minifyEnabled false //删除无用代码
            shrinkResources false //删除无用资源
        }
    }

6. Enter in the terminal in VSCode  flutter build apk, if it is finally displayed  ✓ Built ***, it means that the packaging is successful.

build/app/outputs/flutter-apk/app-release.apkIt is a subpath in the project. At this point, APK packaging has been successfully completed.

2. How to package ipa

Method 1: Recommendation: In fact, the packaging of iOS can completely use the way of developing iOS before.

Method Two:

flutter build ios --debug
flutter build ios --release

Compile directory:

项目工程目录/build/ios/iphoneos/Runner.app

Then we need to create a folder named Demo (the name of our own app), then paste Runner.app under the Demo file, then compress Demo into .zip, and then rename Demo.zip to Demo.ipa , so far the production of ipa is completed.

 

Guess you like

Origin blog.csdn.net/RreamigOfGirls/article/details/126261414