7

I have update my android studio and SDK and some package dependencies on grade of the project and since then I have faced with a lot of problem that I think the reason is incompatibility between dependencies.

As I researched I found that many people have same problems and it is not rare. I have solved some of the error but problems just appears one after another and I am just confused. hope you can help me find out the problem and its solution.

Code works well on new android versions ! (a little strange) and I can compile and run the app on android 21+. but when I try to run it on below 21 android version it give me an error. Every thing was ok before I migrate to Android studio 2.

Here is the error code I get now :

FAILURE: Build failed with an exception.
  • What went wrong: Execution failed for task ':transformClassesWithJarMergingForDebug'.

    com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/annotation/WorkerThread.class

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

here is the project grade file :

task wrapper(type: Wrapper) {
    gradleVersion = '2.2'
}
buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.1.0'
        classpath 'com.google.gms:google-services:2.1.0'

    }


}
apply plugin: 'com.android.application'
allprojects {
    repositories {
        jcenter()
        flatDir {
            dirs 'libs'
        }
    }
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile(name: 'aescrypt-0.0.1', ext: 'aar')
    compile project(':viewmover-1.1.0 (1)')
    compile project(':fab-1.1.2')
    compile files('libs/slf4j-api-1.7.18.jar')
    compile project(':uitools-1.1.0')
    compile('com.android.support:appcompat-v7:23.4.0') {
        exclude group: 'com.google.android', module: 'support-v4'
    }
    compile 'com.android.support:design:23.4.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.github.paolorotolo:appintro:3.4.0'


    compile ('com.google.android.gms:play-services-gcm:8.1.0')   {
        exclude group: 'com.google.android', module: 'support-v4'


    }
}


android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'

    configurations{
        all*.exclude module: 'annotation'
    }
    defaultConfig {
        applicationId "co.goldentime"
        multiDexEnabled true
        minSdkVersion 16
        targetSdkVersion 23
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['submodules/linphone/mediastreamer2/java/src', 'submodules/linphone/java/j2se', 'submodules/linphone/java/common', 'submodules/linphone/java/impl', 'submodules/externals/axmlrpc/src/main/java', 'submodules/linphone/coreapi/help/java', 'src']
            resources.srcDirs = ['submodules/linphone/mediastreamer2/java/src', 'submodules/linphone/java/j2se', 'submodules/linphone/java/common', 'submodules/linphone/java/impl', 'submodules/externals/axmlrpc/src/main/java', 'submodules/linphone/coreapi/help/java', 'src']
            aidl.srcDirs = ['submodules/linphone/mediastreamer2/java/src', 'submodules/linphone/java/j2se', 'submodules/linphone/java/common', 'submodules/linphone/java/impl', 'submodules/externals/axmlrpc/src/main/java', 'submodules/linphone/coreapi/help/java', 'src']
            renderscript.srcDirs = ['submodules/linphone/mediastreamer2/java/src', 'submodules/linphone/java/j2se', 'submodules/linphone/java/common', 'submodules/linphone/java/impl', 'submodules/externals/axmlrpc/src/main/java', 'submodules/linphone/coreapi/help/java', 'src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDir 'libs'

            java.exclude '**/mediastream/MediastreamerActivity.java'
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }


}
apply plugin: 'com.google.gms.google-services'

I find out there is problem with different version of support-v4 but I do not know which one should be exclude. I have a "android-support-v4.jar" in the libs.

let me know if it is needed some other information.

thank you.

Sir1
  • 732
  • 1
  • 8
  • 18
  • 1
    Possible duplicate of [Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'](http://stackoverflow.com/questions/33209631/errorexecution-failed-for-task-apptransformclasseswithjarmergingfordebug) – Harshad Pansuriya May 26 '16 at 12:10
  • remove `module: 'support-v4'` – IntelliJ Amiya May 26 '16 at 12:15
  • @IntelliJAmiya from where do u mean ? I mean I used it to exclude support version 4 two times. I should delete both? – Sir1 May 26 '16 at 12:17
  • @SirvanParaste yes .then `clean-rebuild-run` – IntelliJ Amiya May 26 '16 at 12:25
  • @Ironman I tried that and it did not solve the problem – Sir1 May 26 '16 at 12:35
  • @IntelliJAmiya I tried, still same error message, The build finished successfully but running the project cause that error – Sir1 May 26 '16 at 12:36
  • 1
    call `compile 'com.android.support:support-v4:23.0.1'` remove`jar `and `module: 'support-v4'` – IntelliJ Amiya May 26 '16 at 12:39
  • Why do you need to explicitly have JAR files? Hint: the appcompat-v7 library already includes the v4 library, so you don't need it. I assume this fine started in Eclipse because I know it likes to require you to have the v4 jar in your project (at least it used to) – OneCricketeer May 26 '16 at 12:49
  • 1
    @IntelliJAmiya Thank you very much, It is ok now, I have removed the jar file and that support-v4 , Although in the logs I see some problem with appcompat-v7 but app compiled and run now – Sir1 May 26 '16 at 13:29
  • @SirvanParaste Move ahead . – IntelliJ Amiya May 26 '16 at 13:32

1 Answers1

8

You should add

compile 'com.android.support:support-v4:23.0.1'

And remove

  • module: 'support-v4'

  • android-support-v4.jar

Then Clean-Rebuild-Sync & Run your Project .Hope this helps

IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198