2016-09-23 161 views

回答

8

第1步: 转到主体工程,下应用,右键单击应用和重构应用到特定名称(例如iPlanter)并按确定

步骤2: 转到项目设置文件,该文件是setting.gradle文件

setting.gradle文件包含

include ':app' 

现在需要通过特定的名称来代替应用程序。

对于实例 应用程序通过iPlanter在取代包括“:应用程序” 它看起来像下面

include ':iPlanter' 

然后同步项目,后运行应用程序。 最后,App生成一个apk,如iPlanter-debug.apkiPlanter-release.apk文件。

+0

错误:项目“在'root'项目'iPlanter'中找不到'app'。我得到这个错误@kgsharathkumar – PriyankaChauhan

+0

@pcpriyanka,现在检查,我添加完整的步骤.. :) – kgsharathkumar

+0

我可以选择重命名目录或模块? – PriyankaChauhan

2

试试这个代码:

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") 
    } 
} 
5

您可以用当前的日期和版本

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); 
      } 
     } 
    } 
+0

哪个gradle文件是这个代码添加的? – Ian

+1

应用程序级别build.gradle文件,不在项目级文件 –

+1

AndroidStudio 3怎么样? –

0

在我的电脑用这个应用的名字,就足够了(通过重构)应用来重命名所需的名称yourName。之后,将setting.grandle文件中的include ':app'更改为include ':yourName'。但是,在我的情况下,我需要关闭/重新打开Android Studio,因为同步错误。因此,获得apk类似yourName-debug.apkyourName-release.apk

0

在gradle这个文件的Android {}部分只需添加

archivesBaseName = "NAME_YOU_WANT" 

您将获得“NAME_YOU_WANT-release.apk”作为生成文件的名称。

0

这会帮助你。此代码将像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) 
    } 
    } 

}

0

了解Android Studio 3创建应用程序的名称,这个工作对我来说:

applicationVariants.all { variant -> 
     variant.outputs.all { output -> 
      outputFileName = new File("AppName-" + variant.versionName + ".apk"); 
     } 
} 
相关问题