Wie ändere ich den Namen von apk, indem ich gradle wie dieses Format verwende?
SJ Lim
Ich möchte den Dateinamen "app-release.apk" so ändern, dass er beim Erstellen einer App mit gradle wie folgt lautet.
[Format] (Anwendungsname des Paketnamens) _V (Versionscode) _ (yyMMdd) _ (R | T) [ EXPLAIN ] (Anwendungsname des Paketnamens): Beispiel) com.example.myApp -> myApp (Versionscode): build Versionscode 2.2.3 -> 223 (yyMMdd): Erstellungsdatum 2015.11.18 -> 151118 (R | T): Wenn die App veröffentlicht wird, ist "R", aber das Debuggen ist "T".
Wenn ich in der Version eine APK-Datei generiere, lautet das Ergebnis: myApp_V223_151118_R.apk.
Wie erstelle ich einen solchen Dateinamen in gradle?
Krishnaraj
Update: Bitte überprüfen Sie Anrimians Antwort, die viel einfacher und kürzer ist.
Versuche dies:
gradle.properties
applicationName = MyApp
build.gradle
android {
...
defaultConfig {
versionCode 111
...
}
buildTypes {
release {
...
applicationVariants.all { variant ->
renameAPK(variant, defaultConfig, 'R')
}
}
debug {
...
applicationVariants.all { variant ->
renameAPK(variant, defaultConfig, 'T')
}
}
}
}
def renameAPK(variant, defaultConfig, buildType) {
variant.outputs.each { output ->
def formattedDate = new Date().format('yyMMdd')
def file = output.packageApplication.outputFile
def fileName = applicationName + "_V" + defaultConfig.versionCode + "_" + formattedDate + "_" + buildType + ".apk"
output.packageApplication.outputFile = new File(file.parent, fileName)
}
}
Referenz: https://stackoverflow.com/a/30332234/206292 https://stackoverflow.com/a/27104634/206292