启用proguard时找不到kotlin对象类

问题描述

当禁用proguard时,我的应用程序运行良好,但是一旦启用,它就会破坏功能我有一个名为CachecManager的类,一旦启用了proguard后就无法访问。 这是我的课程

object Cachemanger {
    fun setData(data: String) {
        val yourFilePath: String = BaseClass.appContext.filesDir.toString() + "/" + USER_DATA
        val yourFile = File(yourFilePath)
        val fileOutputStream = FileOutputStream(yourFile)
        fileOutputStream.write(data.toByteArray())
        fileOutputStream.flush()
        fileOutputStream.close()
    }
}

这是我的保护文件

##---------------Begin: proguard configuration for Gson  ----------
# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default,so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { <fields>; }

# Prevent proguard from stripping interface information from TypeAdapter,TypeAdapterFactory,# JsonSerializer,JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * extends com.google.gson.TypeAdapter
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

# Prevent R8 from leaving Data object members always null
-keepclassmembers,allowobfuscation class * {
  @com.google.gson.annotations.Serializedname <fields>;
}

##---------------End: proguard configuration for Gson  ----------

#project related
-keep class com.appname.constants
-keep class com.appname.models.** { *; }
-keepnames class androidx.navigation.fragment.NavHostFragment
#-keep class <class>$Companion { *; }



-keep class kotlin.** { *; }
-keep class kotlin.Metadata { *; }
-dontwarn kotlin.**
-keepclassmembers class **$WhenMappings {
    <fields>;
}
-keepclassmembers class kotlin.Metadata {
    public <methods>;
}
-assumenosideeffects class kotlin.jvm.internal.Intrinsics {
    static void checkParameterIsNotNull(java.lang.Object,java.lang.String);
}

这是我得到的错误

java.lang.classNotFoundException: Didn't find class "com.appname.cachemanager.Cachemanger" on path: DexPathList[[zip file "/data/app/com.appname-2/base.apk"],nativeLibraryDirectories=[/data/app/com.appname-2/lib/arm64,/data/app/com.appname-2/base.apk!/lib/arm64-v8a,/vendor/lib64,/system/lib64]]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)