Android Studio 构建错误 - “无法解决:监控" [英] Android Studio Build Error - "Failed to resolve: monitor"

查看:34
本文介绍了Android Studio 构建错误 - “无法解决:监控"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I had a previously running project, where the versions were upgraded to the latest. Now I cannot build the project due to below build error.

无法解决:监控
打开文件

Failed to resolve: monitor
Open File

打开文件"链接指向 build.gradle(模块)文件.我尝试了无效并重新启动",但没有帮助.

The "Open File" link is to the build.gradle (Module) file. I tried "Invalidate and Restart" which does not help.

在无法解决:监控"或无法解决:"下搜索没有找到任何解决方案.

Searching under "Failed to resolve: monitor" or "Failed to resolve:" did not result in any solutions.

此时我完全被难住了.

模块: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'
}

推荐答案

昨天每当我从 Git 存储库签出新分支或在 Android Studio 中创建新项目时,我都遇到过这个问题.

I had encountered this problem yesterday whenever I checkout a new branch from a Git repo or create a new project in Android Studio.

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

Root cause: When I try to build application, the Android Studio show this error

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

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

Opening https://jcenter.bintray.com/com/android/support/test/monitor/1.0.2/monitor-1.0.2.jar on a browser I got this error.

{
  "errors" : [ {
    "status" : 404,
    "message" : "Could not find resource"
  } ]
}

我的假设是 monitor 依赖项已从 jcenter 存储库中删除(可能是暂时的).结果构建过程失败.所以我想出了两个解决方案:

My assumption is the monitor dependency has been removed (might be temporarily) from jcenter repo. As a result the build process failed. So I figure out 2 solutions:

方案一:去build.gradle(Project)改变repos的顺序,这样gradle构建系统就会在里面找到monitor依赖google 首先是 repo.幸运的是,这个依赖在 repo 中是可用的(至少到目前为止).

Solution 1: Go to build.gradle (Project) change the order of repos, so gradle build system will find monitor dependency in google repo first. Fortunately, this dependency is available in the repo (at least so far).

allprojects {
    repositories {
        jcenter()
        google()
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

Solution 2: Go to build.gradle (Module:App) comment-out or delete these lines. It mean our app do not need the Android Testing Support Library which provides an extensive framework for testing Android apps.

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'
}

然后点击立即同步.

这篇关于Android Studio 构建错误 - “无法解决:监控"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆