1、use jsonreader.setlenient(true) to accept malformed json at line 1 column 1 path
问题描述:
同样的代码,一个请求本地,一个请求远程,本地的能Gson解析成功,远程的不能。
问题分析:
因为本地服务器没有开启数据gzip压缩,所有我们代码中开了gzip压缩也能解析成功,而远程开启了,所以解析报错。详细信息看连接:https://www.jianshu.com/p/a9d861732445
解决方案:
把Request中的.addHeader(“Accept”, “application/json”)移除。
如果我们在代码里没有手动设置 Accept-Encoding = gzip ,
那么 OkHttp 会自动处理 gzip 的解压缩;反之,你需要手动对返回的数据流进行 gzip 解压缩。
2、Cannot fit requested classes in a single dex file methods 66251 大于 65536
问题分析:
项目过大,超过过了65536个方法,一个dex装不下了,需要使用multidex 。因为Android系统定义总方法数是一个short int,short int 最大值为65536
解决方案:
gradle文件的defaultConfig默认配置里面增加:
multiDexEnabled true
新增依赖 implementation ‘com.android.support:multidex:1.0.3’
自定义的Application的onCreate()中添加: MultiDex.install(this);
3、Android嵌套webview时,软键盘挡住输入框问题
解决方案:
在manifest文件中添加 android:windowSoftInputMode=“stateAlwaysHidden|adjustResize”
新增AndroidBug5497Workaround类
import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;
public class AndroidBug5497Workaround {
public static void assistActivity(Activity activity) {
new AndroidBug5497Workaround(activity);
}
private View mChildOfContent;
private int usableHeightPrevious;
private FrameLayout.LayoutParams frameLayoutParams;
private int contentHeight;
private boolean isfirst = true;
private Activity activity;
private int statusBarHeight;
private AndroidBug5497Workaround(Activity activity) {
//获取状态栏的高度
int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
this.activity = activity;
FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
mChildOfContent = content.getChildAt(0);
//界面出现变动都会调用这个监听事件
mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
if (isfirst) {
contentHeight = mChildOfContent.getHeight();//兼容华为等机型
isfirst = false;
}
possiblyResizeChildOfContent();
}
});
frameLayoutParams = (FrameLayout.LayoutParams)
mChildOfContent.getLayoutParams();
}
//重新调整跟布局的高度
private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
//当前可见高度和上一次可见高度不一致 布局变动
if (usableHeightNow != usableHeightPrevious) {
//int usableHeightSansKeyboard2 = mChildOfContent.getHeight();//兼容华为等机型
int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
int heightDifference = usableHeightSansKeyboard - usableHeightNow;
if (heightDifference > (usableHeightSansKeyboard / 4)) {
// keyboard probably just became visible
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference + statusBarHeight;
} else {
frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
}
} else {
frameLayoutParams.height = contentHeight;
}
mChildOfContent.requestLayout();
usableHeightPrevious = usableHeightNow;
}
}
/**
* 计算mChildOfContent可见高度
*/
private int computeUsableHeight() {
Rect r = new Rect();
mChildOfContent.getWindowVisibleDisplayFrame(r);
return (r.bottom - r.top);
}
}
在使用了webview的类中初始化时调用:
AndroidBug5497Workaround.assistActivity(this);
4、android 开发者选项提示:此用户无法使用开发者选项(调试RK系列的硬件设备)
问题描述:
状态栏不能下拉,无法使用最近任务切换、返回桌面、锁屏界面打不开
开发者模式面板提示:此用户无法使用开发者选项
解决方案:
打开设备中USB-》 链接电脑
执行ADB命令
adb shell settings put secure user_setup_complete 1
adb shell settings put global device_provisioned 1
5、Caused by:kotlin.UninitializedPropretyAccessException:lateinit peoperty adapter has not been initialized
问题分析:
在使用了var lateinit adapter时,adapter没有初始化就去进行操作了。
解决方案:
在使用之前先判断adapter有没有初始化
//判断adapter有没有初始化
if(!::adapter.isInitialized){
//adapter没有初始化,则进行初始化
}
6、open failed: EACCES (Permission denied)
问题描述:明明已经申请过文件读写权限,却还是报错,无法读取文件。
问题分析:Android Q文件存储机制修改成了沙盒模式。APP只能访问自己目录下的文件和公共媒体文件。对于AndroidQ以下,还是使用老的文件存储方式。Android Q仍然使用READ_EXTERNAL_STORAGE和WRITE_EXTERNAL_STORAGE作为存储相关运行时权限,但现在即使获取了这些权限,访问外部存储也受到了限制。
解决方案:目前版本的解决方案,在manifest的applicaiton标签添加
android:requestLegacyExternalStorage="true" //使用旧的存储策略,但不是长久之计。
7、More than one file was found with OS independent path ‘lib/armeabi-v7a/**.so’
问题分析:在组件化开发中,存在多个module。而基础组件中正好使用到了这个so文件,然后其他组件有依赖了基础组件,导致编译时报错出现重复的so。
解决方案:移除基础组件build.gradle代码
sourceSets.main {
jniLibs.srcDir 'libs'
}
8、miui 11/12报错 E/ActivityInjector: get life cycle exception
java.lang.ClassCastException: android.os.BinderProxy cannot be cast to android.app.servertransaction.ClientTransaction
解决方案:在项目中创建一个valuesv29.xml,然后在style中新增
<item name="android:forceDarkAllowed">false</item>
完整代码:
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:forceDarkAllowed">false</item>
</style>
详细讲解请看:链接,(需要梯子)
9、在build.gradle下定义了APK打包后的名字,但是打包后APK名字出现乱码。
解决方案:在项目下的gradle.properties内新增一行代码,
-Dfile.encoding=UTF-8
持续更新中。。。