关于安卓Android studio Didn't find class "com.xx.MainActivity" on path: DexPathList[[zip……的解决

本文详细介绍了在Android应用开发中遇到的MultiDex问题及其解决方案。主要针对Android 4.4版本以下设备上出现的ClassNotFoundException,通过调整Build.gradle配置及自定义Application实现multiDex分包编译。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于安卓Android studio Didn’t find class “com.xx.MainActivity” on path: DexPathList[[zip……的解决

本文参考自简书:multiDexEnabled遇坑简记,感谢作者大大!!!

1、我的问题

首先说一下我的问题,我写的项目在安卓5.0以上的手机上运行的时候没有任何问题,但是在安卓4.4的手机上确直接闪退,报错Didn’t find class “com.xx.MainActivity” on path: DexPathList[[zip……,找不到MainActivity?什么鬼?然后查百度的时候有的人说是没有注册Activity,有的人说把build文件夹删去,clean project然后rebuild就好了,但是本人经过试验都不是这些错误,最后灵光乍现怀疑是不是因为在build gradle中配置了multiDexEnabled true的原因,顺着这个思路去查找,真的找到了答案,十分幸运在一天之内解决了这个恶心的问题。

//在build.grudle中我配置了:
defaultConfig {
    /**添加多 dex分包支持*/
    multiDexEnabled true
}

2、出错原因

先来说一下为什么要配置multiDexEnabled true,因为我们代码的总的方法数超过了goole规定的65535个方法,导致了jvm不能编译通过我们的代码,这是后就需要使用multiDexEnabled true来进行分包编译打包(不知道是什么名字,瞎叫的),就是我们把项目打成多个编译包(dex文件),而不是一个dex文件,这在安卓5.0以上没有问题,因为5.0系统上使用art 支持多dex,但是低版本dalvik默认先加载主dex,如果启动时需要的类不在主dex内就会报错ClassNotFoundException,所以会报这个错。

如何进行multiDex分包编译打包?

这里多写一些关于如何使用multiDex的内容,不需要使用multiDexEnabled true的朋友请自行略过:

(1)在 build.gradle(app或其他需要的模块)中配置支持multiDex:
//在build.grudle中配置:
defaultConfig {
    /**添加多 dex分包支持*/
    multiDexEnabled true
}
(2)在 build.gradle添加multiDex打包需要的依赖库:
dependencies {
    //新版本使用implementation关键字,旧版本请使用compile 'com.android.support:multidex:1.0.1'
    implementation 'com.android.support:multidex:1.0.1'
}
(3)自定义Application:

我们需要使用自定义的Application,没有自定义的小伙伴们需要自己自定义一个类继承android.support.multidex.MultiDexApplication,自定义了Application的小伙伴们也需要把继承的父类改成这个类,另外还需要在AndroidManifest.xml中把Application的name改成自己定义的Application:

<application
        android:name=".MyApplication"
        #其他属性………
</application>
(4)还需要最后一步,重写自定义的Application的attachBaseContext()方法:
@Override
protected void attachBaseContext(android.content.Context base) {
    super.attachBaseContext(base);
    android.support.multidex.MultiDex.install(this);
}

到此,multidex的配置就大功告成了!

3、解决方法

经过解压apk得知,发现里面有32个dex文件,一般不会拆分如此多,对于dex 的–multi-dex 选项设置与预编译的library工程有冲突,如果你的应用中包含引用的lirary工程,需要将预编译设置为false,即在 build.gradle中添加:

defaultConfig {
    /**添加多 dex分包支持*/
    multiDexEnabled true
    dexOptions{
        preDexLibraries = false
    }
}

再次编译打包后(建议还是先clean project一下并卸载原来的APP,以免出问题),apk内部只有2个dex文件,测试在4.4系统上完美运行!
最后再次感谢multiDexEnabled遇坑简记 的作者大大,撒花支持!

2025-07-14 19:12:21.243 15048-15048 nativeloader com.example.baiyunmap D Configuring clns-9 for other apk /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/base.apk. target_sdk_version=35, uses_libraries=, library_path=/data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64:/data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/base.apk!/lib/x86_64, permitted_path=/data:/mnt/expand:/data/user/0/com.example.baiyunmap 2025-07-14 19:12:21.246 15048-15048 CompatChangeReporter com.example.baiyunmap D Compat change id reported: 202956589; UID 10220; state: ENABLED 2025-07-14 19:12:21.251 15048-15048 ample.baiyunmap com.example.baiyunmap I AssetManager2(0x77841ae44c58) locale list changing from [] to [en-US] 2025-07-14 19:12:21.256 15048-15048 GraphicsEnvironment com.example.baiyunmap V Currently set values for: 2025-07-14 19:12:21.256 15048-15048 GraphicsEnvironment com.example.baiyunmap V angle_gl_driver_selection_pkgs=[] 2025-07-14 19:12:21.256 15048-15048 GraphicsEnvironment com.example.baiyunmap V angle_gl_driver_selection_values=[] 2025-07-14 19:12:21.256 15048-15048 GraphicsEnvironment com.example.baiyunmap V com.example.baiyunmap is not listed in per-application setting 2025-07-14 19:12:21.256 15048-15048 GraphicsEnvironment com.example.baiyunmap V ANGLE allowlist from config: 2025-07-14 19:12:21.256 15048-15048 GraphicsEnvironment com.example.baiyunmap V com.example.baiyunmap is not listed in ANGLE allowlist or settings, returning default 2025-07-14 19:12:21.256 15048-15048 GraphicsEnvironment com.example.baiyunmap V Neither updatable production driver nor prerelease driver is supported. 2025-07-14 19:12:21.270 15048-15048 nativeloader com.example.baiyunmap D Load /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_base_v7_6_5.so using class loader ns clns-9 (caller=/data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/base.apk!classes3.dex): ok 2025-07-14 19:12:21.301 15048-15048 CompatChangeReporter com.example.baiyunmap D Compat change id reported: 279646685; UID 10220; state: ENABLED 2025-07-14 19:12:21.314 15048-15048 PermissionCheck com.example.baiyunmap E The authManager is: null; the authCallback is: null; the mContext is: null 2025-07-14 19:12:21.319 15048-15048 BaiduApiAuth com.example.baiyunmap I BaiduApiAuth SDK Version:1.0.32 2025-07-14 19:12:21.334 15048-15085 ashmem com.example.baiyunmap E Pinning is deprecated since Android Q. Please use trim or other methods. 2025-07-14 19:12:21.369 15048-15085 CuidBuddyInfoManager com.example.baiyunmap W galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy 2025-07-14 19:12:21.370 15048-15085 CuidBuddyInfoManager com.example.baiyunmap W galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy 2025-07-14 19:12:21.370 15048-15085 CuidBuddyInfoManager com.example.baiyunmap W galaxy lib host missing meta-data,make sure you know the right way to integrate galaxy 2025-07-14 19:12:21.402 15048-15048 PermissionCheck com.example.baiyunmap E The authManager is: null; the authCallback is: null; the mContext is: null 2025-07-14 19:12:21.418 15048-15087 nativeloader com.example.baiyunmap D Load /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libtiny_magic.so using class loader ns clns-9 (caller=/data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/base.apk!classes4.dex): ok 2025-07-14 19:12:21.493 15048-15048 PermissionCheck com.example.baiyunmap E permission check result is: -11 2025-07-14 19:12:21.509 15048-15090 DisplayManager com.example.baiyunmap I Choreographer implicitly registered for the refresh rate. 2025-07-14 19:12:21.515 15048-15048 ample.baiyunmap com.example.baiyunmap I AssetManager2(0x77841ae4e578) locale list changing from [] to [en-US] 2025-07-14 19:12:21.532 15048-15048 CompatChangeReporter com.example.baiyunmap D Compat change id reported: 309578419; UID 10220; state: ENABLED 2025-07-14 19:12:21.534 15048-15048 DesktopModeFlags com.example.baiyunmap D Toggle override initialized to: OVERRIDE_UNSET 2025-07-14 19:12:21.536 15048-15090 EGL_emulation com.example.baiyunmap I Opening libGLESv1_CM_emulation.so 2025-07-14 19:12:21.537 15048-15090 EGL_emulation com.example.baiyunmap I Opening libGLESv2_emulation.so 2025-07-14 19:12:21.541 15048-15090 HWUI com.example.baiyunmap W Failed to choose config with EGL_SWAP_BEHAVIOR_PRESERVED, retrying without... 2025-07-14 19:12:21.541 15048-15090 HWUI com.example.baiyunmap W Failed to initialize 101010-2 format, error = EGL_SUCCESS 2025-07-14 19:12:21.569 15048-15048 nativeloader com.example.baiyunmap D Load /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so using class loader ns clns-9 (caller=/data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/base.apk): ok 2025-07-14 19:12:21.573 15048-15048 System.err com.example.baiyunmap W java.lang.ClassNotFoundException: Didn't find class "com.baidu.platform.comjni.map.cloudcontrol.NACloudControl" on path: DexPathList[[zip file "/data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/base.apk"],nativeLibraryDirectories=[/data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64, /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]] 2025-07-14 19:12:21.573 15048-15048 System.err com.example.baiyunmap W at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) 2025-07-14 19:12:21.574 15048-15048 System.err com.example.baiyunmap W at java.lang.ClassLoader.loadClass(ClassLoader.java:637) 2025-07-14 19:12:21.574 15048-15048 System.err com.example.baiyunmap W at java.lang.ClassLoader.loadClass(ClassLoader.java:573) 2025-07-14 19:12:21.575 15048-15048 System.err com.example.baiyunmap W at java.lang.Runtime.nativeLoad(Native Method) 2025-07-14 19:12:21.575 15048-15048 System.err com.example.baiyunmap W at java.lang.Runtime.loadLibrary0(Runtime.java:1088) 2025-07-14 19:12:21.576 15048-15048 System.err com.example.baiyunmap W at java.lang.Runtime.loadLibrary0(Runtime.java:1012) 2025-07-14 19:12:21.576 15048-15048 System.err com.example.baiyunmap W at java.lang.System.loadLibrary(System.java:1765) 2025-07-14 19:12:21.577 15048-15048 System.err com.example.baiyunmap W at com.baidu.mapsdkplatform.comapi.NativeLoader.a(NativeLoader.java:103) 2025-07-14 19:12:21.577 15048-15048 System.err com.example.baiyunmap W at com.baidu.mapsdkplatform.comapi.NativeLoader.loadLibrary(NativeLoader.java:84) 2025-07-14 19:12:21.577 15048-15048 System.err com.example.baiyunmap W at com.baidu.mapsdkplatform.comapi.map.i.<clinit>(EngineManager.java:272) 2025-07-14 19:12:21.578 15048-15048 System.err com.example.baiyunmap W at com.baidu.mapapi.map.MapView.a(MapView.java:456) 2025-07-14 19:12:21.579 15048-15048 System.err com.example.baiyunmap W at com.baidu.mapapi.map.MapView.<init>(MapView.java:179) 2025-07-14 19:12:21.579 15048-15048 System.err com.example.baiyunmap W at java.lang.reflect.Constructor.newInstance0(Native Method) 2025-07-14 19:12:21.579 15048-15048 System.err com.example.baiyunmap W at java.lang.reflect.Constructor.newInstance(Constructor.java:343) 2025-07-14 19:12:21.579 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.createView(LayoutInflater.java:743) 2025-07-14 19:12:21.579 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:895) 2025-07-14 19:12:21.580 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:850) 2025-07-14 19:12:21.581 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.rInflate(LayoutInflater.java:1012) 2025-07-14 19:12:21.581 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:973) 2025-07-14 19:12:21.582 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.inflate(LayoutInflater.java:571) 2025-07-14 19:12:21.582 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.inflate(LayoutInflater.java:462) 2025-07-14 19:12:21.582 15048-15048 System.err com.example.baiyunmap W at android.view.LayoutInflater.inflate(LayoutInflater.java:413) 2025-07-14 19:12:21.582 15048-15048 System.err com.example.baiyunmap W at com.android.internal.policy.PhoneWindow.setContentView(PhoneWindow.java:577) 2025-07-14 19:12:21.583 15048-15048 System.err com.example.baiyunmap W at android.app.Activity.setContentView(Activity.java:3892) 2025-07-14 19:12:21.583 15048-15048 System.err com.example.baiyunmap W at com.example.baiyunmap.MainActivity.onCreate(MainActivity.java:78) 2025-07-14 19:12:21.583 15048-15048 System.err com.example.baiyunmap W at android.app.Activity.performCreate(Activity.java:9155) 2025-07-14 19:12:21.583 15048-15048 System.err com.example.baiyunmap W at android.app.Activity.performCreate(Activity.java:9133) 2025-07-14 19:12:21.583 15048-15048 System.err com.example.baiyunmap W at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1521) 2025-07-14 19:12:21.583 15048-15048 System.err com.example.baiyunmap W at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4262) 2025-07-14 19:12:21.583 15048-15048 System.err com.example.baiyunmap W at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4467) 2025-07-14 19:12:21.584 15048-15048 System.err com.example.baiyunmap W at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:222) 2025-07-14 19:12:21.584 15048-15048 System.err com.example.baiyunmap W at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:133) 2025-07-14 19:12:21.585 15048-15048 System.err com.example.baiyunmap W at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:103) 2025-07-14 19:12:21.585 15048-15048 System.err com.example.baiyunmap W at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:80) 2025-07-14 19:12:21.586 15048-15048 System.err com.example.baiyunmap W at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2823) 2025-07-14 19:12:21.586 15048-15048 System.err com.example.baiyunmap W at android.os.Handler.dispatchMessage(Handler.java:110) 2025-07-14 19:12:21.586 15048-15048 System.err com.example.baiyunmap W at android.os.Looper.loopOnce(Looper.java:248) 2025-07-14 19:12:21.586 15048-15048 System.err com.example.baiyunmap W at android.os.Looper.loop(Looper.java:338) 2025-07-14 19:12:21.586 15048-15048 System.err com.example.baiyunmap W at android.app.ActivityThread.main(ActivityThread.java:9067) 2025-07-14 19:12:21.586 15048-15048 System.err com.example.baiyunmap W at java.lang.reflect.Method.invoke(Native Method) 2025-07-14 19:12:21.587 15048-15048 System.err com.example.baiyunmap W at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:593) 2025-07-14 19:12:21.587 15048-15048 System.err com.example.baiyunmap W at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:932) 2025-07-14 19:12:21.590 15048-15048 ample.baiyunmap com.example.baiyunmap W CheckJNI: method to register "nativeSetLayerTag" not in the given class. This is slow, consider changing your RegisterNatives calls. 2025-07-14 19:12:21.608 15048-15097 DEBUG com.example.baiyunmap D ThreadProc, CVSocketMan::SocketThreadProc start ... 2025-07-14 19:12:21.611 15048-15048 NetworkLogic com.example.baiyunmap D onNetWorkChanged-0, oldType = mobile 2025-07-14 19:12:21.613 15048-15048 PermissionCheck com.example.baiyunmap E permission check result is: -11 2025-07-14 19:12:21.613 15048-15098 NetworkLogic com.example.baiyunmap D NetworkDetect 2025-07-14 19:12:21.621 15048-15098 DEBUG com.example.baiyunmap D CNetworkDetectEngine::NetworkDetect Start 1 2025-07-14 19:12:21.664 15048-15048 libc com.example.baiyunmap A Fatal signal 11 (SIGSEGV), code 128 (SI_KERNEL), fault addr 0x0 in tid 15048 (ample.baiyunmap), pid 15048 (ample.baiyunmap) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A Cmdline: com.example.baiyunmap 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A pid: 15048, tid: 15048, name: ample.baiyunmap >>> com.example.baiyunmap <<< 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #00 pc 00000000004cab64 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (_baidu_framework::CBaseLayer::CBaseLayer()+148) (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #01 pc 000000000072d769 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #02 pc 0000000000741036 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #03 pc 000000000043abb0 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (_baidu_framework::CVComServer::ComCreateInstance(_baidu_vi::CVString const&, _baidu_vi::CVString const&, void**)+112) (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #04 pc 000000000052e8b1 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #05 pc 0000000000530502 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #06 pc 0000000000522990 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (_baidu_framework::IVMapbaseFactory::CreateInstance(_baidu_vi::CVString const&, void**)+128) (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #07 pc 000000000043abb0 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (_baidu_framework::CVComServer::ComCreateInstance(_baidu_vi::CVString const&, _baidu_vi::CVString const&, void**)+112) (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.746 15112-15112 DEBUG crash_dump64 A #08 pc 000000000048b694 /data/app/~~OljfxsydegH-sraOS4Y7Kg==/com.example.baiyunmap-QyH9YPNP5Ohzcm110rmefQ==/lib/x86_64/libBaiduMapSDK_map_for_navi_v7_6_5.so (BuildId: 72389d7e76ac01b9603c2b9a85daaaadbdc06757) 2025-07-14 19:12:22.750 15112-15112 DEBUG crash_dump64 A #143 pc 000000000000161c <anonymous:7784fd1de000> (com.example.baiyunmap.MainActivity.onCreate+0)
最新发布
07-15
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值