重装或者升级Android Studio后,打开旧的Android项目,同步编译时遇到的一些常见问题及解决办法
1、在sdk安装路径下找不到sdk对应的版本android-28,Gradle sync failed: Failed to find target with hash string 'android-28' in: D:\android\androidstudio\sdk
解决:
找到sdk安装路径和编译工具路径
修改app的build.gradle如下:
2、Android studio ERROR: Failed to resolve: com.android.support.test.espresso:espresso-core:2.2.2
报错位置在module中的build.gradle中
解决:
在项目build.gradle中添加如下代码
3、ERROR: Failed to resolve: com.android.support:appcompat-v7:25.3.1
解决方法,同上一条。
4、Error:Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve project
解决方法,同上一条。
5、The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.
原因
是这里出问题了 instrumentTest.setRoot(‘tests’) ,你可能在升级 Android Studio 时更新了项目的 gradle 配置,这里的配置中 instrumentTest 已被弃用,不适用于现在的 gradle 版本。
解决办法
用 androidTest 替换 instrumentTest,编译运行即可。
6、Cannot resolve external dependency com.android.tools.build:aapt2:3.5.3-54358
在project的build.gradle文件里中加入google(),即如下图:
// Top-level build file where you can add configuration options common to all sub-projects/modules.buildscript { repositories { //mavenCentral() jcenter() google() maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} } dependencies { classpath 'com.android.tools.build:gradle:3.5.3' }}allprojects { repositories { jcenter() google() maven{ url 'http://maven.aliyun.com/nexus/content/groups/public/'} }}
7、Android 依赖报错Version 28 (intended for Android Pie and below) is the last version of the legacy
原因:
由于Android Studio 版本较高,添加库依赖已经不支持compile语句,较高的版本应使用implementation或者api语句。若使用api或implementation语句仍然报错,可能是库的版本较低,出现了不兼容的现象。
依赖库28号版本是Android Pie 以及以下的版本最新的一个版本,对于Android Q以及以上版本应使用AndroidX库。由于support 库太乱了,谷歌在新版本中取消了support库,使用了新的andriodX库。
解决办法:
在错误地方点击鼠标右键--->Refactor--->Migrate to AndroidX--->点击左下角 Do Refactor
(refactor:n.重构)(Migrate:v.迁移)
解决前:
解决后:
8、Android xxx is not translated in zh
原因:在默认的strings.xml中有值,但是在values-zh文件夹下的srings.xml中没有值导致
Lint的终极解决办法:
在主项目的builde.gralde里添加如下代码
android {lintOptions {checkReleaseBuilds false// Or, if you prefer, you can continue to checkforerrorsinrelease builds,// but continue the build even whenerrorsarefound:abortOnError false}}
完!!!
更多相关文章
- Android Studio编译release版本
- 【Android 应用开发】 Ubuntu 安装 Android Studio (旧版本|仅作
- 【Android开源项目分析】android轻量级开源缓存框架——ASimpleC
- android 应用自身检测版本并下载
- Android:系统信息(内存、cpu、sd卡、电量、版本)的获取
- 编译FFMpeg的Android版本,并整合到android studio
- ANDROID版本号和版本名称的重要性介绍
- 二.Android项目结构
- Android版本的RSA非对称加密实现