当我想编译我的应用时遇到问题:
意外的顶层例外: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'
AppProject / build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
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')
}
AppProject /库/程序兼容性/的build.gradle:
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/android-support-v7-appcompat.jar')
}
AppProject /库/实/ buidle.gradle:
apply plugin: 'android-library'
dependencies {
compile files('libs/android-support-v4.jar')
}
AppProject /库/ google_play_services / buidle.gradle:
apply plugin: 'android-library'
dependencies {
compile files('libs/google-play-services.jar')
}
但是当我编译它时,会出现此错误:
Output:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Landroid/support/v4/app/NotificationCompatIceCreamSandwich;
你能帮助我吗?
答案 0 :(得分:8)
我发现了问题:
<强> AppProject / settings.gradle 强>
include ':libraries:facebook', ':app'
<强> AppProject /库/实/的build.gradle 强>
apply plugin: 'android-library'
dependencies {
compile 'com.android.support:support-v4:18.0.0'
}
<强> 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')
}
答案 1 :(得分:6)
Prcaen的答案主要是使用:
compile 'com.android.support:support-v4:18.0.0'
在依赖部分中,而不是:
compile files('libs/google-play-services.jar')
可以解决重复问题。 确实如此!
答案 2 :(得分:2)
您的项目中可能包含两次jar文件。尝试转到文件 - &gt;项目结构并检查您是否有2个相同的模块或库。
答案 3 :(得分:2)
正如我从构建文件中看到的那样,您已经将android-support库添加到了两个模块中。我有完全相同的问题并通过从主模块中删除库来解决它,只留下库中的库。我不确定这是最好的解决方案,但它有效并且gradle不会抱怨。