android-support-v4.jar中出现意外的顶级异常

prc*_*aen 9 android android-appcompat gradle facebook-android-sdk android-studio

我想编译我的应用程序时遇到问题:

意外的顶级异常:java.lang.IllegalArgumentException:已经添加了`

android-support-v4.jar似乎是一个错误.

在我的项目中,我有3个库:appcompat,facebook,google_play_services.

我的gradle文件:

  • AppProject/settings.gradle

    include ':libraries:google_play_services', ':libraries:appcompat', ':libraries:facebook', ':app'
    
    Run Code Online (Sandbox Code Playgroud)
  • AppProject/build.gradle:

    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:0.5.+'
        }
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • AppProject /应用/的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')
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • AppProject /库/程序兼容性/的build.gradle:

    apply plugin: 'android-library'
    
    dependencies {
        compile files('libs/android-support-v4.jar')
        compile files('libs/android-support-v7-appcompat.jar')
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • AppProject /库/ Facebook的/ buidle.gradle:

    apply plugin: 'android-library'
    
    dependencies {
        compile files('libs/android-support-v4.jar')
    }
    
    Run Code Online (Sandbox Code Playgroud)
  • AppProject /库/ google_play_services/buidle.gradle:

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

但是当我编译它时,会出现此错误:

Output:
        UNEXPECTED TOP-LEVEL EXCEPTION:
        java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/NotificationCompatIceCreamSandwich;
Run Code Online (Sandbox Code Playgroud)

你能帮助我吗?

prc*_*aen 8

我发现了问题:

AppProject/settings.gradle

include ':libraries:facebook', ':app'
Run Code Online (Sandbox Code Playgroud)

AppProject /库/ Facebook的/的build.gradle

apply plugin: 'android-library'

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
}
Run Code Online (Sandbox Code Playgroud)

AppProject /应用/的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')
}
Run Code Online (Sandbox Code Playgroud)

  • 嗨,你能详细说明问题是什么吗?你是怎么解决这个问题的? (18认同)

goR*_*Gon 6

Prcaen答案的主要思想是使用:

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

内部依赖部分而不是:

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

可以解决重复问题.它确实如此!