我的 compileSdkVersion 设置的是30,在查看源码的时候,出现的都是.class 文件,类似于这种:
image.png
这对查看源码带来了极大的不方便
一般会在.class 文件上爆出两种错误:
- Sources for ‘Android API 30 Platform’ not found
- Decompiled.class file,bytecode version:52.0(Java 8)
解决第一种错误
image.png
- 首先要保证对应的 sources 已经下载了。
- 其次,找到 jdk.table.xml 文件
- 在文件中找到 sourcePath,在 url 中添入 Android 30 的 source 路径
<sourcePath>
<root type="composite">
<root url="file://$USER_HOME$/Library/Android/sdk/sources/android-30" type="simple" />
</root>
</sourcePath>
- 然后在 Android studio 中 点击 File -> invalidate caches 重启
jdk.table.xml 的文件如何查找:
在网上能搜索到的文件路径是:
/Users/xx/Library/Preferences/AndroidStudio3.5/options/jdk.table.xml
但是很遗憾,我并没有在我的 mac 路径找到
我寻找的路径是:
/Users/xxx/Library/Application Support/Google/AndroidStudio2021.2/options/jdk.table.xml
解决第二种错误
我遇到的是Decompiled.class file,bytecode version:52.0(Java 8)
解决方法同解决第一种方法的 4 个步骤是一样的,但是发现并不好使,有些怀疑是自己的 api 30 源码没有下全,所以更换 compileSdkVersion 到 31,重新编译,就可以看到对应的源码了。
所以试过前面的 4 种方法依旧没有用的时候可以尝试更改compileSdkVersion