【问题标题】:Unexpected Top-Level Exception in android-support-v4.jarandroid-support-v4.jar 中的意外顶级异常
【发布时间】:2013-07-30 13:01:56
【问题描述】:

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

意外的顶级异常: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/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')
    }
    

但是我编译的时候出现这个错误:

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

你能帮帮我吗?

【问题讨论】:

    标签: android gradle android-studio facebook-android-sdk android-appcompat


    【解决方案1】:

    我发现了问题:

    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')
    }
    

    【讨论】:

    • 您好,您能详细说明问题所在吗?你是如何解决这个问题的?
    【解决方案2】:

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

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

    在 dependency 部分而不是:

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

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

    【讨论】:

      【解决方案3】:

      您的项目中可能包含两次该 jar 文件。尝试转到 File -> Project Structure 并检查您是否有 2 个相同的模块或库。

      【讨论】:

        【解决方案4】:

        正如我从您的构建文件中看到的,您已将 android-support 库添加到您的两个模块中。我有完全相同的问题,并通过从主模块中删除库来解决它,只留下一个库一个。我不确定这是不是最好的解决方案,但它可以工作并且 gradle 不会抱怨。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2015-04-04
          • 1970-01-01
          • 2015-09-07
          • 2015-08-29
          • 2014-11-04
          • 1970-01-01
          • 2016-01-31
          相关资源
          最近更新 更多