android - 更新gradle版本并编译到实现时,“无法解决recyclerview-v7”错误

标签 android android-studio gradle

我从事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降级以使其正常工作,但这不是解决方案。有人知道这个问题吗?

最佳答案

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

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

and You just need to add google() on top of jcenter() inside repositories blockes.


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“项目级别”

关于android - 更新gradle版本并编译到实现时,“无法解决recyclerview-v7”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50902984/

相关文章:

java - Gradle 构建找不到包 'java.net.http'

Android:将短信 (SMS) 标记为未读

Android AnimationDrawable 最大 PNG 文件?

android - 如何在 ionic +react + capacitor 项目中设置最低 android 版本支持?

android - actionButtonStyle 不适用于支持库 v23.1.0

安装 OSX 10.11 El Capitan 公共(public) Beta 后 Android SDK 管理器卡住

gradle - Gradle (Kotlin DSL): “Unresolved reference: proguard”

gradle - 如何在Gradle中将文件复制到平面目录

安卓工作室 : How to Migrate IntelliJ Project to Gradle?

android-studio - Android Studio 3.3.2 注释处理器