【问题标题】:Unable to resolve imports from Android Support Repository (Google's Maven included)无法解析来自 Android 支持存储库的导入(包括 Google 的 Maven)
【发布时间】:2018-10-16 14:18:16
【问题描述】:

在 Android Studio 2.3 中:

应用程序构建.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "my.test"
        minSdkVersion 11
        targetSdkVersion 27
        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(dir: 'libs', include: ['*.jar'])
    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:27.0'
    compile 'com.android.support:support-v4:27.0'
    testCompile 'junit:junit:4.12'
}

root build.gradle:

   buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenLocal()
        mavenCentral()
        maven {
            url 'https://maven.google.com'
        }
    }
}

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

虽然我明确添加了 Google maven 存储库,但结果是支持库未解析:

错误:(27, 13) 无法解决: com.android.support:support-v4:27.0 ... 错误:(26, 13) 无法解决:com.android.support:appcompat-v7:27.0 ...

【问题讨论】:

  • 请添加您的整个 build.gradle 代码。

标签: android gradle android-support-library


【解决方案1】:

我怀疑你必须添加完整版代码,例如:

compile 'com.android.support:appcompat-v7:27.0.0'
compile 'com.android.support:support-v4:27.0.0'

请注意,我在版本中添加了最后一个“.0”

【讨论】:

  • 免费啤酒给你。经过一个漫长的夜晚,我的注意力正在下降......
【解决方案2】:

根据你的 gradle 版本,你现在需要使用 google()。

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

而不是

maven {
            url 'https://maven.google.com'
        }

【讨论】:

  • ... 这适用于 Android Studio >= 3。
猜你喜欢
  • 1970-01-01
  • 2020-03-15
  • 2019-11-19
  • 2017-10-29
  • 1970-01-01
  • 1970-01-01
  • 2013-10-03
  • 1970-01-01
  • 2016-04-04
相关资源
最近更新 更多