android - android studio 中的 gradle 问题

标签 android gradle

我知道这个问题:

Failed to resolve: com.android.support:cardview-v7:26.0.0 android

Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]

Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project

我读过这个文档:

Migrate to Android Plugin for Gradle 3.0.0

Migrating to Android 8.0

所以我发布这个问题是因为我相信它不是重复的。

我已经安装了 Android Studio 3.4.1。我之前没有任何以前的版本,我开始了一个新项目。

Gradle 文件中的每个设置都是由 Android Studio 自己设置的,我已经全部检查过了。

我已经试过了

文件内容如下:

build.gradle(模块:应用程序)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.0"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 28
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

}

顶层build.gradle

    // Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://maven.google.com/'}
        maven { url "https://jitpack.io" }
        maven { url 'https://dl.bintray.com/guardian/android' }
    }
}

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

gradle-wrapper.properties

 #Mon Jun 10 17:40:01 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

我在存储库中使用 google() 作为 here明确地说:

  // If you're using a version of Gradle lower than 4.1, you must instead use:
     // maven {
     //     url 'https://maven.google.com'
     // }

我的 gradle 版本是 4.1,所以我不需要上面的代码。

但我仍然收到此错误,因为其他人一直在询问:

  • Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.constraintlayout:constraintlayout:1.1.3.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.versionedparcelable:versionedparcelable:1.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-ui:1.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.vectordrawable:vectordrawable-animated:1.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.fragment:fragment:1.0.0.

我还取消选中了 gradle 中的离线复选框并使用默认

I have also unchecked the offline check box from gradle and using default

当我在 AS 3.4.1 中创建一个新项目并且已经设置了所有必要的设置时,为什么会出现此错误?

最佳答案

您正在尝试混合 AppCompat 和 Jetpack 依赖项,但您不能这样做。

我认为您可能没有为 Jetpack 库设置正确的存储库(为什么找不到任何 Jetpack 库)。

不要使用: implementation 'androidx.appcompat:appcompat:1.0.2' 。 (这是 Jetpack)——使用它的 AppCompat 版本(此外——Jetpack 与 28.x 之前的 Appcompat 版本不一致)。最重要的是,摆脱任何说 (androidx) 的东西。

关于android - android studio 中的 gradle 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56526798/

相关文章:

java - 为什么我的 JsonObjectRequest 不工作?

带有自定义 ArrayList 的 java.util.ConcurrentModificationException

android - 无法在 Android 的弹出菜单中创建 "Share"菜单

java - 在 Android Studio 中构建变体

java - 如何使用Gradle配置JCompilo

android - Android TextInput 上的 onKeyPress 方法

android - WebViewClient 正在重定向,即使没有 URL

android - 错误 :(41, 13) 无法解析 : com. 稀有卵石 :colorpicker:1. 6.0

android - Windows 10 中的 Gradle 文件目录

android - React-native 并且它不起作用,指责在项目 "Task ' 中找不到一些错误 ':app' installRelease'