2017-06-13 30 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) 
      } 
     } 

不過從Android的工作室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

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

將有更復雜的使用情況下比在重命名輸出一個新的API文件名。

+0

謝謝你的支持:) –

相關問題