意想不到的顶级例外:在Android Studio中

时间:2015-10-30 14:44:54

标签: android android-gradle

我知道这里已被问过太多次了,但我还是无法解决这个问题。我已经尝试过以前问题中提供的解决方案,但它们并没有以某种方式工作。

这是我的gradle依赖 -

compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.google.android.gms:play-services:8.1.0'
compile 'com.facebook.android:facebook-android-sdk:3.22.0'
compile project(':IndicatorLib')
compile 'com.makeramen:roundedimageview:1.5.0'
compile 'com.github.clans:fab:1.5.0'
// GMS in the library was causing merging error, we need to exclude the duplicate dependencies
compile ('io.nlopez.smartlocation:library:3.2.0') { exclude group: 'com.google.android.gms'}

这是我的gradle依赖项输出 -

_releaseApk - ## Internal use, do not manually configure ##
+--- com.google.code.gson:gson:2.3.1
+--- com.android.support:appcompat-v7:23.1.0
|    \--- com.android.support:support-v4:23.1.0
|         \--- com.android.support:support-annotations:23.1.0
+--- com.google.android.gms:play-services:8.1.0
|    +--- com.google.android.gms:play-services-ads:8.1.0
|    |    +--- com.google.android.gms:play-services-basement:8.1.0
|    |    |    \--- com.android.support:support-v4:22.2.0 -> 23.1.0 (*)
|    |    \--- com.google.android.gms:play-services-appindexing:8.1.0
|    |         \--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-analytics:8.1.0
|    |    +--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-ads:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appindexing:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appinvite:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0
|    |         \--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appstate:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-cast:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.android.support:mediarouter-v7:22.2.0
|    |         \--- com.android.support:appcompat-v7:22.2.0 -> 23.1.0 (*)
|    +--- com.google.android.gms:play-services-drive:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-fitness:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-location:8.1.0
|    |         +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |         \--- com.google.android.gms:play-services-maps:8.1.0
|    |              \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-games:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-drive:8.1.0 (*)
|    +--- com.google.android.gms:play-services-gcm:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-identity:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-location:8.1.0 (*)
|    +--- com.google.android.gms:play-services-maps:8.1.0 (*)
|    +--- com.google.android.gms:play-services-measurement:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-analytics:8.1.0 (*)
|    +--- com.google.android.gms:play-services-nearby:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-panorama:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-plus:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-safetynet:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-vision:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-wallet:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    +--- com.google.android.gms:play-services-identity:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-maps:8.1.0 (*)
|    \--- com.google.android.gms:play-services-wearable:8.1.0
|         \--- com.google.android.gms:play-services-base:8.1.0 (*)
+--- com.facebook.android:facebook-android-sdk:3.22.0
|    +--- com.android.support:support-v4:[21,22) -> 23.1.0 (*)
|    \--- com.parse.bolts:bolts-android:1.1.4
+--- project :IndicatorLib
|    \--- com.android.support:support-v4:21.0.3 -> 23.1.0 (*)
+--- com.makeramen:roundedimageview:1.5.0
+--- com.github.clans:fab:1.5.0
\--- io.nlopez.smartlocation:library:3.2.0
     \--- com.android.support:support-annotations:23.0.1 -> 23.1.0

_releaseCompile - ## Internal use, do not manually configure ##
+--- com.google.code.gson:gson:2.3.1
+--- com.android.support:appcompat-v7:23.1.0
|    \--- com.android.support:support-v4:23.1.0
|         \--- com.android.support:support-annotations:23.1.0
+--- com.google.android.gms:play-services:8.1.0
|    +--- com.google.android.gms:play-services-ads:8.1.0
|    |    +--- com.google.android.gms:play-services-basement:8.1.0
|    |    |    \--- com.android.support:support-v4:22.2.0 -> 23.1.0 (*)
|    |    \--- com.google.android.gms:play-services-appindexing:8.1.0
|    |         \--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-analytics:8.1.0
|    |    +--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-ads:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appindexing:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appinvite:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0
|    |         \--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-appstate:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-basement:8.1.0 (*)
|    +--- com.google.android.gms:play-services-cast:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.android.support:mediarouter-v7:22.2.0
|    |         \--- com.android.support:appcompat-v7:22.2.0 -> 23.1.0 (*)
|    +--- com.google.android.gms:play-services-drive:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-fitness:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-location:8.1.0
|    |         +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |         \--- com.google.android.gms:play-services-maps:8.1.0
|    |              \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-games:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-drive:8.1.0 (*)
|    +--- com.google.android.gms:play-services-gcm:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-identity:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-location:8.1.0 (*)
|    +--- com.google.android.gms:play-services-maps:8.1.0 (*)
|    +--- com.google.android.gms:play-services-measurement:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-analytics:8.1.0 (*)
|    +--- com.google.android.gms:play-services-nearby:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-panorama:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-plus:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-safetynet:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-vision:8.1.0
|    |    \--- com.google.android.gms:play-services-base:8.1.0 (*)
|    +--- com.google.android.gms:play-services-wallet:8.1.0
|    |    +--- com.google.android.gms:play-services-base:8.1.0 (*)
|    |    +--- com.google.android.gms:play-services-identity:8.1.0 (*)
|    |    \--- com.google.android.gms:play-services-maps:8.1.0 (*)
|    \--- com.google.android.gms:play-services-wearable:8.1.0
|         \--- com.google.android.gms:play-services-base:8.1.0 (*)
+--- com.facebook.android:facebook-android-sdk:3.22.0
|    +--- com.android.support:support-v4:[21,22) -> 23.1.0 (*)
|    \--- com.parse.bolts:bolts-android:1.1.4
+--- project :IndicatorLib
|    \--- com.android.support:support-v4:21.0.3 -> 23.1.0 (*)
+--- com.makeramen:roundedimageview:1.5.0
+--- com.github.clans:fab:1.5.0
\--- io.nlopez.smartlocation:library:3.2.0
     \--- com.android.support:support-annotations:23.0.1 -> 23.1.0

据我所知,smartlocation库是造成问题的主要罪魁祸首,因为如果删除此库,应用程序正在构建。根据库的build.gradle,我认为唯一可以冲突的是GMS库,我已经为其添加了排除,但这也给出了同样的错误。我还能做些什么来解决这个问题?

更新: -

这是错误日志 -

Error:Execution failed for task ':app:dexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    F:\Android SDK\build-tools\21.1.2\dx.bat --dex --no-optimize --output F:\Android Projects\Office Projects\Git Synced\new\app\build\intermediates\dex\debug --input-list=F:\Android Projects\Office Projects\Git Synced\new\app\build\intermediates\dex\debug\inputList.txt
Error Code:
    2
Output:
    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)         在com.android.dx.command.Main.main(Main.java:106)

1 个答案:

答案 0 :(得分:8)

错误表示您的应用程序及其引用的库达到一定的大小,您遇到的构建错误表明您的应用已达到Android应用构建体系结构的限制。

所以你必须把它MultiDexApplication

gradle的一部分

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 21

        // Enabling multidex support.
        multiDexEnabled true
    }
}

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

创建一个扩展MultiDexApplication的类,并在清单

中定义该类

public class CustomMultiDexApplication extends MultiDexApplication {

     @Override
    public void onCreate() {
        super.onCreate();
    }
}

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.android.multidex.myapplication">
    <application
        android:name="your.package.name.CustomMultiDexApplication">
    </application>
</manifest>

support v7的一个提示包括support v4,因此不需要添加v4库的依赖关系。