1

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'
}
Federico Picci
  • 1,105
  • 10
  • 17
  • 1
    Now, we have the same problem in this moment. We have tried some jarjar tools, Gradle's FatJar, and don't achieve with a solution. Now, we are trying the [espresso solution](https://android.googlesource.com/platform/frameworks/testing/+/android-support-test/espresso/core/build.gradle) library which is using a jarjar script in compile time, but we don't have a right solution yet. – beni Apr 07 '16 at 13:25
  • Other approach is Picasso library which has zero dependencies when it is imported and it uses okhttp library. When is upload to the maven repository, it changes the dependency as optional. But, we don't have any success – beni Apr 07 '16 at 13:34
  • Thanks @beni , if we achieve some progress, I'll let you know. I hope you'll do the same ;) – Federico Picci Apr 07 '16 at 13:49

1 Answers1

0

I'm working with @Beni in the same problem and we get some working solution to this problem. The bad news are related with gradle version plugin. With this solution you are tied to gradle 1.3 version because espresso gradle script we are using is looking for a task that is present in 1.3 gradle versión and not in the following versions.

So this is not the best approach ever, but it works and solves our problem. Anyway if someone can help to not be tied to any gradle version it would be great.

I give you a link with our solution: https://github.com/GigigoGreenLabs/JarJarDagger2Example

You have similar tools to jarjar that you can use, have a look at:

https://github.com/musketyr/gradle-fatjar-plugin

Gradle shadow plugin or maven shade plugin if you are using maven.

Hope this helps!