MultiDex支持Android应用程序错误

时间:2014-10-29 14:55:18

标签: android android-gradle android-5.0-lollipop dex

我想使用Android L compat libs。将相关代码添加到gradle后,我收到错误:

  Error Code:
2
  Output:
objc[36290]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: method ID not in [0, 0xffff]: 65536
  at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:501)
  at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:276)
  at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:490)
  at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:167)
  at com.android.dx.merge.DexMerger.merge(DexMerger.java:188)
  at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439)
  at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287)
  at com.android.dx.command.dexer.Main.run(Main.java:230)
  at com.android.dx.command.dexer.Main.main(Main.java:199)
  at com.android.dx.command.Main.main(Main.java:103)

我在herehere看到了有关它的问题,并尝试了此blog post的解决方案,我仍然收到错误,在博文中,我明白了:

  Error Code:
2  Output:
objc[36323]: Class JavaLaunchHelper is implemented in both /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java and /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre/lib/libinstrument.dylib. One of the two will be used. Which one is undefined.
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Library dex files are not supported in multi-dex mode
    at com.android.dx.command.dexer.Main.runMultiDex(Main.java:322)
    at com.android.dx.command.dexer.Main.run(Main.java:228)
    at com.android.dx.command.dexer.Main.main(Main.java:199)
    at com.android.dx.command.Main.main(Main.java:103)

这些是我的android gradle设置:

android {
compileSdkVersion 21
buildToolsVersion "20.0.0"

defaultConfig {
    applicationId "com.my.package"
    minSdkVersion 9
    targetSdkVersion 21
}

buildTypes {
    release {
        runProguard false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
    }
}

}

这些是我的依赖项:

dependencies {
compile project(':libraries:ecoGallery')
compile project(':libraries:facebookSDK')
compile 'com.android.support:support-v4:21.0.0'
compile 'com.android.support:appcompat-v7:21.0.0'
compile 'com.google.android.gms:play-services:6.1.71'
compile 'com.j256.ormlite:ormlite-android:4.48'
compile 'com.j256.ormlite:ormlite-core:4.48'
compile 'com.mixpanel.android:mixpanel-android:4.3.1@aar'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.nineoldandroids:library:2.4.0'
compile 'oauth.signpost:signpost-commonshttp4:1.2.1.2'
compile 'oauth.signpost:signpost-core:1.2.1.2'
compile 'com.uservoice:uservoice-android-sdk:+@aar'
compile 'com.newrelic.agent.android:android-agent:4.87.0'
compile 'com.google.guava:guava:18.0'
compile files('libs/android-support-multidex.jar')

}

有没有人对我可能做错的事情有任何想法?

5 个答案:

答案 0 :(得分:4)

适用于Android的Gradle插件v0.14.0添加了full multidex support 删除您所做的所有build.gradle更改(对于multidex),只需添加以下内容:

android {
   defaultConfig {
      ...
      multiDexEnabled = true
   }
}

答案 1 :(得分:2)

尝试将以下代码添加到build.gradle中,为我工作。

android{

...
dexOptions {
        preDexLibraries = false
    }

afterEvaluate {
        tasks.matching {
            it.name.startsWith('dex')
        }.each { dx ->
            if (dx.additionalParameters == null) {
                dx.additionalParameters = ['--multi-dex']
            } else {
                dx.additionalParameters += '--multi-dex'
            }
        }
    }
...
}

答案 2 :(得分:2)

而不是包括整个谷歌图书馆, 只使用你需要的那些。

代表。使用方法:

    compile 'com.google.android.gms:play-services-maps:7.8.0'
    compile 'com.google.android.gms:play-services-location:7.8.0'

而不是

compile 'com.google.android.gms:play-services:7.8.0'

答案 3 :(得分:0)

尝试禁用"即时运行":

在android studio中: 菜单文件 - >设置

在构建,执行,部署中 - >即时运行

UNCHECK已启用在部署时默认运行热交换代码/资源更改(默认启用)

答案 4 :(得分:0)

他们给你的答案都不详尽。问题出在Multidex上。您必须在app gradle中添加库:

implementation 'com.android.support:multidex:1.0.3'

之后,添加app gradle的defaultConfig:

multiDexEnabled true

您的应用程序必须是Multidex类型..您必须在清单中写下它:

android:name=".MyApplication"

MyApplication必须是Multidex类,或者必须扩展它。