我想根据产品风格使用不同的图像,如果是调试或发布,res 文件夹的正确设置是什么来实现这一点?
在我的 build.gradle 中:
productFlavors {
flavor1 {
applicationId "com.myapp.flavor1"
}
flavor2 {
applicationId "com.myapp.flavor2"
}
}
buildTypes {
debug {
applicationIdSuffix '.debug'
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
shrinkResources true
useProguard true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
在我的文件夹结构中,我现在有:
src/flavor1/res
/flavor2/res
/main/res
/debug/res
我试过在我的调试文件夹中将 flavor1 和 flavor2 作为带有资源的子文件夹,但这不适用。在调试中只有一个 res 文件夹会导致两种风格的 Assets 相同,而我希望它们不同。那么我该如何设置项目,以便根据调试/发布和不同的产品风格获得不同的图像?
编辑:
更新文件夹结构
最佳答案
来自安卓build variants docs ,
Gradle automatically creates build variants based on your build types and product flavors, and names them according to
product-flavor Build-Type
所以在您的情况下,您已经有 4 个变体。如果你想要不同的源集,你可以像下面这样
src/flavor1Debug
src/flavor2Release
等等..注意命名约定
关于android - 如何根据发布/调试为不同的产品风格和不同的图标设置 gradle?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41219832/