Android Studio构建错误 - "无法解析:监视器"

eth*_*han 3 android gradle android-studio

我有一个以前运行的项目,其中版本升级到最新版本.现在由于下面的构建错误,我无法构建项目.

无法解决:监视
打开文件

"打开文件"链接指向build.gradle(Module)文件.我试过"无效并重新启动"这没有用.

在"无法解决:监视器"或"无法解决:"下搜索未导致任何解决方案.

在这一点上我完全被难住了.

模块:build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion '28.0.3'

    defaultConfig {
        applicationId "com.example.android.sunshine"
        minSdkVersion 14
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'

    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'

    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support:support-annotations:28.0.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
Run Code Online (Sandbox Code Playgroud)

Nhấ*_*ang 6

每当我从Git仓库结帐新分支或在Android Studio中创建新项目时,我就遇到过这个问题.

根本原因:当我尝试构建应用程序时,Android Studio会显示此错误

Could not find monitor.jar (com.android.support.test:monitor:1.0.2).
Searched in the following locations:
    https://jcenter.bintray.com/com/android/support/test/monitor/1.0.2/monitor-1.0.2.jar
Run Code Online (Sandbox Code Playgroud)

在浏览器上打开https://jcenter.bintray.com/com/android/support/test/monitor/1.0.2/monitor-1.0.2.jar我收到此错误.

{
  "errors" : [ {
    "status" : 404,
    "message" : "Could not find resource"
  } ]
}
Run Code Online (Sandbox Code Playgroud)

我的假设是monitorjcenterrepo中删除了(可能是暂时的)依赖.结果,构建过程失败.所以我找出了2个解决方案:

解决方案1:转到build.gradle (Project)更改repos的顺序,因此gradle构建系统将首先monitorgooglerepo中找到依赖关系.幸运的是,这种依赖关系在repo中可用(至少到目前为止).

allprojects {
    repositories {
        jcenter()
        google()
    }
}
Run Code Online (Sandbox Code Playgroud)

allprojects {
    repositories {
        google()
        jcenter()
    }
}
Run Code Online (Sandbox Code Playgroud)

解决方案2:转到build.gradle (Module:App)注释或删除这些行.这意味着我们的应用程序不需要Android测试支持库,它提供了一个用于测试Android应用程序的广泛框架.

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:28.0.0'

    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.android.support:preference-v7:28.0.0'

    androidTestImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support:support-annotations:28.0.0'

    // Comment-out or delete these lines
//    androidTestImplementation 'com.android.support.test:runner:1.0.2'
//    androidTestImplementation 'com.android.support.test:rules:1.0.2'
}
Run Code Online (Sandbox Code Playgroud)

然后点击立即同步.