Android错误记录合集

环境:

Intellij IDEA 2020.3.1

Gradle 4.0.0

gradle 6.1.1

 

1.Execution failed for task ':app:javaPreCompileAnzhiDebug'

显示错误:

Error:Execution failed for task ':app:javaPreCompileAnzhiDebug'. > Annotation processors must be explicitly declared now. 
The following dependencies on the compile classpath are found to contain annotation processor.
Please add them to the annotationProcessor configuration.
- butterknife-7.0.1.jar (com.jakewharton:butterknife:7.0.1)
Alternatively, set android.defaultConfig.javaCompileOptions.annotationProcessorOptions.includeCompileClasspath = true to continue with previous behavior.
Note that this option is deprecated and will be removed in the future.
See https://developer.android.com/r/tools/annotation-processor-error-message.html for more details.

解决方法:

在app-build.gradle中defaultConfig{...}内部添加如下代码

javaCompileOptions {   // 显式声明支持注解 
    annotationProcessorOptions {
         includeCompileClasspath false 
    } 
}        

 

2.ERROR: Failed to parse XML

显示错误:

ERROR:Failed to parse XML in D:**\app\src\main\AndroidManifest.xml
ParseError at [row, col]:[26, 9]
Message:expected start or end tag

解决方法:

在app-build.gradle中defaultConfig{...}内部修改minSdkVersion与自己新建一个Project的minSdkVersion相同,我修改为16

  

3. Android dataBinding 错误: 程序包Model不存在

解决方法:

DataBinding生成的Binding类时,会引用到自定义的model或者view。
!!切记包名不可以大写,否则会报错

 

4.xml布局文件预览不显示

解决方法:

方法1:
    File-->Invalidate caches/Restart...
方法2:
    Select Design Surface(预览中左上角的蓝色菱形图标)-->Force Reflesh Layout
方法3:
    res资源引用,styles.xml文件中添加一个 "Base."<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">改为:
 <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

 

5.'android.useAndroidX' property is not enabled

显示错误:

This project uses AndroidX dependencies, but the 'android.useAndroidX' property is not enabled. 
Set this property to true in the gradle.properties file and retry.

解决方法:

在项目的gradle.properties文件中添加如下代码:
android.useAndroidX=true
android.enableJetifier=true

  

6.Compilation is not supported for following modules

显示问题:

Compilation is not supported for following modules: XXX, XXX, app. 
Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.

 解决方案:

打开 根目录.idea\modules.xml文件
删除提示的、不存在的module配置并保存
重新打开项目即可

出现原因:

可能是暴力删除(直接去根目录强制删除)项目中某个module,配置没删干净。

 

7.控制台信息出现乱码

显示问题:

  

解决方法:

双击Shift
输入Edit Custom VM Options,有两个选项,选第一个(后面没有Help的)
打开了一个文件,里面添加一行代码:-Dfile.encoding=UTF-8
保存重启生效

  

 

posted @ 2021-02-18 21:08  织秋  阅读(181)  评论(0编辑  收藏  举报