在命令行中输入
gradlew compileDebug --stacktrace -info
或者
gradlew compileDebug --stacktrace -debug
或者(推荐,最详细)
gradlew compileDebugSources --stacktrace -info
参考博客:https://blog.csdn.net/wjj1996825/article/details/80899135
https://blog.csdn.net/wjj1996825/article/details/79838430
https://blog.csdn.net/yue530tomtom/article/details/79361820
https://blog.csdn.net/u014453811/article/details/54582426/
情况1:
Output: error: resource style/Theme.AppCompat.Light.DarkActionBar (aka com.hp.sortfilebysize:style/Theme.AppCompat.Light.DarkActionBar) not found.
E:\ASWorkSpace\SortFileBySize\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:9: error: style attribute 'attr/colorPrimary (aka com.hp.sortfilebysize:attr/colorPrimary)' not found.
E:\ASWorkSpace\SortFileBySize\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:10: error: style attribute 'attr/colorPrimaryDark (aka com.hp.sortfilebysize:attr/colorPrimaryDark)' not found.
E:\ASWorkSpace\SortFileBySize\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:11: error: style attribute 'attr/colorAccent (aka com.hp.sortfilebysize:attr/colorAccent)' not found.
error: failed linking references.
情况2:
Output: E:\ASWorkSpace\SortFileBySize\app\src\main\res\layout\activity_main.xml:13: error: attribute layout_constraintBottom_toBottomOf (aka com.hp.sortfilebysize:layout_constraintBottom_toBottomOf) not found.
E:\ASWorkSpace\SortFileBySize\app\src\main\res\layout\activity_main.xml:13: error: attribute layout_constraintLeft_toLeftOf (aka com.hp.sortfilebysize:layout_constraintLeft_toLeftOf) not found.
E:\ASWorkSpace\SortFileBySize\app\src\main\res\layout\activity_main.xml:13: error: attribute layout_constraintRight_toRightOf (aka com.hp.sortfilebysize:layout_constraintRight_toRightOf) not found.
E:\ASWorkSpace\SortFileBySize\app\src\main\res\layout\activity_main.xml:13: error: attribute layout_constraintTop_toTopOf (aka com.hp.sortfilebysize:layout_constraintTop_toTopOf) not found.
error: failed linking file resources.
情况3:
Output: E:\ASWorkSpace\Temp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
E:\ASWorkSpace\Temp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values-v28\values-v28.xml:11: error: resource android:attr/dialogCornerRadius not found.
E:\ASWorkSpace\Temp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:946: error: resource android:attr/fontVariationSettings not found.
E:\ASWorkSpace\Temp\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:946: error: resource android:attr/ttcIndex not found.
error: failed linking references.
Android studio升级到3.0以上,工程自动会引入Androidx的相关包,当因为某些原因,我们把默认依赖删除以后,就会出现Android resource linking failed。
错误日志1是缺少androidx.appcompat:appcompat:1.0.0-alpha1依赖,错误日志2是缺少androidx.constraintlayout:constraintlayout:1.1.2依赖,。
错误日志3是因为compileSdkVersion版本不对,应该改为compileSdkVersion 28
解决方案
错误1、2添加相关依赖即可,如下:
implementation 'androidx.appcompat:appcompat:1.0.0-alpha1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
参考博客:https://blog.csdn.net/qq_26585943/article/details/81119065
分两种,一种是去除所有依赖中指定的某个模块:
configurations {
all*.exclude group 'com.android.support',module: 'support-core-ui'
}
另一种只去除某个依赖下的指定模块:
implementation 'com.jcodecraeer:xrecyclerview:1.5.9' {
exclude module: 'support-core-ui'
}
但是我在去除某个依赖下的指定模块,编译后会报错
参考博客:https://blog.csdn.net/Calvin_zhou/article/details/80880501
——————————————————————分割线———————————————————————
1月10日更新。
最后没有用以上两个方法,用的另一种,亲测特别好用。
在项目根目录的build.gradle文件中添加
ext {
supportlib_version = 'xx.x.x' //xx.x.x为目标版本号
}
subprojects {
project.configurations.all {
resolutionStrategy.eachDependency { details ->
if (details.requested.group == 'com.android.support'
&& !details.requested.name.contains('multidex')) {
details.useVersion "$supportlib_version"
}
}
}
}
推荐博客:https://blog.csdn.net/niuba123456/article/details/81836579
会保持更新。
------------------------------------------------------2019.04.08更新------------------------------------------------------------
mac上,在AndroidStudio中直接在termital使用命令./gradlew可能会提示权限限制
-bash: ./gradlew: Permission denied
此时输入命令行
即可。
------------------------------------------------------2019.04.10更新------------------------------------------------------------
新建项目支持AndroidX,结果问题来了,报错
AGPBI: {"kind":"error","text":"Program type already present: android.support.v4.os.ResultReceiver","sources":[{}],"tool":"D8"}
死活提示我android.support.v4.os.ResultReceiver重复引用,怎么exclude都不行。
在gradle.properties加上
android.useAndroidX=true
android.enableJetifier=true