无法解决Android Studio的依赖问题

4

我只想知道如何成功构建Gradle插件

错误无法解决':app@debugAndroidTest/compileClasspath'的依赖关系:无法解决androidx.core:core:1.1.0。 显示详细信息 受影响的模块:app

**

build.gradle :project

**

// 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.5.1'

        // 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:模块:应用程序

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "android.example.com"
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.android.support:support-v4:28.0.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    implementation "com.android.support:support-v4:28.0.0"
    implementation "com.android.support:appcompat-v7:28.0.0"
    implementation "com.android.support:support-vector-drawable:28.0.0"
    implementation "com.android.support:recyclerview-v7:28.0.0"
    implementation "com.android.support:design:28.0.0"
    implementation "com.android.support.constraint:constraint-layout:1.1.3"
    implementation 'com.android.support:support-annotations:28.0.0'

    implementation 'com.jakewharton:butterknife:10.0.0'
    annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0'


}

我只想知道如何成功构建Gradle插件。

1
你正在混合使用androidX和support版本。只需执行以下操作即可解决问题。 菜单栏重构 > 迁移到AndroidX。可能会显示一些重复依赖的警告。只需删除这些重复项并重新同步即可。 - DHAVAL A.
1
当我创建新项目时,默认使用不同的Gradle和SDK 29以及AndroidX实现,也会出现相同的错误。当使用Android支持实现时也会出现相同的错误。 - Ahmed Nasser
1个回答

0

使用Android Studio 3.2及更高版本,您可以通过从菜单栏中选择重构 > 迁移到AndroidX来将现有项目迁移到AndroidX。

重构命令使用了两个标志。默认情况下,这两个标志在您的gradle.properties文件中都设置为true:

android.useAndroidX=true

Android插件使用适当的AndroidX库,而不是Support Library。

android.enableJetifier=true

Android插件通过重写第三方库的二进制文件自动迁移现有库以使用AndroidX。

详情请参见https://developer.android.com/jetpack/androidx/migrate


1
gradle.properties中默认已经写入了两个标志“true”,但仍然出现错误。 - Ahmed Nasser
请按照以下步骤进行重构> 迁移到AndroidX - Md. Asaduzzaman
你可以使用 implementation 'androidx.legacy:legacy-support-v4:1.0.0' 代替 AppCompat 支持。 - Md. Asaduzzaman
我创建了一个新项目来查看问题所在,然后当它构建时,我遇到了相同的错误,但我没有更改gradle.app的实现,它的依赖关系如下:dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0' } - Ahmed Nasser
实现 'com.google.android.material:material:1.0.0' 实现 'androidx.cardview:cardview:1.0.0' 实现 'androidx.constraintlayout:constraintlayout:1.1.3' 测试实现 'junit:junit:4.12' Android测试实现 'androidx.test.ext:junit:1.1.1' Android测试实现 'androidx.test.espresso:espresso-core:3.2.0' } - Ahmed Nasser

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接