Flutter 脚本打包 iOS 和 Android 应用 MacOS

120 阅读1分钟

1. Flutter 安卓脚本打包配置

1.1申请签名 MocOS端

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

image.png 提示:没有安装JAVA的可能会报错,装一个JAVA就好了

1.2安卓目录下新建key.properties文件

storePassword=xxx
keyPassword=xxx
keyAlias=key0
storeFile=/xxx/xxx/upload-keystore.jks

image.png

1.3在andriod目录下app下的build.gradle,添加以下代码

def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
    keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}

image.png

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

image.png 1.4编写打包脚本新建文件apk.sh 如图所示

cd ../
/Users/jack/fvm/versions/stable/bin/\  //自己flutter sdk存放的位置
flutter build apk --no-shrink --obfuscate --split-debug-info=./symbols

image.png 1.5点击绿色三角即可运行

image.png

2.iOS打包脚本配置

iOS打包就很简单了,直接写脚本,运行就可以了;

cd ../
/Users/jack/fvm/versions/stable/bin/\
flutter build ipa --obfuscate --split-debug-info=./symbols

喜欢的话点个赞再走吧!