【问题标题】:'Could not resolve recyclerview-v7' Error, while updating gradle version and compile to implementation'Could not resolve recyclerview-v7' 错误,同时更新 gradle 版本并编译到实现
【发布时间】:2018-06-18 05:11:47
【问题描述】:

我在 Android 上工作 2 年了。我从来没有遇到过这样的问题。 更新 Android Studio 和 com.android.tools.build:gradle:3.1.3 后,我遇到了这个问题。

问题: Could not resolve RecyclerView-v7

这是一个愚蠢的问题,让我卡了 1 个小时。这只发生在com.android.tools.build:gradle:3.1.3

项目级 build.gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply from: rootProject.file('dependencies.gradle')

buildscript {
    repositories {
        jcenter()

        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
    }
}

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
        jcenter()
        maven { url 'https://maven.google.com' }
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
}

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

应用级 build.gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    defaultConfig {
        applicationId "in.kpis.upkeep"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        setProperty("archivesBaseName", applicationId + "-v" + versionCode + "(" + versionName + ")")
    }
    dataBinding {
        enabled = true
    }
    buildTypes {
        debug {
            versionNameSuffix "-T"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            versionNameSuffix "-R"
        }
    }

    useLibrary 'org.apache.http.legacy'
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
    compileOptions {
        targetCompatibility rootProject.ext.targetCompatibilityVersion
        sourceCompatibility rootProject.ext.sourceCompatibilityVersion
    }
}
def SUPPORT_LIB_VER = '27.1.1'
def SDP_VERSION = '1.0.5'
def BUTTER_KNIFE_VER = '8.8.1'
dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    implementation "com.android.support:appcompat-v7:$SUPPORT_LIB_VER"
    implementation "com.android.support:design:${SUPPORT_LIB_VER}"
    implementation "com.android.support:cardview-v7:$SUPPORT_LIB_VER"
    implementation "com.android.support:recyclerview-v7:${SUPPORT_LIB_VER}"
    implementation 'com.googlecode.libphonenumber:libphonenumber:8.0.1'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.google.code.gson:gson:2.8.4'
    implementation "com.jakewharton:butterknife:${BUTTER_KNIFE_VER}"
    annotationProcessor "com.jakewharton:butterknife-compiler:${BUTTER_KNIFE_VER}"
    implementation 'com.wdullaer:materialdatetimepicker:3.6.0'
    implementation "com.intuit.sdp:sdp-android:$SDP_VERSION"
    implementation "com.intuit.ssp:ssp-android:$SDP_VERSION"
    implementation group: 'org.simpleframework', name: 'simple-xml', version: '2.7.1'
    implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.github.esafirm.android-image-picker:imagepicker:1.13.0'
    implementation 'com.github.bumptech.glide:glide:4.5.0'
}

导出版本

ext {
    compileSdkVersion = 27
    buildToolsVersion = '27.0.3'
    minSdkVersion = 15
    targetSdkVersion = 27
    sourceCompatibilityVersion = JavaVersion.VERSION_1_8
    targetCompatibilityVersion = JavaVersion.VERSION_1_8
}

我降级了 build.gradle 以使其正常工作,但这不是解决方案。有人知道这个问题吗?

【问题讨论】:

  • 你的目标 SDK 版本是什么。
  • 编辑了我的问题。
  • gradle 同步出现问题对吗?
  • @SaurabhBhandari 我需要在我的问题中提到我已经尝试了所有可以尝试的东西吗?
  • @JojoNarte 是的,我无法构建项目。

标签: android android-studio gradle


【解决方案1】:

这是因为您已将 build.gradle “应用级别”中的所有 compile 更新为 implementation

要解决这个问题 - 转到您的 build.gradle (Project level)

你只需要在 jcenter() 里面添加 google() 存储库块。

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.3'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

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

将此代码放入您的 build.gradle “项目级别”

【讨论】:

  • 我会试试这个并告诉你。
  • 什么状态?
  • 我没有标记正确,因为我无法检查它。我已经为你的善意的努力投了赞成票。我一定会在我有空的时候试试这个。
【解决方案2】:

google() 添加到您的allprojects >> repositories 块中。您不需要添加maven { url 'https://maven.google.com' } 和连续的maven 块。

【讨论】:

    【解决方案3】:

    它使用较低版本的 Gradle 可以工作,这意味着它很可能不是因为存储库。

    也许是因为你的buildToolsVersion。我没有看到你把它放在你的build.gradle 中。请确保它是 27.0.3。

    您是否检查了您的 SDK 管理器?您可以确保您的 SDK 管理器没有使用旧版本的 SDK 构建工具。

    SDK 工具 -> 检查显示包详细信息(左下角)-> 安装 Build Tools 版本 27.0.3,并卸载旧的 Build Tools 版本

    【讨论】:

      猜你喜欢
      • 2017-02-12
      • 2022-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-25
      • 1970-01-01
      • 2017-09-03
      相关资源
      最近更新 更多