I'm developing a library for android that will be used in many applications. The library depends on some other libraries. For example, it uses Dagger 1.2, so if an app that will include my library will useDagger 2.0, the project won't build because of conflicts. What can I do?
I tried Jarjar, with this workspace gradle
buildscript {
repositories {
jcenter()
mavenLocal()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'net.vrallev.gradle:jarjar-gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
this is the app gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.xxx.yyy.sdklauncherapp"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile project(':library')
compile 'com.google.dagger:dagger:2.2'
}
and this is my library gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
apply plugin: 'net.vrallev.jarjar'
jarjar {
jarJarFile 'jarjar-1.4.jar'
rules = [
'rule com.squareup.dagger.** ext.com.squareup.dagger.@1'
]
srcExcludes = ['META-INF/**']
outputName 'build_repackaged.jar'
outputDir 'libs'
ignoreJarJarResult false
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
jarjar 'com.squareup.dagger:dagger:1.2.2'
}
答案 0 :(得分:0)
我正在和@Beni一起解决同样的问题,我们得到了一些解决这个问题的方法。坏消息与gradle版本插件有关。使用此解决方案,您可以使用gradle 1.3版本,因为我们使用的espresso gradle脚本正在寻找1.3 gradleversión中存在的任务,而不是以下版本。
所以这不是最好的方法,但它起作用并解决了我们的问题。无论如何,如果有人可以帮助不与任何gradle版本绑定,那将是很棒的。
我为您提供了解决方案的链接:https://github.com/GigigoGreenLabs/JarJarDagger2Example
您可以使用与jarjar类似的工具,请查看:
https://github.com/musketyr/gradle-fatjar-plugin
如果你使用maven,请使用Gradle shadow插件或maven shade插件。
希望这有帮助!