没钱吃肉
2018-01-06 07:40
采纳率: 100%
浏览 3.6k

加上自定义Application之后报错(ClassNotFoundException)

相关代码

Application类:

package com.weyes.focus;

import android.app.Application;

public class MyApplication extends Application {}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.weyes.focus">

    <application
        android:name="com.weyes.focus.MyApplication"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>

                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>
</manifest>

问题描述

添加:android:name="com.weyes.focus.MyApplication"
项目在安卓5.0以上运行都没有问题。
在4.x上运行报错。我这里三台手机都报错,红米(4.2.1)、三星(4.3)、酷派(4.4.4)。

删除:android:name="com.weyes.focus.MyApplication"
所有手机运行正常。

报错信息

01-06 15:28:08.720 25650-25650/? E/AndroidRuntime: FATAL EXCEPTION: main
                                                   java.lang.RuntimeException: Unable to get provider com.luck.picture.lib.PictureFileProvider: java.lang.ClassNotFoundException: Didn't find class "com.luck.picture.lib.PictureFileProvider" on path: DexPathList[dexElements=[zip file "/data/app/com.weyes.focus-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.weyes.focus-1, /vendor/lib, /system/lib]]
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:5115)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4670)
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4606)
                                                       at android.app.ActivityThread.access$1300(ActivityThread.java:162)
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414)
                                                       at android.os.Handler.dispatchMessage(Handler.java:99)
                                                       at android.os.Looper.loop(Looper.java:153)
                                                       at android.app.ActivityThread.main(ActivityThread.java:5383)
                                                       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:853)
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
                                                       at dalvik.system.NativeStart.main(Native Method)
                                                    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.luck.picture.lib.PictureFileProvider" on path: DexPathList[dexElements=[zip file "/data/app/com.weyes.focus-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.weyes.focus-1, /vendor/lib, /system/lib]]
                                                       at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
                                                       at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
                                                       at android.app.ActivityThread.installProvider(ActivityThread.java:5100)
                                                       at android.app.ActivityThread.installContentProviders(ActivityThread.java:4670) 
                                                       at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4606) 
                                                       at android.app.ActivityThread.access$1300(ActivityThread.java:162) 
                                                       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1414) 
                                                       at android.os.Handler.dispatchMessage(Handler.java:99) 
                                                       at android.os.Looper.loop(Looper.java:153) 
                                                       at android.app.ActivityThread.main(ActivityThread.java:5383) 
                                                       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:853) 
                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
                                                       at dalvik.system.NativeStart.main(Native Method) 

这里报错说找不到这个类com.luck.picture.lib.PictureFileProvider,其实不单单是这个类,而是所有类都找不到,但这些类确实都是存在的,也就是类加载的时候就有问题了,实在不知道哪里出了问题,哪路大神碰过类似的问题么?求指教!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 昵称_Justin 2018-01-06 07:47
    已采纳

    你这个问题是分包错误,一、配置build.gradle (app)

    android { compileSdkVersion 25 buildToolsVersion "25.0.2" defaultConfig { applicationId "" minSdkVersion 15 targetSdkVersion 25 versionCode 1 versionName "1.0.0" multiDexEnabled true }
    dependencies { compile 'com.android.support:multidex:1.0.0' }
    二、使用自定义的Application继承MultiDexApplication这个类,或者重写Application的方法attachBaseContext(),并调用MultiDex.install();

    @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(base); }
    三、到项目的根目录下执行 ./gradlew clean build

    点赞 评论
  • bjshanxi2017 2018-01-07 10:22

    你这个问题是分包错误

    点赞 评论

相关推荐 更多相似问题