微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

启用proguard时找不到kotlin对象类

如何解决启用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 举报,一经查实,本站将立刻删除。