默认情况下,IDE会生成一个apk文件,如app-debug.apk
或app-release.apk
文件,但我需要生成该应用程序的Apk的特定名称。Android:如何更改Android Studio中生成的apk文件的具体名称?
例如: 我的应用程序名称为iPlanter所以我需要分别产生iPlanter-debug.apk
或iPlanter-release.apk
代替app-debug.apk
或app-release.apk
。
感谢,
默认情况下,IDE会生成一个apk文件,如app-debug.apk
或app-release.apk
文件,但我需要生成该应用程序的Apk的特定名称。Android:如何更改Android Studio中生成的apk文件的具体名称?
例如: 我的应用程序名称为iPlanter所以我需要分别产生iPlanter-debug.apk
或iPlanter-release.apk
代替app-debug.apk
或app-release.apk
。
感谢,
第1步: 转到根主体工程的,下应用,右键单击应用和重构应用到特定名称(例如iPlanter)并按确定
步骤2: 转到项目设置文件,该文件是setting.gradle
文件
setting.gradle
文件包含
include ':app'
现在需要通过特定的名称来代替应用程序。
对于实例 应用程序通过iPlanter在取代包括“:应用程序” 它看起来像下面
include ':iPlanter'
然后同步项目,后运行应用程序。 最后,App生成一个apk,如iPlanter-debug.apk
或iPlanter-release.apk
文件。
试试这个代码:
defaultConfig{
applicationVariants.all { variant ->
changeAPKName(variant, defaultConfig)
}
}
def changeAPKName(variant, defaultConfig) {
variant.outputs.each { output ->
if (output.zipAlign) {
def file = output.outputFile
output.packageApplication.outputFile = new File(file.parent, "Your APK NAME")
}
def file = output.packageApplication.outputFile
output.packageApplication.outputFile = new File(file.parent, "Your APK NAME")
}
}
您可以用当前的日期和版本
android {
def version = "2.4";
def milestone = "1";
def build = "0";
def name = getDate()+"APP NAME WHAT YOU WANT"+"v"+version
signingConfigs {
config {
….
}
}
compileSdkVersion Integer.parseInt(COMPILE_SDK)
buildToolsVersion BUILD_TOOLS_VERSION
defaultConfig {
applicationId "com.PACKAGENAME"
minSdkVersion Integer.parseInt(MIN_SDK_LIBRARY)
targetSdkVersion Integer.parseInt(TARGET_SDK)
versionCode 11
versionName "2.3"
multiDexEnabled true
}
buildTypes {
debug {
applicationVariants.all { variant ->
variant.outputs.each { output ->
def apk = output.outputFile;
def newName;
newName = apk.name.replace("-" + variant.buildType.name, "")
.replace(project.name, name);
newName = newName.replace("-", "-" + version + "-" + milestone +
"-" + build + "-");
output.outputFile = new File(apk.parentFile, newName);
}
}
}
在我的电脑用这个应用的名字,就足够了(通过重构)应用来重命名所需的名称yourName。之后,将setting.grandle文件中的include ':app'
更改为include ':yourName'
。但是,在我的情况下,我需要关闭/重新打开Android Studio,因为同步错误。因此,获得apk类似yourName-debug.apk和yourName-release.apk。
在gradle这个文件的Android {}部分只需添加
archivesBaseName = "NAME_YOU_WANT"
。
您将获得“NAME_YOU_WANT-release.apk”作为生成文件的名称。
这会帮助你。此代码将像iPlanter-release.apk或iPlanter-debug.apk
buildTypes {
applicationVariants.all { variant ->
variant.outputs.each { output ->
project.ext { appName = 'iPlanter' }
def newName = output.outputFile.name
newName = newName.replace("app-", "$project.ext.appName-")
output.outputFile = new File(output.outputFile.parent, newName)
}
}
}
了解Android Studio 3创建应用程序的名称,这个工作对我来说:
applicationVariants.all { variant ->
variant.outputs.all { output ->
outputFileName = new File("AppName-" + variant.versionName + ".apk");
}
}
错误:项目“在'root'项目'iPlanter'中找不到'app'。我得到这个错误@kgsharathkumar – PriyankaChauhan
@pcpriyanka,现在检查,我添加完整的步骤.. :) – kgsharathkumar
我可以选择重命名目录或模块? – PriyankaChauhan