4

I am newbie in gradle scripts, have only basic knowledge.
I have multiple modules inside my project. Here is screenshot.
enter image description here

In my project build.gradle file I have basic configuration.
As far as I know this file is for global project configuration.

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }

    }
}

All my module build.grade files have different dependencies. For instance.

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleDependency
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
    compile 'com.etsy.android.grid:library:1.0.5'
    compile 'com.squareup.picasso:picasso:2.3.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.5.3'
    compile 'com.fasterxml.jackson.core:jackson-core:2.5.3'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.5.3'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.github.ksoichiro:android-observablescrollview:1.5.1'
    compile 'com.viewpagerindicator:library:2.4.1@aar'
    compile 'com.android.support:cardview-v7:21.0.3'
    compile 'com.android.support:recyclerview-v7:21.0.3'
    compile 'org.codehaus.jackson:jackson-mapper-asl:1.9.13'
    compile('com.mikepenz.materialdrawer:library:2.9.7@aar') {
        transitive = true
    }
    compile project(':horizontalrecyclerview')
    compile project(':ultimaterecyclerview')
    compile 'org.lucasr.twowayview:core:1.0.0-SNAPSHOT@aar'
    compile 'org.lucasr.twowayview:layouts:1.0.0-SNAPSHOT@aar'
    compile 'com.yqritc:recyclerview-flexibledivider:1.2.4'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.malinskiy:superrecyclerview:1.1.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.1.1'
}

What is the problem ? Some of my modules require the same library dependency, or all modules require the same library. When I add dependency to each module build.gradle file, I get next error while project build.

Error:Execution failed for task ':app:processDebugResources'.
> Error: more than one library with package name 'com.mikepenz.iconics'
  You can temporarily disable this error with android.enforceUniquePackageName=false
  However, this is temporary and will be enforced in 1.0

How can I solve this problem ? Add dependency into the root build.gradle file or some other solution.
Or simply follow advice and set

android.enforceUniquePackageName=false
CROSP
  • 4,499
  • 4
  • 38
  • 89

1 Answers1

0

There are multiple archives with the same package (Either by having classes in it, or in AndroidManifest.xml. I am not sure). This is a mistake made by the developer of the archives.

If you add the following tasks to your build script and execute :lib-that-has-error:extractCompileDependencies, you will find the extracted dependencies in build/compileDependencies.

To fix this issue:

  • First make sure that you use the latest versions of the dependencies. Maybe the issue has already been reported and fixed.
  • If the problem persists with the latest versions, then check which extracted dependencies contain the same package. Ask the developer of those dependencies to fix the issue.
def compileDependenciesBuildDir = new File(buildDir, 'compileDependencies')

task copyCompileDependencies(type: Copy) {
    from configurations.compile
    into compileDependenciesBuildDir
}

task extractCompileDependencies() {
    inputs.files(copyCompileDependencies)

    doLast {
        compileDependenciesBuildDir.listFiles(new FileFilter() {
            @Override
            boolean accept(File pathname) {
                return pathname.isFile()
            }
        }).each {
            def unzippedDirectory = new File(it.parent, it.name + '-unzipped')
            ant.unzip(src: it, dest: unzippedDirectory, overwrite: 'true')
            def classesJarFile = new File(unzippedDirectory, 'classes.jar')
            if (classesJarFile.exists()) {
                ant.unzip(src: classesJarFile, dest: new File(unzippedDirectory, 'classes'), overwrite: 'true')
            }
        }
    }
}
Johan Stuyts
  • 3,607
  • 1
  • 18
  • 21