Android Studio 常见错误分析

本文汇总了Android Studio开发过程中常见的21个错误及其解决办法,包括SSL错误、Gradle同步失败、清单文件警告等问题,并提供了详细的步骤指导。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.Error:SSL peer shut down incorrectly :

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

这里写图片描述

下载完成之后,解压到gradle目录下
这里写图片描述

选择本地gradle
这里写图片描述

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!对话框,如图所示:

在这里插入图片描述

解决:
在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

在这里插入图片描述

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去除勾选
在这里插入图片描述

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
最终为<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

18.Error:Execution failed for task ‘:app:mergeDebugResources’

  • 解决方法:
    • 在Modle的build.gradle下添加两行代码
    • aaptOptions.cruncherEnabled = false
    • aaptOptions.useNewCruncher = false
    android {
    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    aaptOptions.cruncherEnabled = false
    aaptOptions.useNewCruncher = false
    

    19.Cannot debug application from module app on device

    可以运行但不能开启debug模式
    Error running app: Cannot debug application from module app on device xiaomi-mi_4lte-347a4d71. This application does not have the debuggable attribute enabled in its manifest. If you have manually set it in the manifest, then remove it and let the IDE automatically assign it. If you are using Gradle, make sure that your current variant is debuggable.

解决:解决方法:build.gradle文件中加上 debuggable true

buildTypes {
   release {
       //  TODO:打正式包时记得关掉
       debuggable true
       minifyEnabled false
       proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
       signingConfig signingConfigs.config
   }
}

20.CLEARTEXT communication to XX not permitted by network security policy

用用了非加密传输(http),1.>=9.0 版本报错 2.targetSdkVersion >=28
同时满足这两个条件会出现这个错

目前有3中解决方法:

  • 1)全部改为https (推荐,治标治本)

  • 2)配置清单文件,更改安全配置

    • 在res的xml目录(),然后创建一个名为:network_config.xml文件,内容如下:
    		<?xml version="1.0" encoding="utf-8"?>
    		<network-security-config>
    		<base-config cleartextTrafficPermitted="true" />
    		</network-security-config>
    
    • 在AndroidManifest.xml中配置cleartextTrafficPermitted
     <application
        ****
        android:networkSecurityConfig="@xml/network_config"
        ****
     >
    
  • 3)更改targetSdkVersion <=27

21.Error:A problem occurred configuring project ‘:XXX’

文件local.properties中尝试添加ndk ,ndk.dir=D\:\\develop\\xxxxxx

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值