如何在不同的android构建变体之间共享依赖关系?
我有一个Android库项目(RealCoolLib)。RealCoolLib的用户有时希望将依赖项打包到aar中,有时他们希望以正常的渐变方式使用它。我的身材渐变如下所示:如何在不同的android构建变体之间共享依赖关系?,android,gradle,groovy,android-gradle-plugin,build.gradle,Android,Gradle,Groovy,Android Gradle Plugin,Build.gradle,我有一个Android库项目(RealCoolLib)。RealCoolLib的用户有时希望将依赖项打包到aar中,有时他们希望以正常的渐变方式使用它。我的身材渐变如下所示: apply plugin: 'com.android.library' android { compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_COMPILE_SDK_VERSION) buildToolsVersion project.ANDR
apply plugin: 'com.android.library'
android {
compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_COMPILE_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION
defaultConfig {
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode 1
versionName 1.0.0
}
buildTypes {
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'client-proguard.txt'
}
releaseNoPro {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'client-proguard.txt'
}
releaseWithJars {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'client-proguard.txt'
}
releaseWithJarsNoPro {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
consumerProguardFiles 'client-proguard.txt'
}
}
}
dependencies {
compile 'com.googlelib.everyone.needs.this:1.0.0'
debugCompile 'com.tools.debugversion:0.0.5'
debugCompile 'org.awesome.stuff.debug:2.0.0'
debugCompile 'com.another.tool.needed:3.0.0'
releaseCompile 'com.tools.releaseversion:1.0.0'
releaseCompile 'org.awesome.stuff:2.0.0'
releaseCompile 'com.another.tool.needed:3.0.0'
releaseNoProCompile 'com.tools.releaseversion:1.0.0'
releaseNoProCompile 'org.awesome.stuff:2.0.0'
releaseNoProCompile 'com.another.tool.needed:3.0.0'
releaseWithJarsProvided file('stuff/com_tools_releaseversion.jar')
releaseWithJarsCompile file('stuff/org_awesome_stuff.jar')
releaseWithJarsCompile file('stuff/com_another_tool_needed.jar')
releaseWithJarsNoProProvided file('stuff/com_tools_releaseversion.jar')
releaseWithJarsNoProCompile file('stuff/org_awesome_stuff.jar')
releaseWithJarsNoProCompile file('stuff/com_another_tool_needed.jar')
}
这会导致大量重复的依赖项声明。有没有办法创建一个保存jar列表的“单元”
依赖项和另一个具有正常符号的依赖项?基本上,我正在寻找一些方法来减少重复。您可以这样做:
configurations {
baseConfiguration
configurationA {
extendsFrom(baseConfiguration)
}
configurationB {
extendsFrom(baseConfiguration)
}
}
dependencies {
baseConfiguration('junit:junit:4.12')
}
然后,当运行/gradlew dependencies
时,您可以看到configurationA
和configurationB
包含与baseConfiguration
相同的依赖项:
baseConfiguration
\--- junit:junit:4.12
\--- org.hamcrest:hamcrest-core:1.3
configurationA
\--- junit:junit:4.12
\--- org.hamcrest:hamcrest-core:1.3
configurationB
\--- junit:junit:4.12
\--- org.hamcrest:hamcrest-core:1.3
Docs:我会试一试。所以我试过了,但似乎因为安卓对它的口味和变体做了一些特殊的处理,所以我只能进行一次分组。