Android Studio 常见错误分析

文章目录

    • 1.Error:SSL peer shut down incorrectly :
    • 2.Unable to start the daemon process 重装Studio 出现该错误
    • 3.studio 低版本运行高版本项目报错:Error:This Gradle plugin requires a newer IDE able to request IDE model level 3. For Android Studio this means version 3.0+
    • 4.安装Apk的时候出现`WARNING: Uninstalling will remove the application data!`对话框,如图所示:
    • 5.decompiled class file bytecode version 51.0 java 7
    • 6.文件名太长,无法删除文件
    • 7.Gradle project sync failed.Base functionality will not work property
    • 8.长时间编译,且下载失败 Gradle Download:https://jcenter.bintray.com
    • 9.studio无法内部更新
    • 10.Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout
    • 12. No service of type Factory available in ProjectScopeServices.
    • 13. 清单文件警告:App is not indexable by Google Search
    • 14.cannot resolve symbol AppCompatActivity
    • 15.Could not find com.android.support:support-annotations:27.1.1
    • 16.Program type already present: android.support.v4.app.FragmentTransitionCompa
    • 17.xml不显示视图
    • 18.Error:Execution failed for task ':app:mergeDebugResources'
    • 19.Cannot debug application from module app on device
    • 20.CLEARTEXT communication to XX not permitted by network security policy
    • 21.Error:A problem occurred configuring project ':XXX'

1.Error:SSL peer shut down incorrectly :

一般是在升级studio之后报此错误 ,由于网络被墙,无法下载到版本所对应的gradle
需要手动下载
点击此处,查看对应的版本号

Android Studio 常见错误分析_第1张图片

下载完成之后,解压到gradle目录下
Android Studio 常见错误分析_第2张图片

选择本地gradle
Android Studio 常见错误分析_第3张图片

2.Unable to start the daemon process 重装Studio 出现该错误

解决:

1 找到 C:\Users\Administrator.gradle

2 新建文件gradle.properties

文本内容:org.gradle.jvmargs=-Xmx512m

3 重启Studio

3.studio 低版本运行高版本项目报错:Error:This Gradle plugin requires a newer IDE able to request IDE model level 3. For Android Studio this means version 3.0+

解决:
在gradle.properties文件中加入`android.injected.build.model.only.versioned = 3`

4.安装Apk的时候出现WARNING: Uninstalling will remove the application data!对话框,如图所示:

Android Studio 常见错误分析_第4张图片

解决:
在gradle.properties文件中加入android.injected.testOnly=false

5.decompiled class file bytecode version 51.0 java 7

解决:重新设置SDK路径,编译一下

6.文件名太长,无法删除文件

解决:假设B文件夹下有无法删除的文件
1.在要删除的文件夹同级新建一个文件夹,命名A(随便起)
2.该目录下进入cmd命令
3.执行命令 robocopy A B /purge

7.Gradle project sync failed.Base functionality will not work property

Android Studio 常见错误分析_第5张图片

8.长时间编译,且下载失败 Gradle Download:https://jcenter.bintray.com

添加maven仓库

buildscript {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
   
allprojects {
    repositories {
        maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'}
    }
}

再不济,换成手机热点,多编译几次试试

9.studio无法内部更新

studio目录/bin/studio64.exe.vmoptions加入以下代码

-Djava.net.preferIPv4Stack=true
-Didea.updates.url=http://dl.google.com/android/studio/patches/updates.xml
-Didea.patches.url=http://dl.google.com/android/studio/patches/

仍如法解决:尝试以下方法Use secure connection去除勾选
Android Studio 常见错误分析_第6张图片

10.Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout

版本不匹配

 dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
  
}
//   gradle/wrapper/gradle-wrapper.properties  检查版本号是否匹配
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

12. No service of type Factory available in ProjectScopeServices.

项目build.gradle中修改maven版本,换成1.4.1,
注意下面区别:

	//换成1.4.1版本也不行
//  classpath 'com.github.dcendents:android-maven-plugin:1.2'
	//正解
    classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'

13. 清单文件警告:App is not indexable by Google Search

android {
    compileSdkVersion 28
    .......
	lintOptions {
    disable 'GoogleAppIndexingWarning'
	 }
}

14.cannot resolve symbol AppCompatActivity

关闭studio,在该项目中删除.idea文件夹,重新打开studio

15.Could not find com.android.support:support-annotations:27.1.1

allprojects {
    repositories {
        jcenter()
        //添加以下代码
        maven {
            url "https://maven.google.com"
        }

    }

16.Program type already present: android.support.v4.app.FragmentTransitionCompa

参考:https://stackoverflow.com/questions/52845161/error-program-type-already-present-android-support-v4-app-fragmenttransitionco

//加入依赖
implementation 'com.android.support:support-v4:28.0.0'

17.xml不显示视图

显示报错信息:Failed to load AppCompat ActionBar with unknown error.
解决:从清单文件中 找到@style/AppTheme点进来,在Theme.AppCompat.Light.DarkActionBar前面加上Base
最终为