android studio 错误汇总以及解决办法
问题1.
Error:Execution failed for task ':app:preDebugAndroidTestBuild'. > Conflict with dependency 'com.android.support:support-annotations' in project ':app'. Resolved versions for app (26.1.0) and test app (27.1.1) differ. See https://d.android.com/r/tools/test-apk-dependency-conflicts.html for details.
意思是“com.android.support:support-annotations”依赖冲突了,APP的 是26.1.0,而 测试APP是 27.1.1
解决措施:
1).最简单的方法,直接Rebuild Project ,此次编译可以通过,但后面还是出现,比如:Clean Project时
2).直接在build.gradle 修改SdkVersion
compileSdkVersion 26
targetSdkVersion 26
改为
compileSdkVersion 27
targetSdkVersion 27
3). 修改 dependencies
第一印象直接添加一句
com.android.support:support-annotations:26.1.0 ,就行了吧,等你同步后,发现然并卵
我这么试了发现根本就不行。查了好久才发现并不只是这一句有问题,在google之后http://stackoverflow.com/questions/28999124/resolved-versions-for-app-22-0-0-and-test-app-21-0-3-differ给出了一些解释。
简单粗暴的方法,添加force强制指定annotations,你会发现成功了
configurations.all {
resolutionStrategy.force 'com.android.support:support-annotations:26.1.0'
}
问题2
android.content.res.Resources$NotFoundException: String resource ID #0x0
在给TextView的setText(Int int)方法中的int指的是R.string.xxx,不能赋值其它int值
问题3、 apk安装出现闪退
java.lang.RuntimeException: Unable to instantiate application
在build.gradle文件中将gradle版本安装提示修改后重新编译得到解决
问题4
Error:Tag attribute name has invalid character ’ ‘.
Error:Tag attribute name has invalid character ’ ‘.
Error:org.gradle.process.internal.ExecException: Process ‘command
‘E:Androidsdkuild-tools26.0.2aapt.exe” finished with non-zero
exit value 1 Error:Execution failed for task
‘:backend01:processDebugResources’.
Failed to execute aapt
这个错误是因为在AndroidManifest.xml中category的值有一个空格,将空格去除就好了
问题5
Error:Execution failed for task :app:processDebugAndroidTestResources.
No slave process to process jobs, aborting
clean和rebuild都没有成功后,直接点击 File>Invalidate Caches/Restart后编译通过
问题6
新建的工程 就出现这个错误
- 出现的异常
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.1.
Open File
Show Details
- 解决方案
看错误的信息
Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support.constraint:constraint-layout:1.1.1.
我的理解 不能加载1.1.1 版本的 那么 就改成
dependencies {
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:27.1.1'
// implementation 'com.android.support.constraint:constraint-layout:1.1.1'
//替换陈这个版本的
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:support-v4:27.1.1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
build
ok
问题7
1. Error:Execution failed for task ':app:transformNative_libsWithStripDebugSymbolForDDebug‘
java.lang.NullPointerException (no error message)
2. Error:Execution failed for task ':module:transformNative_libsWithStripDebugSymbolForDebug'.
java.lang.NullPointerException (no error message)
- 原因
Debug模式找不到NDK。 -
解决办法
注释掉第11行的ndk
问题8
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/graphics/drawable/DrawableWrapper;
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.graphics.drawable.DrawableWrapper" on path: DexPathList[[zip file "/data/app/com.cpsc.cpsc_pgsip-2/base.apk"],nativeLibraryDirectories=[/data/app/com.cpsc.cpsc_pgsip-2/lib/arm, /data/app/com.cpsc.cpsc_pgsip-2/base.apk!/lib/armeabi-v7a, /vendor/lib, /system/lib]]
- 根据问题得知是 android.support.v4.graphics.drawable.DrawableWrapper 找不到
- 解决办法 ,分2步
1.保持版本支持
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-v4:27.1.1'
compile 'com.android.support:design:27.1.1'
- 找到出问题的布局重新写一次,可能是这里的问题,我再做了1之后,发现没什么卵用(但是保持一致的还是好的)最后还是重新写一次布局ok了。
- 如果在v28.0.0上,可以尝试把android.support.v4.graphics.drawable.DrawableWrapper 改成android.support.v4.graphics.drawable.WrappedDrawable可以解决这个问题