GitHub地址
打包過程視頻預(yù)覽
對(duì)于macOS用戶使用flutter build apk
打包可為曲折,官方只給出了Android正常的配置流程惭缰,但是macOS用戶是不行滴---需要申請(qǐng)系統(tǒng)的訪問權(quán)限授權(quán)
-
簡(jiǎn)略的Android Studio配置(默認(rèn)你的簽名文件已經(jīng)設(shè)置完成)
防止key.properties文件
配置gradle
-
配置腳本執(zhí)行是申請(qǐng)macOS的系統(tǒng)權(quán)限參考文章
-
打開keychain app, 選中密碼,點(diǎn)擊底部toolbar的+
-
設(shè)置對(duì)應(yīng)的信息
密鑰項(xiàng)目名稱:隨意填寫叁征,就是一個(gè)名稱
賬戶名稱:可以打開終端輸入```whoami```可以查看對(duì)應(yīng)用戶
-
gradle配腳本
def getPassword(String currentUser, String keyChain) { def stdout = new ByteArrayOutputStream() def stderr = new ByteArrayOutputStream() exec { commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w' standardOutput = stdout errorOutput = stderr ignoreExitValue true } //noinspection GroovyAssignabilityCheck stdout.toString().trim() } def getWhoami(){ def stdout = new ByteArrayOutputStream() def stderr = new ByteArrayOutputStream() exec { commandLine 'whoami' standardOutput = stdout errorOutput = stderr ignoreExitValue true } //noinspection GroovyAssignabilityCheck stdout.toString().trim() } //def pass = getPassword("YOUR_USER_NAME","android_keystore") //終端中 whoami 查看YOUR_USER_NAME android_keystore你在密鑰串中設(shè)置的名稱 def pass = getPassword(getWhoami(),"les01_flutter")
-
最終配置
def getPassword(String currentUser, String keyChain) {
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
exec {
commandLine 'security', '-q', 'find-generic-password', '-a', currentUser, '-s', keyChain, '-w'
standardOutput = stdout
errorOutput = stderr
ignoreExitValue true
}
//noinspection GroovyAssignabilityCheck
stdout.toString().trim()
}
def getWhoami(){
def stdout = new ByteArrayOutputStream()
def stderr = new ByteArrayOutputStream()
exec {
commandLine 'whoami'
standardOutput = stdout
errorOutput = stderr
ignoreExitValue true
}
//noinspection GroovyAssignabilityCheck
stdout.toString().trim()
}
//def pass = getPassword("YOUR_USER_NAME","android_keystore") //終端中 whoami 查看YOUR_USER_NAME android_keystore你在密鑰串中設(shè)置的名稱
def pass = getPassword(getWhoami(),"les01_flutter")
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
compileSdkVersion 27
lintOptions {
disable 'InvalidPackage'
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.xiangshike.les01hello"
minSdkVersion 16
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
storeFile file(keystoreProperties['storeFile'])
/*
//windows用戶
keyPassword keystoreProperties['keyPassword']
storePassword keystoreProperties['storePassword']
*/
storePassword pass // Change this
keyPassword keystoreProperties['keyPassword'] // Change this
}
}
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
signingConfig signingConfigs.release
}
}
}
打包:
flutter build apk --debug