2017-07-18 37 views
5

我想爲debug構建類型而不是release構建類型中的一個構建類型,它有一個不同的versionCode。這用於在Gradle Android插件v2.3.2(Gradle v3.3)中使用下面的配置來工作,但現在在v3.0.0-alpha5(Gradle v4.1-milestone-1)中沒有任何效果。任何關於在最新的Gradle插件中發生了什麼變化的想法,使其忽略variant.mergedFlavor.versionCode屬性?Gradle 3.0.0 alpha變體輸出問題

buildTypes {  
     debug { 
       applicationIdSuffix ".debug" 
       versionNameSuffix "-" + buildTime() 
       android.applicationVariants.all { variant -> 
        if (variant.buildType.name != buildTypes.debug.name) return 
        variant.outputs.all { 
         outputFileName = "${archivesBaseName}-${variant.name}-v${variant.versionName}-signed.apk" 
         variant.mergedFlavor.versionCode = Integer.parseInt(buildTimeSmall()) 
        } 
       } 
      } 
} 

回答

2

migration guide

使用變API操縱變體輸出被打破與新的插件。它仍然可以用於簡單的任務,例如在編譯時間改變APK名,如下圖所示:

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

然而,涉及訪問OUTPUTFILE對象更復雜的任務不再起作用。這是因爲變體特定的任務不再在配置階段創建。這會導致插件不能預先知道所有的輸出,但這也意味着更快的配置時間。作爲替代,我們將引入新的API來提供類似的功能。

+0

我讀過,但他們提到了outputFile的變化,而不是變體本身。或者我錯過了什麼? –

+1

'使用Variant API來操作變體輸出...',基本上你在你的groovy代碼中使用了這個API:'variant.outputs.all {...}' – azizbekian

+1

我的不好,閱讀正確的..希望他們會在未來的版本中添加對某些屬性的支持。 –