9

Ich habe ein Problem, wenn ich meine app kompilieren wollen:Unexpected Top-Level-Exception in android-support-v4.jar

UNERWARTETE TOP-LEVEL AUSNAHME: java.lang.IllegalArgumentException: bereits added`

Es scheint ein Fehler mit android-support-v4.jar zu sein.

In meinem Projekt habe ich 3 Bibliotheken: appcompat, facebook, google_play_services.

Meine gradle Dateien:

  • 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/Bibliotheken/appcompat/build.gradle:

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

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

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

Aber wenn ich es kompilieren, diese Fehlermeldung angezeigt:

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

Können Sie mir helfen?

Antwort

8

fand ich das Problem:

AppProject/settings.gradle

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

AppProject/Bibliotheken/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') 
} 
+18

Hallo, können Sie näher erläutern, was das Problem war? Und wie hast du dieses Problem gelöst? – yasith

2

Sie haben wahrscheinlich diese JAR-Datei zweimal in Ihrem Projekt enthalten. Versuchen Sie, zu Datei -> Projektstruktur zu gehen und zu prüfen, ob Sie 2 identische Module oder Bibliotheken haben.

2

Wie ich von Ihren Build-Dateien sehen können, haben Sie Android-Support-Bibliothek zu zwei Ihrer Module hinzugefügt. Ich hatte genau das gleiche Problem und löste es, indem ich die Bibliothek aus dem Hauptmodul entfernte und nur noch eins für die Bibliothek übrig ließ. Ich bin mir nicht sicher, dass dies die beste Lösung ist, aber es funktioniert und Gradle beschweren sich nicht.

6

Die Hauptidee in Antwort Prcaen ist, dass mit:

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

innerhalb Abhängigkeit Abschnitt statt:

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

die Duplizierung Problem lösen können. Und es tut!