简体   繁体   English

MultiDex支持Android应用程序错误

[英]MultiDex support in Android application error

I want to use Android L compat libs. 我想使用Android L compat libs。 after adding the relevant code to gradle, I get the error: 将相关代码添加到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)

I saw questions about it this here and here , and tried out the solution from this blog post , and I still get an error, where in the case of the blog post, I get: 我在这里这里看到了有关它的问题,并从这篇博客文章中尝试了解决方案,我仍然得到一个错误,在博客文章的情况下,我得到:

  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)

These are my android gradle settings: 这些是我的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'
    }
}

} }

These are my dependencies: 这些是我的依赖:

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

} }

Does anyone have any ideas for what I might be doing wrong? 有没有人对我可能做错了什么有任何想法?

Gradle plugin v0.14.0 for Android adds full multidex support . 适用于Android的Gradle插件v0.14.0增加了完整的multidex支持
Remove all the build.gradle changes you made (for multidex), and simply add the following: 删除您所做的所有build.gradle更改(对于multidex),只需添加以下内容:

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

Trying adding the following code to your build.gradle, worked for me. 尝试将以下代码添加到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'
            }
        }
    }
...
}

instead of including the entire google library, use only the ones you require. 而不是包括整个谷歌图书馆,只使用你需要的。

for ex. 对于前 use: 使用:

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

instead of 代替

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

Try to disabled "Instant run": 尝试禁用“即时运行”:

In android studio: Menu File -> Settings 在android studio中:菜单文件 - >设置

In Build, Execution, Deployment -> Instant run 在构建,执行,部署 - >即时运行

UNCHECK Enabled Instant Run to hot swap code/resource changes on deploy (default enabled) UNCHECK已启用在部署时立即运行到热交换代码/资源更改(默认启用)

None of the answers they gave you were exhaustive. 他们给你的答案都没有详尽无遗。 The problem lies in the Multidex. 问题出在Multidex上。 You must add the library in the app gradle : 您必须在app gradle中添加库:

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

After, add in the defaultConfig of the app gradle : 之后,添加app gradle的defaultConfig:

multiDexEnabled true

Your Application must be of the Multidex type.. You must write it in the manifest : 您的应用程序必须是Multidex类型..您必须在清单中写入它:

android:name=".MyApplication"

MyApplication must be either the Multidex class, or it must extend it. MyApplication必须是Multidex类,或者必须扩展它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM