Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected Top-Level Exception in android-support-v4.jar

I have a problem when I want to compile my app:

UNEXPECTED TOP-LEVEL EXCEPTION: java.lang.IllegalArgumentException: already added`

It seems to be a error with android-support-v4.jar.

In my project I have 3 libraries: appcompat, facebook, google_play_services.

My gradle files:

  • AppProject/settings.gradle

    include ':libraries:google_play_services', ':libraries:appcompat', ':libraries:facebook', ':app'
    
  • AppProject/build.gradle :

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.5.+'
        }
    }
    
  • AppProject/app/build.gradle:

    apply plugin: 'android'
    
    dependencies {
        compile project(':libraries:appcompat')
        compile project(':libraries:facebook')
        compile project(':libraries:google_play_services')
        compile files('libs/android-async-http-1.4.3.jar')
        compile files('libs/gson-2.2.4.jar')
        compile files('libs/libGoogleAnalyticsV2.jar')
        compile files('libs/universal-image-loader-1.8.4.jar')
        compile files('libs/urbanairship-lib-3.0.0.jar')
    }
    
  • AppProject/libraries/appcompat/build.gradle:

    apply plugin: 'android-library'
    
    dependencies {
        compile files('libs/android-support-v4.jar')
        compile files('libs/android-support-v7-appcompat.jar')
    }
    
  • AppProject/libraries/facebook/buidle.gradle:

    apply plugin: 'android-library'
    
    dependencies {
        compile files('libs/android-support-v4.jar')
    }
    
  • AppProject/libraries/google_play_services/buidle.gradle:

    apply plugin: 'android-library'
    
    dependencies {
        compile files('libs/google-play-services.jar')
    }
    

But when I compile it, this error appears:

Output:
        UNEXPECTED TOP-LEVEL EXCEPTION:
        java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/NotificationCompatIceCreamSandwich;

Can you help me?

like image 214
prcaen Avatar asked Jul 30 '13 13:07

prcaen


2 Answers

I found the problem :

AppProject/settings.gradle

include ':libraries:facebook', ':app'

AppProject/libraries/facebook/build.gradle

apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}

AppProject/app/build.gradle

apply plugin: 'android'

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile 'com.android.support:appcompat-v7:18.0.+'
    compile 'com.google.android.gms:play-services:3.1.36'

    compile project(':libraries:facebook')
    compile files('libs/android-async-http-1.4.3.jar')
    compile files('libs/gson-2.2.4.jar')
    compile files('libs/libGoogleAnalyticsV2.jar')
    compile files('libs/universal-image-loader-1.8.4.jar')
    compile files('libs/urbanairship-lib-3.0.0.jar')
}
like image 53
prcaen Avatar answered Oct 22 '22 04:10

prcaen


The main idea in Prcaen's answer is that using:

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

inside dependency section instead of:

compile files('libs/google-play-services.jar')

can solve the duplication problem. And it does!

like image 33
goRGon Avatar answered Oct 22 '22 06:10

goRGon