2016-09-23 2 views
6

デフォルトではIDEのgenarate a apkはapp-debug.apkまたはapp-release.apkのファイルですが、私はアプリケーションのApkという特定の名前を生成する必要があります。例についてはAndroid:Android Studioで生成されたapkファイルの特定の名前を変更するにはどうすればよいですか?

: 私のアプリケーション名はので、私はそれぞれの代わりapp-debug.apkまたはapp-release.apkiPlanter-debug.apkまたはiPlanter-release.apkを生成する必要がiPlanterです。

おかげで、

答えて

8

ステップ1: ゴーメインプロジェクトの、アプリ下のルートに、右アプリをクリックすると、特定の名前(例iPlanterにアプリをリファクタリング)を入力してOKを押します。

ステップ2: は、Goは、ファイルが

include ':app' 

が含まれてい

setting.gradlesetting.gradleファイルで設定ファイルをプロジェクトに今、特定の名前でアプリを交換する必要があります。例 Appの

にiPlanterで置き換えるには、 ':アプリ' それはあなたのアプリケーションを実行した後 それは、

include ':iPlanter' 

その後、シンクプロジェクト以下のように見えます。 最後に、アプリケーションはiPlanter-debug.apkまたはiPlanter-release.apkファイルのようなapkを生成します。

+0

エラー:プロジェクト」 app 'はルートプロジェクト' iPlanter 'に見つかりませんでした。私はこのエラーを取得しています@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

あなたは、それがアプリへ(リファクタリング経由)の名前を変更するだけで十分私のPC上で、現在の日付とバージョン

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を終了/再開する必要があります。その結果、apkyourName-debug.apkyourName-release.apkのようなものが得られます。

0

ちょうどあなたのGradleファイルのアンドロイド{}部分に

archivesBaseName = "NAME_YOU_WANT" 

を追加します。

生成されたファイルの名前として "NAME_YOU_WANT-release.apk"が表示されます。

0

これが役に立ちます。このコードはiPlanter-release.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メーカー3については
0

iPlanter-debug.apkのようなアプリ名を作成します、これは私の作品:

applicationVariants.all { variant -> 
     variant.outputs.all { output -> 
      outputFileName = new File("AppName-" + variant.versionName + ".apk"); 
     } 
} 
関連する問題