MultiDexExtractor在错误的dex文件中 [英] MultiDexExtractor in wrong dex file

查看:177
本文介绍了MultiDexExtractor在错误的dex文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个太大的应用程序,无法放入一个dex文件,所以我正在使用multidex。当我在某些机器上创建它时,它工作的很好,但是当我在另一个机器上创建它时,应用程序在某些设备上崩溃,而不是所有(注2上的崩溃,在Nextus 6上运行)。

  8519-8519 /? E / AndroidRuntime:FATAL EXCEPTION:main 
android.support.multidex.MultiDex.install(MultiDex.java:159)
java.lang.NoClassDefFoundError:android.support.multidex.MultiDexExtractor
在android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
在android.app.ActivityThread.handleBindApplication(ActivityThread.java) :4228)
at android.app.ActivityThread.access $ 1300(ActivityThread.java:140)
at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1287)
at android .os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898 )在java.lang.reflect.Method.invokeNative处使用
(Native Method)在java.lang.reflect.Method.invoke处使用
(Method.java:511 )
at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1008)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
at dalvik.system.NativeStart.main(Native Method)

我反编译APK,发现MultiDexExtractor类在classes2.dex中,而不是classes.dex。



我认为gradle v1.0.0及以上版本会自动将所有类放入正确的dex中?任何想法?



在gradle文件中,我添加了

 编译'com.android.support:multidex:1.0.0'

p>

  multiDexEnabled true 



在默认配置中

然后在应用程序文件中:

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

我正在使用android构建工具 22.0。 1



以下是我的gradle版本:

  $ ./gradlew --version 

------------------------------- -----------------------------
Gradle 2.2.1
--------- -------------------------------------------------- -

Build time:2014-11-24 09:45:35 UTC
版本号:无
版本:6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a

Groovy:2.3。 6
Ant:2013年12月23日编译的Apache Ant(TM)1.9.3版本
JVM:1.8.0_25(Oracle Corporation 25.25-b02)
操作系统:Mac OS X 10.9.5 x86_64


解决方案

首先,mutidex最近的版本是1.0.1,所以我会建议更新你的依赖。其次,你并没有展示整个Application类,但除非你真的知道你需要现在的东西,否则我会建议扩展 android.support.multidex.MultiDexApplication ,所以你不需要需要打扰所有的init,因为MultiDexApplication会照顾到这一点。 MultiDex与我的应用程序没有问题,但是我自己扩展了 android.support.multidex.MultiDexApplication


I have an app that is too big to fit into one dex file so I'm using multidex. It works fine when i create it on certain machines, but when i create it on another one, the app crashes on some devices, not all (crashes on Note 2, works on Nextus 6).

8519-8519/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.NoClassDefFoundError: android.support.multidex.MultiDexExtractor
            at android.support.multidex.MultiDex.install(MultiDex.java:159)
            at com.myapp.MyApplication.onCreate(MyApplication.java:39)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1014)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4228)
            at android.app.ActivityThread.access$1300(ActivityThread.java:140)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1287)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:4898)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1008)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:775)
            at dalvik.system.NativeStart.main(Native Method)

I decompiled the APK, and found that the MultiDexExtractor class is in classes2.dex instead of classes.dex where it should be.

I thought gradle v1.0.0 and above is placing all the classes in the correct dex automatically? Any ideas?

In the gradle file, i've added

compile 'com.android.support:multidex:1.0.0'

in the dependencies and

multiDexEnabled true

in the default config

Then in the Application file:

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

I'm using the android build tools 22.0.1

And here are my gradle versions:

$ ./gradlew --version

------------------------------------------------------------
Gradle 2.2.1
------------------------------------------------------------

Build time:   2014-11-24 09:45:35 UTC
Build number: none
Revision:     6fcb59c06f43a4e6b1bcb401f7686a8601a1fb4a

Groovy:       2.3.6
Ant:          Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM:          1.8.0_25 (Oracle Corporation 25.25-b02)
OS:           Mac OS X 10.9.5 x86_64

解决方案

First, mutidex recent version is 1.0.1, so I'd suggest updating your dependency. Second, you did not show whole Application class but unless you really know you need what you have now, I'd suggest extending android.support.multidex.MultiDexApplication so you do not need to bother all the init as MultiDexApplication would take care of this. I had no problems with MultiDex with my apps, but I am extending android.support.multidex.MultiDexApplication myself.

这篇关于MultiDexExtractor在错误的dex文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆