Gradle依赖问题android

时间:2015-09-17 03:34:02

标签: android android-gradle build.gradle

我注意到io.reactive和estimote的sdk之间存在冲突,但我似乎无法弄清楚如何解决它。老实说,我只是通过删除estimote依赖关系然后删除两个reactivex依赖项并找到项目功能来注意到冲突。我试过排除常见的库,但似乎没有任何工作。这就是我拥有的一切:

原始错误:

UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
    at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502)
    at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277)
    at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2

摇篮:

apply plugin: 'com.android.application'
apply plugin: 'io.fabric'


buildscript {
    repositories {

//
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {



        classpath 'io.fabric.tools:gradle:1.+'
    }
}



repositories {
    mavenCentral()
//
    maven { url 'https://maven.fabric.io/public' }
}

android {

    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.whats.up"
        minSdkVersion 18
        targetSdkVersion 18
        versionCode 49
        versionName "2.0"
    }



    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.+'
    compile 'com.android.support:support-v4:20.0.+'
    compile 'uk.co.chrisjenx:calligraphy:2.0.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.mixpanel.android:mixpanel-android:4.5.3'
    compile 'com.google.android.gms:play-services:6.+'
    compile 'com.github.ksoichiro:android-observablescrollview:1.5.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.castorflex.smoothprogressbar:library:1.1.0'
    compile project(":libs:library")
    compile 'io.realm:realm-android:0.81.1'
    compile files('libs/cwac-merge-1.1.1-2.jar')
    compile files('libs/cwac-camera-0.6.12.jar')
    compile 'com.makeramen:roundedimageview:2.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.android.support:cardview-v7:22.1.1'
    compile('com.twitter.sdk.android:twitter:1.0.0@aar') {
        transitive = true;
    }
    compile 'io.reactivex:rxandroid:1.0.1'
    compile 'io.reactivex:rxjava:1.0.0'
    compile ('com.estimote:sdk:0.8.6@aar'){
//
        exclude module: 'appcompat-v7'
        exclude module: 'support-v4'
        exclude module: 'support-annotations'
        exclude module: 'junit'
        exclude module: 'io.reactivex'
        exclude group: 'com.google.android'
        exclude group: 'com.google.android.*'
        exclude group: 'com.google.code.findbugs'
        exclude group: 'com.android.dx'
    }
    compile('com.twitter.sdk.android:tweet-composer:0.7.0@aar')
            {
                transitive = true;
            }
    compile('com.crashlytics.sdk.android:crashlytics:2.5.1@aar') {
        transitive = true;

    }
}

./ gradlew -q app:dependencies:

compile - Classpath for compiling the main sources.
+--- com.android.support:appcompat-v7:21.0.+ -> 21.0.3
|    \--- com.android.support:support-v4:21.0.3 -> 22.0.0
|         \--- com.android.support:support-annotations:22.0.0
+--- com.android.support:support-v4:20.0.+ -> 22.0.0 (*)
+--- uk.co.chrisjenx:calligraphy:2.0.1
+--- com.squareup.retrofit:retrofit:1.9.0
|    \--- com.google.code.gson:gson:2.3.1
+--- com.squareup.picasso:picasso:2.5.2
+--- com.mixpanel.android:mixpanel-android:4.5.3
+--- com.google.android.gms:play-services:6.+ -> 6.5.87
|    \--- com.android.support:support-v4:21.0.0 -> 22.0.0 (*)
+--- com.github.ksoichiro:android-observablescrollview:1.5.2
|    \--- com.android.support:recyclerview-v7:21.0.0
|         \--- com.android.support:support-v4:21.0.0 -> 22.0.0 (*)
+--- com.nineoldandroids:library:2.4.0
+--- com.github.castorflex.smoothprogressbar:library:1.1.0
+--- project :libs:library
|    \--- com.android.support:support-v4:22.0.0 (*)
+--- io.realm:realm-android:0.81.1
+--- com.makeramen:roundedimageview:2.1.0
+--- com.facebook.android:facebook-android-sdk:4.0.0
|    +--- com.android.support:support-v4:[21,22) -> 22.0.0 (*)
|    \--- com.parse.bolts:bolts-android:1.1.4
+--- com.android.support:cardview-v7:22.1.1
+--- com.twitter.sdk.android:twitter:1.0.0
|    +--- com.twitter.sdk.android:tweet-composer:0.7.0
|    |    +--- com.twitter.sdk.android:twitter-core:1.0.0
|    |    |    +--- com.squareup.retrofit:retrofit:1.6.1 -> 1.9.0 (*)
|    |    |    +--- io.fabric.sdk.android:fabric:1.0.0 -> 1.3.5
|    |    |    \--- com.google.code.gson:gson:2.2.4 -> 2.3.1
|    |    \--- io.fabric.sdk.android:fabric:1.0.0 -> 1.3.5
|    +--- com.digits.sdk.android:digits:1.0.0
|    |    +--- com.twitter.sdk.android:twitter-core:1.0.0 (*)
|    |    +--- io.fabric.sdk.android:fabric:1.0.0 -> 1.3.5
|    |    \--- com.twitter.sdk.android:tweet-ui:1.0.0
|    |         +--- com.twitter.sdk.android:twitter-core:1.0.0 (*)
|    |         +--- com.squareup.picasso:picasso:2.3.2 -> 2.5.2
|    |         +--- io.fabric.sdk.android:fabric:1.0.0 -> 1.3.5
|    |         \--- com.android.support:support-v4:21.0.0 -> 22.0.0 (*)
|    +--- com.twitter.sdk.android:twitter-core:1.0.0 (*)
|    +--- io.fabric.sdk.android:fabric:1.0.0 -> 1.3.5
|    \--- com.twitter.sdk.android:tweet-ui:1.0.0 (*)
+--- io.reactivex:rxandroid:1.0.1
|    \--- io.reactivex:rxjava:1.0.13
+--- io.reactivex:rxjava:1.0.0 -> 1.0.13
+--- com.estimote:sdk:0.8.6
+--- com.twitter.sdk.android:tweet-composer:0.7.0 (*)
\--- com.crashlytics.sdk.android:crashlytics:2.5.1
     +--- io.fabric.sdk.android:fabric:1.3.5
     +--- com.crashlytics.sdk.android:crashlytics-core:2.3.4
     |    +--- io.fabric.sdk.android:fabric:1.3.5
     |    \--- com.crashlytics.sdk.android:answers:1.3.1
     |         \--- io.fabric.sdk.android:fabric:1.3.5
     +--- com.crashlytics.sdk.android:beta:1.1.3
     |    \--- io.fabric.sdk.android:fabric:1.3.4 -> 1.3.5
     \--- com.crashlytics.sdk.android:answers:1.3.1 (*)

我非常不确定如何解释那里的最后一部分 - 所以如果我的问题被揭示,我很想知道如何找到它以供将来参考!谢谢!

2 个答案:

答案 0 :(得分:3)

简单,不推荐修复是:

在你的应用的build.gradle中:

android {
   ...
   defaultConfig {
       ...
       // Enabling multidex support.
       multiDexEnabled true
   }
...
}

dependencies {
  compile 'com.android.support:multidex:1.0.0'
}

在AndroidManifest.xml中:

<application
    ...
    android:name="android.support.multidex.MultiDexApplication">
    ...
</application>

原因:

  

Android应用程序(APK)文件包含Dalvik可执行文件(DEX)文件形式的可执行字节码文件,其中包含用于运行应用程序的已编译代码。 Dalvik可执行规范将单个DEX文件中可引用的方法总数限制为65,536,包括Android框架方法,库方法和您自己的代码中的方法。超过此限制要求您配置应用程序构建过程以生成多个DEX文件,称为多索引配置。

此处的所有详细信息:Building Apps with Over 65k Methods

虽然给出的答案将是解决当前问题的快捷方式,但 Android建议不要使用它,或者至少建议您尽可能避免使用它。

减少您的dexcount

尽管真的需要它们,但请尽量避免依赖大型开源项目。如果你无法避免这些,请以聪明的方式使用它们。像GooglePlayServices这样的库可以让您使用其API的子集来防止此类问题。

例如,你有:

com.google.android.gms:play-services:6.+ // The ENTIRE play-services library

你真的需要整个游戏服务库吗?该库非常庞大,谷歌为您提供了使用您需要的组件的方法,比如说您想使用Google帐户登录,您可以改为:

com.google.android.gms:play-services-identity:X.+ // Google Account Login only
com.google.android.gms:play-services-analytics:X.+ // Google Analytics
com.google.android.gms:play-services-maps:X.+ // Google Maps...
// ... and so on.

有关播放服务的各个API列表,请参阅Setting Up Google Play Services

跟踪你的dexcount

有几个库可以帮助您跟踪您的dexcount,以防止您达到限制。一个例子:

Dexcount Gradle Plugin

此库将跟踪您的dexcount并在您构建时报告它,例如:

> ./gradlew assembleDebug

...buildspam...
:app:compileDebugSources
:app:preDexDebug UP-TO-DATE
:app:dexDebug
:app:packageDebug
:app:zipalignDebug
:app:assembleDebug
Total methods in MyApp-debug-5.3.14.apk: 56538

答案 1 :(得分:0)

 dependencies {
  compile 'com.android.support:multidex:1.0.0'
}
defaultConfig 中的

并添加此

$user_profile = $facebook->api('/me');

https://developer.android.com/tools/building/multidex.html

https://developer.android.com/reference/android/support/multidex/MultiDexApplication.html