2017-06-28 7 views
6

私のプロジェクトでアンドロイドビルドツール "com.android.tools.build:gradle:3.0.0-alpha4"を使用しようとしています。私のビルドスクリプトでは、過去にうまくいきましたが、もうサポートされていないような出力apkの名前を変更します。gradleでapkファイル名を変更できませんでした:3.0.0-alpha4

android { 

    productFlavors { 
     flavorUnsigned { 
      applicationVariants.all { variant -> 
       variant.outputs.all { output -> 
        output.outputFile = new File(
          output.outputFile.parent, 
          output.outputFile.name.replace("app-flavorUnsigned-release-unsigned.apk", "DemoApp-${variant.versionName}($variant.versionCode).apk")) 
        def mappingFile = "${rootDir}/app/build/outputs/mapping/${getCurrentFlavor()}/release/mapping.txt" 
        if (variant.getBuildType().isMinifyEnabled()) { 
         variant.assemble.doLast { 
          copy { 
           from "${mappingFile}" 
           into "${rootDir}/app/build/outputs/apk" 
          } 
         } 
        } 
       } 
      } 
     } 

    } 
} 

しかし、あなたは、Androidのプラグイン3.0.0-alpha1以上にあなたのプロジェクトを移行したい場合は、以下を実行する必要があります

Error:Cannot set the value of read-only property 'outputFile' for ApkVariantOutputImpl_Decorated{apkData=Main{type=MAIN, fullName=flavorUnsignedDebug, filters=[]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl. 

答えて

20

を自分のプロジェクトを構築しながら、今、私はこのエラーを取得しています:中 APIの変更を変種出力:どのようにトンを学ぶため

// If you use each() to iterate through the variant objects, 
// you need to start using all(). That's because each() iterates 
// through only the objects that already exist during configuration time— 
// but those object don't exist at configuration time with the new model. 
// However, all() adapts to the new model by picking up object as they are 
// added during execution. 
android.applicationVariants.all { variant -> 
    variant.outputs.all { 
     outputFileName = "${variant.name}-${variant.versionName}.apk" 
    } 
} 

読むthisページoプラグインを適用し、プロジェクトをいくつかの急な変更に適応させます。

+0

...これは私のために働いた

Use output.outputFileName instead of output.outputFile 

、これを試してみてください – pk4393

0

私はすでにそのリンクからの提案を試してみましたが、まだそれが動作していない

関連する問題