(1).java.lang.IllegalStateException: Observer android.widget.AbsListView$AdapterDataSetObserver@b10fb42 was not registered.
这个报错在异常信息里是看不到关于程序里有报错的地方的,而这个报错是因为程序不停的setAdapter();
处理方法是只有当adapter为空时用再次使用这个方法。(呈现当手机在报错页面进入其他页面然后锁屏几分钟,然后打开手机,最后返回报错的页面操作就会闪退。)
(2)java.lang.RuntimeException: Unable to start activity ComponentInfo{包名.MainActivity}: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment 包名.LocalFragment: make sure class name exists, is public, and has an empty constructor that is public
这个报错是因为LocalFragment类有一个自定义带参数的构造方法。(呈现与上一个错误是一样的)。原因:是因为处于后台太长时间后台会释放不适用的内存。返回这个页面时系统创建对象是用默认的不带参数的构造方法,而不是自定义的构造方法。所以出错。
(3)java.lang.ClassCastException: android.support.v4.view.ViewPager$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams
这是一个在Activity中的两个添加Fragment,而用ViewPager来划动。报错原因是transaction.replace(ID,Fragment)中的ID是Viewpager的ID,而不是Viewpager中内容的ID,所以会报这个错误。
(4)Installation failed due to: 'null'
//虚拟机安装错误 解决
splits {
abi {
enable true
reset()
include 'x86', 'armeabi-v7a', 'x86_64'
universalApk true
}
}
原文链接:https://blog.csdn.net/qq_38436214/article/details/100727172
(5)IndexOutOfBoundsException:Inconsistency detected
在使用RecyclerView时引起一个BUG,查找网上的资料都说自定义一个Manager去拦截闪退。 (总结的来说就是因为数据发生变化,而适配器又根据数据的变化而刷新了) 我报错的使用场景是悬浮窗上使用这个RecyclerView的,为了方便将悬浮窗设置了单例,每次进入都会新建适配器对象。而数据是异步去clear和刷新数据的(扫描完成后去更新数据,且此时才刷新数据)。 这样第一次进来没什么问题,第二次之后数据集合有可以已经不为0了,这样新建对象存放数据,同时异步也扫描完成就会报错。(个人认为是这样),所以进来这个对象不管有没有数据我直接clear数据等异步数据去刷新页面即可。(场景不一样处理有可能不一样了) //改变图片颜色 Drawable drawable = mContext.getResources().getDrawable(R.mipmap.select_down_image); Drawable wrappedDrawable = DrawableCompat.wrap(drawable); DrawableCompat.setTintList(wrappedDrawable, ColorStateList.valueOf(color) ); holder.binding.tvSelectName.setCompoundDrawablesWithIntrinsicBounds(null,null,wrappedDrawable,null);
(6) Caused by: java.nio.charset.MalformedInputException: Input length = 1
运行项目或者Clear时报错:简单粗暴的删除build文件夹即可。
(7)retrofit2+rxjava2在混淆后报错。
E FATAL EXCEPTION: main
Process: com.**, PID: 27382
java.lang.RuntimeException: Unable to create service com.**.service.UtilService: java.lang.IllegalArgumentException: Unable to create call adapter for class io.reactivex.Observable
for method ApiService.getHelp
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4257)
at android.app.ActivityThread.access$1700(ActivityThread.java:244)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1982)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7720)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:612)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:997)
Caused by: java.lang.IllegalArgumentException: Unable to create call adapter for class io.reactivex.Observable
for method ApiService.getHelp
at retrofit2.Utils.methodError(Utils.java:52)
at retrofit2.HttpServiceMethod.createCallAdapter(HttpServiceMethod.java:60)
at retrofit2.HttpServiceMethod.parseAnnotations(HttpServiceMethod.java:34)
at retrofit2.ServiceMethod.parseAnnotations(ServiceMethod.java:36)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:168)
at retrofit2.Retrofit$1.invoke(Retrofit.java:147)
at java.lang.reflect.Proxy.invoke(Proxy.java:1006)
at $Proxy2.getHelp(Unknown Source)
at com.**.http.network.HttpRequests.getHelp(HttpRequests.java:40)
at com.**.utils.NetWorkUtils.getHelpData(NetWorkUtils.java:22)
at com.**.service.UtilService.initData(UtilService.java:62)
at com.**.service.UtilService.onCreate(UtilService.java:58)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:4245)
... 8 more
Caused by: java.lang.IllegalStateException: Observable return type must be parameterized as Observable<Foo> or Observable<? extends Foo>
at retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory.get(RxJava2CallAdapterFactory.java:118)
at retrofit2.Retrofit.nextCallAdapter(Retrofit.java:219)
at retrofit2.Retrofit.callAdapter(Retrofit.java:203)
at retrofit2.HttpServiceMethod.createCallAdapter(HttpServiceMethod.java:58)
... 19 more
看着这些报错在网卡查资料,CSDN的资料是最无语了,十个有九个相同的,有些用别人也不说从那里抄回来了。
刚开始的混淆(之前在AndroidStudio4.1左右的版本建立的项目运行都没有毛病的,但在新的AS建的项目混淆后运行就不行了,混淆前一点毛病没有)
implementation 'io.reactivex.rxjava2:rxjava:2.2.8' implementation 'io.reactivex.rxjava2:rxandroid:2.1.1' implementation 'com.squareup.retrofit2:retrofit:2.5.0' implementation 'com.squareup.retrofit2:converter-scalars:2.1.0' implementation 'com.squareup.retrofit2:adapter-rxjava2:2.4.0' implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1' implementation 'org.ligboy.retrofit2:converter-fastjson-android:2.1.0'
# ==================retrofit2+rxjava2 start===================
#-------------- retrofit2 -------------
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepattributes AnnotationDefault
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
-keep,allowobfuscation,allowshrinking interface retrofit2.Call
-keep,allowobfuscation,allowshrinking class retrofit2.Response
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-keep class retrofit2.** { *; }
-dontwarn retrofit2.**
-keepattributes Exceptions
-dontwarn okio.**
-dontwarn javax.annotation.**
#-------------------------
#-------------- okhttp3 -------------
-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.{*;}
-dontwarn com.squareup.okhttp3.**
-keep class com.squareup.okhttp3.** { *;}
-dontwarn okio.**
#----------- rxjava rxandroid----------------
-dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
-dontnote rx.internal.util.PlatformDependent
# ==================retrofit2+rxjava2 end===================
后来在
Retrofit 2.0 基本使用_addconverterfactory fastjson_QDJdeveloper的博客-CSDN博客看到有Retrofit2.0在github的开源就直接去找了相关的混淆
Retrofit GitHub 地址:GitHub - square/retrofit: A type-safe HTTP client for Android and the JVM
官网地址:Retrofit
之后只是将Retrofit2.0的混淆规则修改就可以了。。
-keepattributes Signature, InnerClasses, EnclosingMethod
-keepattributes RuntimeVisibleAnnotations, RuntimeVisibleParameterAnnotations
-keepattributes AnnotationDefault
-keepclassmembers,allowshrinking,allowobfuscation interface * {
@retrofit2.http.* <methods>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn javax.annotation.**
-dontwarn kotlin.Unit
-dontwarn retrofit2.KotlinExtensions
-dontwarn retrofit2.KotlinExtensions$*
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface <1>
-if interface * { @retrofit2.http.* <methods>; }
-keep,allowobfuscation interface * extends <1>
-keep,allowobfuscation,allowshrinking class kotlin.coroutines.Continuation
-if interface * { @retrofit2.http.* public *** *(...); }
-keep,allowoptimization,allowshrinking,allowobfuscation class <3>
(看到简书说说换成2.9版本的,结果一样的,只要没混淆前没问题,混淆后有问题就是混淆不行了)