Android could not get unknown property for applicationVariants

1
could not get unknown property for 'applicationVariants' for BuildType xxxx
1
2
3
4
5
6
7
buildTypes {
    release {
        applicationVariants.all { variant ->
            appendVersionName(variant, defaultConfig)
        }
    }
}

applicationVariants 只包含在 apply plugin: 'com.android.application' 插件中

如果使用 apply plugin: 'com.android.library'

1
2
3
4
5
6
7
buildTypes {
    release {
       libraryVariants.all { variant ->
            appendVersionName(variant, defaultConfig)
        }
    }
}
  • applicationVariants 只在 com.android.application
  • libraryVariants 只在 com.android.library
  • testVariants 都含有,但一般只有默认的 debug