[英]Change generated apk name from “app-debug.apk”
Every time I run a project with Android Studio (1.02) it's generate an unsigned apk which located in ..\\build\\outputs\\apk folder and get by default the name "app-debug.apk"每次我使用 Android Studio (1.02) 运行一个项目时,它都会生成一个未签名的 apk,它位于 ..\\build\\outputs\\apk 文件夹中,默认情况下获得名称“app-debug.apk”
I want to change that default name to something else.我想将该默认名称更改为其他名称。
Is it possible?是否可以? How?
如何?
In build.gradle
(Module: app):在
build.gradle
(模块:app)中:
android {
...
defaultConfig {
...
setProperty("archivesBaseName", "MyNewAppNameGoesHere")
}
}
This works by modifying the archivesBaseName
-property and works for Gradle Version >= 2.0, last tested with 2.1.0.这通过修改
archivesBaseName
-property 起作用,适用于 Gradle 版本 >= 2.0,最后用 2.1.0 测试。
You can use applicationVariants and change the output file in the build.gradle.您可以使用 applicationVariants 并更改 build.gradle 中的输出文件。 You can also modify the name regarding to your needs.
您还可以根据需要修改名称。
buildTypes{
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = file("$project.buildDir/apk/test.apk")
}
}
}
Solution for gradle3: gradle3的解决方案:
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = applicationId;
outputFileName += "-v" + android.defaultConfig.versionName;
if (variant.buildType.name == "release") {
outputFileName += ".apk";
} else {
outputFileName += "-SNAPSHOT.apk";
}
}
}
如果有人想在 Android 工作室之外更改 apk 名称(只是为了将此文件发送给其他人,就像我的情况一样),只需右键单击应用程序名称并将其更改为您想要的任何名称。
defaultConfig {
applicationId "com.dcarl661.awesomelayout"
minSdkVersion 14
targetSdkVersion 25
versionCode 1
versionName "1.0"
//here put it in the section where you have the version stuff
setProperty("archivesBaseName", "AwesomeLayout")
}
The 'app' part of the name uses the folder name of your application's module (default is 'app').名称的“app”部分使用应用程序模块的文件夹名称(默认为“app”)。 See the link below on how to change that.
请参阅下面的链接,了解如何更改它。
Why is my APK name generic? 为什么我的 APK 名称是通用的?
The '-debug' prefix is something you can change in the Module settings at Build Types “-debug”前缀是您可以在构建类型的模块设置中更改的内容
defaultConfig {
applicationId "com.example"
def date = new Date();
def formattedDate = date.format('yyyy-MM-dd-HHmmss')
setProperty("archivesBaseName", "Quest_" + versionName + "_"+formattedDate)
}
i did like this.我喜欢这个。 More detailed
更详细
Maybe this question (and its accepted answer) are interesting for you: How to set versionName in APK filename using gradle?也许这个问题(及其接受的答案)对您很有趣:如何使用 gradle 在 APK 文件名中设置 versionName? It describes how to put your versionName into the APK name.
它描述了如何将您的 versionName 放入 APK 名称中。
You have to use the 'Update' part of the accepted answer.您必须使用已接受答案的“更新”部分。 Also you need the versionName (in this example) declared in your defaultConfig in the build.gradle file.
您还需要在 build.gradle 文件中的 defaultConfig 中声明 versionName(在本例中)。 It does also work if you define versionCode in the build.gradle (as described here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manifest-entries ).
如果您在 build.gradle 中定义 versionCode,它也可以工作(如下所述: http ://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Manifest-entries)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.