我们有两个不同的风味维度,就像在这个例子中一样,我们想要动态生成 applicationId 像
com.company.apple
相反,此脚本将生成一个 applicationId
null.company.apple
我相信这是因为底部的函数迭代了整个 productFlavor 列表,而不是组合列表。
flavorDimensions "product", "license"
productFlavors.all {
ext.scheme = null
ext.scheme_tail = ""
ext.kind = null
ext.license = null
}
productFlavors {
apple {
dimension "product"
kind = "apple"
scheme = "companyapple"
}
orange {
dimension "product"
scheme = "companyorange"
kind = "orange"
}
kiwi {
dimension "product"
scheme = "companykiwi"
kind = "kiwi"
}
com {
dimension "license"
license = "com"
scheme_tail = ''
}
eu {
dimension "license"
license = "eu"
scheme_tail = "eu"
}
uk {
dimension "license"
license = "uk"
scheme_tail = "uk"
}
}
productFlavors.all {
applicationId license + ".company." + kind
ext.fileProvider = applicationId + ".fileprovider"
manifestPlaceholders = [scheme: "$scheme$scheme_tail", fileProvider: "$fileProvider"]
buildConfigField("String", "FILE_PROVIDER", "\"$fileProvider\"")
buildConfigField("String", "SCHEME", "\"$scheme$scheme_tail\"")
buildConfigField("String", "KIND", "\"$kind\"")
buildConfigField("String", "LICENSE", "\"$license\"")
}
如何遍历组合列表以构建我的 buildConfig 字段和 applicationIds?
manifestPlaceholders 的使用方式如下:
<activity android:name=".FruitViewerActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="${scheme}" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${fileProvider}"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
谢谢,罗里