Android 无法实例化应用程序proguard

Android 无法实例化应用程序proguard,android,android-studio,proguard,Android,Android Studio,Proguard,当我使用proguard时,它总是出现这样的错误。我不知道该怎么办,我已经尝试了所有的教程。请帮助任何能帮助的人 Process: com.example.belajarproguard, PID: 22062 java.lang.RuntimeException: Unable to instantiate application com.example.belajarproguard.MVVMApplication: java.lang.ClassNotFoundException: Did

当我使用proguard时,它总是出现这样的错误。我不知道该怎么办,我已经尝试了所有的教程。请帮助任何能帮助的人

Process: com.example.belajarproguard, PID: 22062
java.lang.RuntimeException: Unable to instantiate application com.example.belajarproguard.MVVMApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.belajarproguard.MVVMApplication" on path: DexPathList[[zip file "/data/app/com.example.belajarproguard-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.belajarproguard-2/lib/x86, /system/lib, /vendor/lib]]
    at android.app.LoadedApk.makeApplication(LoadedApk.java:802)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5335)
    at android.app.ActivityThread.-wrap2(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.belajarproguard.MVVMApplication" on path: DexPathList[[zip file "/data/app/com.example.belajarproguard-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.belajarproguard-2/lib/x86, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.Instrumentation.newApplication(Instrumentation.java:992)
    at android.app.LoadedApk.makeApplication(LoadedApk.java:796)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5335) 
    at android.app.ActivityThread.-wrap2(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1528) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
MVVM应用程序

class MVVMApplication : Application(), KodeinAware {

    override val kodein = Kodein.lazy {
        import(androidXModule(this@MVVMApplication))

        bind() from singleton { NetworkConnectionInterceptor(instance()) }
        bind() from singleton { BasicAuth() }
        bind() from singleton { MyApi(instance(), instance()) }
        bind() from singleton { MarketingRepo(instance(), instance()) }
        bind() from singleton { AppDatabase(instance()) }
        bind() from singleton { PageFragmentsViewModelFactory(instance()) }
    }

}

在您的
proguard规则文件中,请输入以下规则:

-keep class com.example.belajarproguard.** { *; }

如果您使用的是
androidX
,则可以使用
@Keep
注释

@Keep
class MVVMApplication : Application(), KodeinAware {

    override val kodein = Kodein.lazy {
        import(androidXModule(this@MVVMApplication))

        bind() from singleton { NetworkConnectionInterceptor(instance()) }
        bind() from singleton { BasicAuth() }
        bind() from singleton { MyApi(instance(), instance()) }
        bind() from singleton { MarketingRepo(instance(), instance()) }
        bind() from singleton { AppDatabase(instance()) }
        bind() from singleton { PageFragmentsViewModelFactory(instance()) }
    }

}

此问题已解决,问题在multidex中

java.lang.RuntimeException: Unable to instantiate application com.example.belajarproguard.MVVMApplication: java.lang.ClassNotFoundException: Didn't find class "com.example.belajarproguard.MVVMApplication" on path: DexPathList[[zip file "/data/app/com.example.belajarproguard-2/base.apk"],nativeLibraryDirectories=[/data/app/com.example.belajarproguard-2/lib/x86, /system/lib, /vendor/lib]]
你只需要改变一下

class MVVMApplication : Application(), KodeinAware {

将此添加到类中

override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }
并将其添加到依赖项中

implementation 'androidx.multidex:multidex:2.0.1'
来源

别忘了
清理项目之前

请显示您的proguard规则文件以及MVVMApplication classI尚未输入任何规则yetI放入规则-keep class com.example.belajarproguard,并且没有任何更改
implementation 'androidx.multidex:multidex:2.0.1'