Last active
May 8, 2020 10:00
-
-
Save 410063005/29f75e97b581e81f006dc325c0e80277 to your computer and use it in GitHub Desktop.
一个用于修改 flutter aar 产物版本号的脚本。用法:gradle -b aar_uploader.gradle uploadAar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def flutterArchVersion = '<修改成你的 version>' | |
def flutterGroupName = '<修改成你的 group>' | |
def localProperties = new Properties() | |
def flutterSdk = '' | |
def localPropertiesFile = rootProject.file('.android/local.properties') | |
if (localPropertiesFile.exists()) { | |
localPropertiesFile.withReader('UTF-8') { reader -> | |
localProperties.load(reader) | |
} | |
flutterSdk = localProperties.getProperty('flutter.sdk', '') | |
} | |
if (flutterSdk != '') { | |
println("当前 flutter sdk: $flutterSdk") | |
} else { | |
throw new GradleException('flutter sdk not configed') | |
} | |
def oldVersion = localProperties.getProperty('flutter.versionName', '1.0') | |
task rmLockFile(type: Exec, description: '清理 lockfile') { | |
doFirst { | |
println description | |
} | |
workingDir "." | |
commandLine 'rm', "-rf", "$flutterSdk/bin/cache/lockfile" | |
} | |
task updateVersion(description: '更新 flutter 产物版本') { | |
doFirst { | |
println description | |
} | |
// 更新 .android/Flutter/build.gradle 中的版本号 | |
File autoGenBuildFile = new File('.android/Flutter/build.gradle') | |
List oldContent = autoGenBuildFile.readLines() | |
List newContent = oldContent.collect { | |
if (it.startsWith("group '")) { | |
"group '$flutterGroupName'" | |
} else if (it.startsWith("version '")) { | |
//def gitCommitHash = 'git rev-parse --verify --short HEAD'.execute().text.trim() | |
//"version '$flutterArchVersion-$gitCommitHash'" | |
"version '$flutterArchVersion'" | |
} else { | |
it | |
} | |
} | |
autoGenBuildFile.text = newContent.join('\n') | |
} | |
task pubGet(type: Exec, description: 'flutter pub get', dependsOn: rmLockFile) { | |
doFirst { | |
println description | |
} | |
workingDir '.' | |
commandLine 'flutter', 'pub', 'get' | |
} | |
task uploadAar(type: Exec, description: '生成 aar 并上传 maven 库' | |
, dependsOn: [pubGet, updateVersion]) { | |
doFirst { | |
println description | |
} | |
workingDir '.' | |
commandLine 'flutter', 'build', 'aar', '--no-debug', '--no-profile', '--no-pub', '--target-platform', 'android-arm' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment