2017-06-13 3 views
4

私はコードエラー:(81、0)getMainOutputFileはサポートされなくなりました。出力のファイル名を判別する必要がある場合は、getOutputFileNameを使用してください。

android.applicationVariants.all { variant -> 
      def appName = "MyApplication.apk" 

      variant.outputs.each { output -> 
       output.outputFile = new File(output.outputFile.parent, appName) 
      } 
     } 

の下に使用してビルドプロセスをカスタマイズしようとしています。しかし、アンドロイドスタジオ3.0から、それは私がエラー

エラーの下に取得しています動作していません:(81、0)getMainOutputFileがサポートされなくなりました。出力のファイル名を判別する必要がある場合は、getOutputFileNameを使用してください。

答えて

2

はちょうどこのようにそれを実行します。

buildTypes { 
    release { 
     minifyEnabled false 
     proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     signingConfig getSigningConfig() 
     android.applicationVariants.all { variant -> 
      def date = new Date(); 
      def formattedDate = date.format('dd MMMM yyyy') 
      variant.outputs.all { 
       def newApkName 
       newApkName = "MyApp-${variant.versionName}, ${formattedDate}.apk" 
       outputFileName = newApkName; 
      } 
     } 
    } 
} 
+0

このソリューションは、動作します。 – RisingUp

+0

をサポートしていただきありがとうございます:) –

1

これはAndroid Gradle Plugin v3 migration guideで覆われている:

出力の名前を変更するよりも複雑なユースケースのための新しいAPIがあります

Using the Variant API to manipulate variant outputs is broken with the new plugin. It still works for simple tasks, such as changing the APK name during build time, as shown below:

// 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 = "${project.name}-${variant.name}-${variant.versionName}.apk" 
    } 
} 

ファイル名。

+0

をサポートしていただきありがとうございます:) –

関連する問題