Error:Execution failed for task ':app:preDebugAndroidTestBuild'.错误解决

在新建布局文件的时候,页面显示:

design editor is unavailable until a successful build(设计编辑器不可用,直到成功创建。)

细看下面还有一行错误:

Error:Execution failed for task ':app:preDebugAndroidTestBuild'.(':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.

( ':app'.项目中的 'com.android.support:support-annotations' 有冲突,应用是26.1.0,测试应用是27.1.1。)

解决方法:

在build.gradle的文件中加入两行代码:

implementation'com.android.support:appcompat-v7:27.1.1'

androidTestImplementation'com.android.support:support-annotations:27.1.1'

同时更正build.gradle中的compileSdkVersion和targetSdkVersion版本为27:

android {

compileSdkVersion27

    defaultConfig {

applicationId"com.example.culif.activitytest"

        minSdkVersion27

        targetSdkVersion27

        versionCode1

        versionName"1.0"

        testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"

    }

如果出现找不到27.1.1的错误点一下install就可以

作者:西柚读书
链接:https://www.jianshu.com/p/efbc0a23d942
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自www.cnblogs.com/Frank-dev-blog/p/10354847.html