Android 10 闪退问题
coconutnut

(未解决)

bug描述

打开工程可以安装,但是闪退

Build中报错

1
2
注: 某些输入文件使用或覆盖了已过时的 API。
注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。

尝试解决

尝试1

https://blog.csdn.net/caidi1988314/article/details/52460922?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-3

build.gradle android {}里加

1
2
3
4
5
6
allprojects {
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" }
}
}

出现

在报错的函数上加

1
@SuppressWarnings("deprecation")

Build成功,但还是闪退

尝试2

看到activity_main.xml里有

按提示修改

还是闪退

https://blog.csdn.net/yogima/article/details/89416885?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1

把MainActivity所有函数都注释掉,可以打开

一点一点放开

发现问题在

1
2
3
4
File path = new File(dir);
String[] list = path.list();
len = list.length;
if (len == 0) { return 0; }

list空的时候,list.length会异常

加了个为空返回0

但是这个异常怎么不提示呢???

这里会为空应该读文件权限没有获取到

尝试3

像上次那样加

1
android:requestLegacyExternalStorage="true"

报错

1
AAPT: error: attribute android:requestLegacyExternalStorage not found.

https://blog.csdn.net/DeMonliuhui/article/details/99718553

现在这个工程的版本是

1
2
3
4
5
6
7
8
9
10
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.example.mydoppler"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

改成

1
2
3
4
5
6
7
8
9
10
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId"com.example.mydoppler"
minSdkVersion 26
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

requestLegacyExternalStorage属性可以加了

输出那个获取的文件路径,还是null

尝试4

在Run里面又发现一句红的

1
E/libc: Access denied finding property "ro.vendor.df.effect.conflict"