您的位置:首页 > 编程语言 > Java开发

关于分包后的apk运行发生java.lang.NoClassDefFoundError的问题

2016-06-16 14:20 399 查看
这次在开发过程中遇到了应用提交应用市场审核不通过的问题,小米开放平台给我发来了Log文件,一看发现是 java.lang.NoClassDefFoundError
这个错误引起了,反复查看代码就是没找到问题出在哪儿,百度半天一点进展没有。

然后谷歌了一下  出来了很多stackoverflow的结果  于是  我解决了  

发下原地址:http://stackoverflow.com/questions/32110859/fatal-exception-java-lang-noclassdeffounderror-android-support-v7-appcompat-r

具体就是因为我项目中引用各种第三方sdk、jar包导致项目开始变得臃肿,然后方法名过多做了分包的处理

重点就是这个  做了分包处理后 我周围的安卓机都是Android 5.0以上的系统  Android 5.0以上的系统能够正常读取拆分后的dex包 而Android 5.0以下的版本则不能

为此 我用multirom给我的Nexus 5多刷了一个Android 4.4版本miui系统  发现确实是这样 应用一启动直接就崩了

然后根据stackoverflow上的大神给出了方法成功解决了这个问题。

就酱。

我把解决问题关键内容直接贴出来好了

I faced the same issue and fixed it. It is issue with Dex limit. Because the dex limit is reached, it creates two dex files. Lollipop knows how to read, pre-Lollipop has no idea unless you specify it in the
Application
class.

Please make sure following is in place:

in build.gradle

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

IMPORTANT to support pre-Lollipop:

In Manifest, under the application tag,

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

Or if you have used your own
Application
class, make your
Application
override
attachBaseContext
starting with

import android.support.multidex.MultiDexApplication;
import android.support.multidex.MultiDex;

public class MyApplication extends MultiDexApplication {
// ......

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Android