Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android 混淆問題記錄can't find superclass or interface

Android 混淆問題記錄can't find superclass or interface

編輯:關於Android編程

今天用了AS混淆項目,工程使用了fastjson解析數據,混淆出現以下問題:

Warning:com.alibaba.fastjson.support.jaxrs.FastJsonProvider: can't find superclass or interface javax.ws.rs.ext.MessageBodyReader
Warning:com.alibaba.fastjson.support.jaxrs.FastJsonProvider: can't find superclass or interface javax.ws.rs.ext.MessageBodyWriter
Warning:com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter: can't find superclass or interface org.springframework.http.converter.AbstractHttpMessageConverter
Warning:com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter: can't find superclass or interface org.springframework.http.converter.GenericHttpMessageConverter
Warning:com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4: can't find superclass or interface org.springframework.http.converter.AbstractGenericHttpMessageConverter
Warning:com.alibaba.fastjson.support.spring.FastJsonJsonView: can't find superclass or interface org.springframework.web.servlet.view.AbstractView
Warning:com.alibaba.fastjson.support.spring.FastjsonSockJsMessageCodec: can't find superclass or interface org.springframework.web.socket.sockjs.frame.AbstractSockJsMessageCodec
Warning:retrofit.RxSupport$1: can't find superclass or interface rx.Observable$OnSubscribe
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.format.DateTimeFormatter
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDate
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDate
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.ZonedDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.OffsetDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.OffsetTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.ZoneId
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.Period
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.Duration
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.Instant
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.format.DateTimeFormatter
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDate
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.temporal.TemporalAccessor
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.format.DateTimeFormatter
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDate
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDate
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.ZonedDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.OffsetDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.OffsetTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.ZoneId
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.Period
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.Duration
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.Instant
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.format.DateTimeFormatter
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.format.DateTimeFormatter
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDate
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.format.DateTimeFormatter
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.LocalDateTime
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.temporal.TemporalAccessor
Warning:com.alibaba.fastjson.parser.deserializer.Jdk8DateCodec: can't find referenced class java.time.format.DateTimeFormatter
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalInt
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalLong
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalDouble
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.Optional
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalDouble
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalInt
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalLong
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.Optional
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalDouble
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalInt
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.OptionalLong
Warning:com.alibaba.fastjson.parser.deserializer.OptionalCodec: can't find referenced class java.util.Optional
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Point
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Rectangle
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Font
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Color
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Point
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Font
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Rectangle
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Color
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Font
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Color
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Rectangle
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Point
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Font
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Rectangle
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Color
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Font
Warning:com.alibaba.fastjson.serializer.AwtCodec: can't find referenced class java.awt.Color

然後網上查找一下,發現都說加上-keep class javax.ws.rs.* { ; }
和-ignorewarnings就可以了

#忽略警告
-ignorewarnings
-keep class javax.ws.rs.** { *; }
-dontwarn com.alibaba.fastjson.**
-keep class com.alibaba.fastjson.** { *; }

然後發現也不行,一直在混淆中,1個小時過去提示:
PSI and index do not match:PSI and index do not match
又按網上說的Invalidate Caches/Restart…
還是不行!
這裡寫圖片描述

後面發現build.gradle配置的問題!!!
getDefaultProguardFile(‘proguard-android.txt’), “proguard-rules.pro”
一定要加一個”proguard-rules.pro”,之前一直把混淆放在proguard-android.txt:getDefaultProguardFile(‘proguard-android.txt’)。<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4NCjxwPnByb2d1YXJkLXJ1bGVzLnByb8P719a/ydLUy+ax48iho6zIu7rzsNG77M/9t8XA78Pmo6E8L3A+DQo8cHJlIGNsYXNzPQ=="brush:java;"> buildTypes { release { buildConfigField "boolean", "LOG_DEBUG", "false" // 不顯示Log minifyEnabled true // 混淆 // shrinkResources true // 移除無用的resource文件 proguardFiles getDefaultProguardFile('proguard-android.txt'), "proguard-rules.pro" signingConfig signingConfigs.release // defaultConfig { // } } debug { buildConfigField "boolean", "LOG_DEBUG", "true" // 顯示Log signingConfig signingConfigs.debug // defaultConfig { // } } }

proguard-rules.pro內容:

#不壓縮輸入的類文件
-dontshrink
#指定代碼的壓縮級別
-optimizationpasses 5
#包明不混合大小寫
-dontusemixedcaseclassnames
#不去忽略非公共的庫類
-dontskipnonpubliclibraryclasses
#優化  不優化輸入的類文件
-dontoptimize
#預校驗
-dontpreverify
#混淆時是否記錄日志
 -verbose
# 混淆時所采用的算法
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
#保護注解
-keepattributes *Annotation*
#忽略警告
-ignorewarnings

-keep public class * extends android.app.Activity      # 保持哪些類不被混淆
-keep public class * extends android.app.Application   # 保持哪些類不被混淆
-keep public class * extends android.app.Service       # 保持哪些類不被混淆
-keep public class * extends android.content.BroadcastReceiver  # 保持哪些類不被混淆
-keep public class * extends android.content.ContentProvider    # 保持哪些類不被混淆
-keep public class * extends android.app.backup.BackupAgentHelper # 保持哪些類不被混淆
-keep public class * extends android.preference.Preference        # 保持哪些類不被混淆
-keep public class com.android.vending.licensing.ILicensingService    # 保持哪些類不被混淆
-keep public class com.google.vending.licensing.ILicensingService   # 保持哪些類不被混淆


-keepclassmembers class **.R$* {
    public static ;
    public static final int *;
}
-keepclasseswithmembernames class * {  # 保持 native 方法不被混淆
    native ;
}
-keepclasseswithmembers class * {   # 保持自定義控件類不被混淆
    public (android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {# 保持自定義控件類不被混淆
    public (android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity { # 保持自定義控件類不被混淆
    public void *(android.view.View);
}
-keepclassmembers enum * {     # 保持枚舉 enum 類不被混淆
    public static **[] values();
    public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable { # 保持 Parcelable 不被混淆
    public static final android.os.Parcelable$Creator *;
}

-keep public class * extends android.view.View {
    public (android.content.Context);
    public (android.content.Context, android.util.AttributeSet);
     public (android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
    }
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

#apk 包內所有 class 的內部結構
#-dump class_files.txt
#未混淆的類和成員
#-printseeds seeds.txt
#列出從 apk 中刪除的代碼
#-printusage unused.txt
#混淆前後的映射
#-printmapping mapping.txt

#fastjson 可以混淆也可以不混淆
#-keep class javax.ws.rs.** { *; }
#-dontwarn com.alibaba.fastjson.**
#-keep class com.alibaba.fastjson.** { *; }
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
    public ;
}
-keepattributes Signature

#gson
-dontwarn com.google.gson.**
-keep class com.google.gson.** { *;}
-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
    public ;
}

#v4
-dontwarn android.support.v4.**
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep public class * extends android.support.v4.**
-keep public class * extends android.app.Fragment

#greendao
#-dontwarn de.greenrobot.dao.**
#-keep class de.greenrobot.dao.** { *;}
-keepclassmembers class * extends de.greenrobot.dao.AbstractDao {
    public static java.lang.String TABLENAME;
}
-keep class **$Properties
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved