错误:无法解决:在android studio中常见

时间:2018-06-08 12:41:59

标签: firebase dependencies build.gradle android-studio-3.1

我重新安装了android工作室,在重新打开旧项目的同时显示错误:

Error:Failed to resolve: firebase-messaging
<a href="openFile:D:/Android projects/Porject_name/app/build.gradle">Open File</a>

Error:Failed to resolve: common
<a href="openFile:D:/Android projects/Porject_name/app/build.gradle">Open File</a>

build.gradle(Porject)文件:

// Top-level build file where you can add configuration options common to 

all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        classpath 'com.google.gms:google-services:3.1.0'

    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()

        google()


        maven {
            url "https://jitpack.io"
        }

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

build.gradle(app)文件:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion '27.0.3'
    useLibrary 'org.apache.http.legacy'

    defaultConfig {
        applicationId "com.example.abc"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:26.1.0'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:design:26.1.0'
    compile 'com.android.support:support-v4:26.1.0'
    compile 'com.github.traex.rippleeffect:library:1.3'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.google.firebase:firebase-messaging:12.0.0'
    compile 'com.baoyz.swipemenulistview:library:1.3.0'
    compile 'se.emilsjolander:stickylistheaders:2.1.5'
    compile 'com.applandeo:material-calendar-view:1.4.0'
    compile 'com.github.michaelye.easydialog:easydialog:1.4'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    compile 'com.squareup.picasso:picasso:2.5.2'

}
apply plugin: 'com.google.gms.google-services'

我添加了所有必需的插件和sdk但仍然无法正常工作。 安装了Firebase插件,即谷歌播放服务。在卸载工作室之前它工作正常。请帮忙。

3 个答案:

答案 0 :(得分:21)

将此maven {url“https://maven.google.com”}添加/移动到build.gradle中的顶级矿工

答案 1 :(得分:6)

这对我有用。我只是按照这个重新排序

repositories {
    mavenCentral()
    mavenLocal()
    google()
    jcenter()
  }

答案 2 :(得分:0)

当我在Android Studio 预览(Android Studio 3.2 Canary 18)版本中运行Project时,我也遇到了这个问题

  • gradle-wrapper.properties 分发网址distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

  • 并且它还在 build.gradle (项目级别)中加入了classpath classpath 'com.android.tools.build:gradle:3.2.0-alpha16'

因此,android studio预览版本所做的上述更改导致我的项目出现Error:Failed to resolve: common <a href..>错误,所以我通过将它们更改回稳定来解决这个问题

gradle-wrapper.properties

中将分发网址更改为 distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

将类路径更改为 classpath 'com.android.tools.build:gradle:3.1.2'