Common error reporting problems in Android development (continuous update records)

1. Gradle synchronously reports Caused by: java.lang.NoSuchFieldError: ASCII error

Scenario: There was another project in 2018, but I don’t remember the version of Android studio at that time. The current AS version in 2022 is version 4.2.2. After running the project in 2018, I couldn’t run it. The error report was an ASCII error. At that time, I was wondering if the project contained Chinese paths or illegal characters. It was useless to check and change.

Solution: Upgrade the version of gradle: the previous version of gradle is 3.2.0 and updated to a higher version. (You can find a project that can run and check the gradle version.)

Project-level gradle file:
classpath 'com.android.tools.build:gradle:xxx'
At the same time, gradle-wrapper.properties is updated to version 5.6.4:
distributionUrl=https://services.gradle.org/distributions/gradle -5.6.4-all.zip


2. AS compilation error: line 1:0 mismatch input '?' expecting {COMMENT, SEA_WS, '<',PI}

Scenario: Pull a project from github, copy an xml file from the project to my normal compilable project, copy it in and compile and run the error as follows:

 Caused by: org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:mergeDebugResources'.
……
Caused by: java.lang.NullPointerException
at android.databinding.tool.store.LayoutFileParser.parseOriginalXml(LayoutFileParser.java :128)
The relevant error message directly points to the null pointer caused by this xml file (because you can click on the error message to jump to this xml file, I forgot to take a screenshot). The first time I saw a null pointer because of an xml file (the file did not report an error message, and the file looked fine on the surface), I was confused.

I found the final reason on stackoverflow: the problem of android studio UTF-8 BOM format, as shown in the figure

I know it is a problem with the UTF-8 BOM format. To be honest, I don’t know what this BOM is. It may be an encoding format.
Solution: Right-click the project -> Remove Bom (there is an option at the bottom of the menu, just click), and then re-run the compilation.

 

Guess you like

Origin blog.csdn.net/sunbinkang/article/details/126329011