2016-09-23 116 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"); 
     } 
} 
相關問題