Android Studio构建错误-“;未能解决:监视器";
我有一个以前运行的项目,其中的版本升级到了最新版本。现在,由于以下生成错误,我无法生成项目 无法解析:监视器Android Studio构建错误-“;未能解决:监视器";,android,android-studio,gradle,Android,Android Studio,Gradle,我有一个以前运行的项目,其中的版本升级到了最新版本。现在,由于以下生成错误,我无法生成项目 无法解析:监视器打开文件 “打开文件”链接指向build.gradle(模块)文件。我尝试了“失效并重新启动”,但没有帮助 在“未能解决:监视器”或“未能解决:”下搜索未得到任何解决方案 在这一点上我完全被难住了 模块:build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 28 b
打开文件 “打开文件”链接指向build.gradle(模块)文件。我尝试了“失效并重新启动”,但没有帮助 在“未能解决:监视器”或“未能解决:”下搜索未得到任何解决方案 在这一点上我完全被难住了 模块: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中创建一个新项目时,我都遇到了这个问题 根本原因:当我尝试构建应用程序时,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
在浏览器上打开时出现此错误
{
"errors" : [ {
"status" : 404,
"message" : "Could not find resource"
} ]
}
我的假设是,monitor
依赖项已从jcenter
repo中删除(可能是暂时的)。因此,生成过程失败。所以我想出了两个解决方案:
解决方案1:转到build.gradle(项目)
更改回购顺序,这样gradle构建系统将首先在谷歌回购中找到监控依赖项。幸运的是,这种依赖性在回购协议中是可用的(至少到目前为止)
到
解决方案2:转到build.gradle(模块: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'
}
然后点击“立即同步”问题似乎出在jcenter上。我花了几个小时研究这个问题,你的问题似乎与我的问题相似,我认为下面的解决方案应该有效
出于某种原因,对于jcenter中的许多库,许多库的pom文件保留在适当的位置,但相应的aar文件已被删除。播放服务库的情况也是如此。请在此检查以下内容以供参考(jcentre提供了play services Basic的pom文件,但jcentre没有aar文件):
解决方案:
在项目级渐变文件中,更改以下代码块
到
为什么这样做?
在我们的第一个代码块中,当gradle试图解析存储库中的依赖项时(在我的例子中,它是jcentre存储库中的google服务库),由于相应的aar文件已被删除,因此无法解析它。结果,生成失败,如下所示:
Could not find play-services-basement.aar (com.google.android.gms:play-services-basement:15.0.1).
在我们的第二个代码块中,google repository在jcenter repository之前被引用。当gradle build启动时,它首先在存储库{…中列出的库中查找,以解析项目中使用的任何库。现在,当gradle尝试解析jcenter中的play services基底时,它成功地解析了依赖关系,因为相应的aar文件已由google存储库提供(最新版本的相同aar文件在jcenter存储库中不可用)在评估jcenter repository之前已经引用过。请检查并让我知道这是否有效。在删除androidTestImplementation'com.android.support.test:runner:1.0.2'后尝试构建并增加您的最小sdkversion@singh.indoliaSon Truong提供的解决方案是可行的,但您能否提供更多信息,说明您为什么要这样做感觉'com.android.support.test:runner:1.0.2'和mind sdk版本可能会有问题?它将帮助我解决未来的构建错误。可能重复@Radesh我在发布此问题之前尝试彻底搜索解决方案。可能是因为我缺乏gradle构建故障排除方面的知识,我永远也找不到您的帖子令人惊讶的是,这个解决方案是有效的。我也对这样的解决方案感到目瞪口呆,印象深刻。对我来说,这毫无意义。这个解决方案的原理是什么,为什么有效?根本原因在下面的答案中解释了:在您的情况下,monitor-1.0.2.jar
不再托管在jcenter中,而是pom.xml
仍然是!(请参见)@M.Ricciuti感谢您提供的信息,因此我的假设是正确的。一些依赖项已从jcenter
中删除,原因不明。最好能从jcenter
中找到他们为什么这样做的官方信息。
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'
}
allprojects {
repositories {
jcenter()
google()
}
}
allprojects {
repositories {
google()
jcenter()
}
}
Could not find play-services-basement.aar (com.google.android.gms:play-services-basement:15.0.1).