AS Notes|记录日常开发遇到的 AS 问题(不断更新。。。

944 阅读4分钟

我们走过了青春,却离别在了秋季。。。

先放一张目前 Android Studio 版本图:

image.png

PS:说实话不太喜欢这个掘金图片打标记的情况,不方便后期同步,懒得搞图床啥的,还是建议和 CSDN 学习下,能否给个开关,由作者去选择是否给图片加对应的标记。

占楼,看了下掘金之前草稿箱出现图片丢失情况,先发文,后续慢慢更新...

这里仅记录个人遇到的一些 AS 问题以及验证成功的解决方式,当然每个人环境或者其他情况不太一样,这个看个人情况而定吧。

望谅解。。。

1、Git 显示乱码

image.png

之前出现过这个问题,主要是因为字体原因,这次尝试一波:

image.png

选择字体之后,点击 Apply 并 Ok,再回头看:

image.png

2、Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.

错误日志如下:

Android Gradle plugin requires Java 11 to run. You are currently using Java 1.8.
You can try some of the following options:
  - changing the IDE settings.
  - changing the JAVA_HOME environment variable.
  - changing `org.gradle.java.home` in `gradle.properties`.
Gradle settings

根目录下输入如下命令查看版本信息:

  • ./gradlew --version

输出如下:

Welcome to Gradle 7.0.2!

Here are the highlights of this release:
 - File system watching enabled by default
 - Support for running with and building Java 16 projects
 - Native support for Apple Silicon processors
 - Dependency catalog feature preview

For more details see https://docs.gradle.org/7.0.2/release-notes.html

------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------

Build time:   2021-05-14 12:02:31 UTC
Revision:     1ef1b260d39daacbf9357f9d8594a8a743e2152e

Kotlin:       1.4.31
Groovy:       3.0.7
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_211 (Oracle Corporation 25.211-b12)
OS:           Mac OS X 10.16 x86_64

按照如下路径修改 JDK 版本为 11:

  • Preferences > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK

image.png

随后将 build 中的 JDK 版本做替换:

android {
    // ...
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_11
        targetCompatibility JavaVersion.VERSION_11
    }
    kotlinOptions {
        jvmTarget = '11'
    }
}

3、Error: Activity class {cn.xxx.xxx/cn.xxx.xxx.SplashActivity} does not exist.

先来看下异常输出:

Error while executing: am start -n "cn.xxx.xxx/cn.xxx.xxx.SplashActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER

Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=cn.xxx.xxx/.SplashActivity }

Error type 3

Error: Activity class {cn.xxx.xxx/cn.xxx.xxx..SplashActivity} does not exist.

这里出现这个问题主要是因为切换不同的版本(包名不一样),导致 install 手机上不能正确打开启动页面。

Fix 方案:

  • 点击下图的小象,重新进行一次同步即可

Git.png

4、Loading Devices...

先附上对应图:

Loading Devices...png

Android Studio 加载不出对应的设备。

Fix 方案:

  • 检查当前电脑端 adb 是否启动多个,强制退出后再次观察。或者通过 adb kill 方式干掉,然后再试试。

image.png

这里需要观察手机端是否开启「USB 调试」,我这里的 OPPO 以及 VIVO 总是会出现断线情况,需要重新打开。

这里根据个人情况而定。

5、Received status code 405 from server: Method Not Allowed

Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.6.3/gradle-3.6.3.pom'. Received status code 405 from server: Method Not Allowed
Disable Gradle 'offline mode' and sync project

怀疑是本地的某些配置,导致访问不正常。

本地网络连接正常,访问也均正常。

本人解决方式:

  • 清除本地所有 AS 缓存配置,都在隐藏文件中,记得挨个删除。不行就直接卸载 AS,然后一个个全部删除。

特意搜索了下 405 原因,一起来看下:

405 错误一般指请求 method not allowed 错误,本文列出了出现该错误的可能原因。

出现 405 错误的可能原因有:

  • POST 类请求出现 302 跳转,302 跳转的时候会更改请求方法此时服务端可能不能识别,则报 405 错误。
  • 请求服务端直接校验 Method,对应 Response Header 中会有 Allow =GET 的信息字样。
  • 负载均衡或者 Web Server 上做转发的时候,修改了请求 Method 导致后端无法识别。

6、Invocation failed Unexpected end of file from server

23:55:16.609: git -c credential.helper= -c core.quotepath=false -c log.showSignature=false fetch origin --recurse-submodules=no --progress --prune
Invocation failed Unexpected end of file from server
java.lang.RuntimeException: Invocation failed Unexpected end of file from server
	at org.jetbrains.git4idea.GitAppUtil.sendXmlRequest(GitAppUtil.java:30)
	at org.jetbrains.git4idea.http.GitAskPassApp.main(GitAskPassApp.java:58)
Caused by: java.net.SocketException: Unexpected end of file from server
	at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:866)
	at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
	at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:863)
	at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:689)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1615)
	at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1520)
	at org.apache.xmlrpc.DefaultXmlRpcTransport.sendXmlRpc(DefaultXmlRpcTransport.java:87)
	at org.apache.xmlrpc.XmlRpcClientWorker.execute(XmlRpcClientWorker.java:72)
	at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClient.java:194)
	at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClient.java:185)
	at org.apache.xmlrpc.XmlRpcClient.execute(XmlRpcClient.java:178)
	at org.jetbrains.git4idea.GitAppUtil.sendXmlRequest(GitAppUtil.java:27)
	... 1 more
error: unable to read askpass response from '/Users/heliquan/Library/Caches/Google/AndroidStudio2021.1/tmp/intellij-git-askpass-local.sh'
fatal: could not read Username for 'http://xxx.xxx.cn': Device not configured

按如下勾选 Use credential helper 即可。

Preferences 
-> Version Control 
-> Git 
-> 勾选 Use credential helper

操作示意图:

image.png

7、Android Studio 右侧 Gradle 不显示自定义的 task

将如下关闭,并且重启 Android Studio,重新 Build 即可。

image.png

8、Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6

如下图所示:

image.png

Fix:

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

kotlinOptions {
    kotlinOptions { jvmTarget = "1.8" }
}

9、 Android Studio Dolphin Xml 布局无法预览解决方案

看了网上的一些解决方案,感觉比较麻烦,某天尝试了一波,发现贼有效果,什么都不用改,那就是使用 Android Studio 预览版!妥妥无问题!

image.png

10、Conflict with another tag that has the same ID

大概率是因为文件缓存造成,解决方式如下,依次尝试:

  • Clear + Rebuild
  • Invalidate Caches
  • 万能的重启电脑

THK