为每种产品口味使用不同的 Android SDK(库存和定制)

Use different Android SDK (stock and custom) for each product flavor

我需要针对特定​​设备的库存 Android SDK 和自定义 Android SDK 构建我的应用程序并修改 AOSP。

我的想法是在我的 build.gradle 中使用产品风格来有条件地指向正确的 SDK 目录。基本上,我正在寻找具有以下效果的东西:

productFlavors {
    stock {
        sdk.dir "/path/to/stocksdk"
    }
    mydevice {
        sdk.dir "/path/to/customsdk"
    }
}

查看 ProductFlavor DSL 文档,没有 属性 设置 SDK 目录。

还有哪些其他方法可以达到类似的效果?

有趣的问题,但不幸的是你不能productFlavorsbuildTypes设置不同的SDK。您只能在项目级别拥有它。

Product flavors can customize the following properties:

minSdkVersion
targetSdkVersion
versionCode
versionName
package name (overrides value from manifest)
release signing info (keystore, key alias, passwords,...).
BuildConfig: Ability to provide custom Java code.
NDK ABI filter (Not implemented yet)
test info
package name for test app (optional, default is <base>.test)
InstrumentationTestRunner class (optional)
Additionally, Product Flavor can provide their own source code, resources and manifest.

A Build Type provides configuration for the following build properties:

manifest debuggable flag
native compilation debug flag
proguard enabled + specific rules (Not implemented yet)
debug signing flag (ie whether to use debug key or release key)
package name suffix (2)
version name suffix (new in milestone 0.3)
Buildconfig
DEBUG flag. Set automatically based on the manifest debuggable flag.
Ability to provide custom Java code.

Source (Build System Concepts on http://tools.android.com/tech-docs/)

What other ways could I achieve a similar result?

您可以将此项目设为库项目,然后使用不同的 SDK 创建包装器项目,只需使用库中的功能即可。所以现在你有一个单独的包装器项目而不是 productFlavors,你可以在 local.properties 文件中为每个包装器项目更改 sdk.dir