Android Studio wird den Standard-APK-Namen als app- (release | debug) .apk generieren.
Wie apk Dateiname wie Paketname der App wie com.example-debug.apk
generieren.Apk-Namen als Paketname in Android Studio generieren
Antwort
Versuchen Sie, diese build.gradle die in Ihrem Modul setzen
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
def appId = android.defaultConfig.applicationId
def fileName = appId + "-" variant.buildType.name +".apk"
output.outputFile = new File(file.parent, fileName)
}
}
Dank für seine Arbeits Update. – Bangaram
Das spuckt nur ein APK für mich aus und spuckt für jede Build-Variante kein APK aus. – Subby
Natürlich nicht, wenn Sie apk für eine andere Variante möchten, müssen Sie zuerst die Build-Variante ändern. Oder verwenden Sie einen Befehl, um alle Versionen zu erstellen. Dieser Code ändert nur den Namen der apk, nichts mehr. – slezadav
können Sie diese link sehen. oder Unlogische Option zum Umbenennen Ihrer release|debug.apk
mit dem Namen, was Sie im Dateibrowser wollen.
kann dieser Code für Sie nützlich sein:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def newName = output.outputFile.name
newName = newName.replace("app-", "$rootProject.ext.appName-") //"MyAppName" -> I set my app variables in the root project
newName = newName.replace("-release", "-release" + formattedDate)
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
debug {
}
}
Code :)
Erstellen Sie eine Datei mit dem Namen customname.gradle in der obersten Ebene des project.Put hinein diesen Code genießen.
android.applicationVariants.all { variant ->;
def appName
//Check if an applicationName property is supplied; if not use the name of the parent project.
if (project.hasProperty("applicationName")) {
appName = applicationName
} else {
appName = parent.name
}
variant.outputs.each { output ->;
def newApkName
//If there's no ZipAlign task it means that our artifact will be unaligned and we need to mark it as such.
if (output.zipAlign) {
newApkName = "${appName}-${output.baseName}-${variant.versionName}.apk"
} else {
newApkName = "${appName}-${output.baseName}-${variant.versionName}-unaligned.apk"
}
output.outputFile = new File(output.outputFile.parent, newApkName)
}}
Dann in Ihrem gradle App-Modul diesen Code hinzufügen
apply from: "../customname.gradle"
Sie können es tun, ohne die anderen Aufgaben zu verwenden, die archivesBaseName
Einstellung.
Zum Beispiel:
defaultConfig {
....
project.ext.set("archivesBaseName", "MyName-" + defaultConfig.versionName);
}
Ausgang:
MyName-1.0.12-release.apk
In Ihrem Fall:
project.ext.set("archivesBaseName", "com.example");
Sie können möglicherweise auf rootProject name zugreifen und es wie folgt verwenden: 'project.ext.set (" archivesBaseName ", rootProject.getName() + "-" + defaultConfig.versionName); ' –
skaliert leider nicht, wenn Sie mit Varianten arbeiten, da archivesBaseName global für alle ist – Ewoks
Dies kann Ihnen helfen. Dieser Code erstellt einen App-Namen wie applicationId-release.apk
oder applicationId-debug.apk
, in dem ApplicationId Ihr Paketname sein kann.
buildTypes {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def newName = output.outputFile.name
newName = newName.replace("app-", applicationId)
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
Link kann http://stackoverflow.com/questions/22126299/change-apk-name-with-gradle/22126638#22126638 helfen –
Der obige Link ist nützlich –