【问题标题】:unable resolve dependency android studio无法解决依赖android studio
【发布时间】:2019-10-12 06:17:08
【问题描述】:

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

错误无法解析“:app@debugAndroidTest/compileClasspath”的依赖项:无法解析androidx.core:core:1.1.0。 显示详细资料 受影响的模块:app

**

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.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 :module:app

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 插件

【问题讨论】:

  • 您正在将 androidX 与支持版本混合使用。只需执行以下操作将对您有所帮助。菜单栏Refactor > Migrate to AndroidX。可能它会向您显示一些重复依赖项的警告。因此,只需删除这些重复项并再次同步即可。
  • 当我创建新项目时,我也有同样的错误,使用 sdk 29 和 androidx 实现的不同 gradle 默认在使用 android 支持实现时也有同样的错误

标签: android gradle android-gradle-plugin


【解决方案1】:

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

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

android.useAndroidX=true

Android 插件使用适当的 AndroidX 库而不是支持库。

android.enableJetifier=true

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

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

【讨论】:

  • gradle.properties 中已经写了两个标志,默认为“true”,仍然有错误
  • 按照重构>迁移到AndroidX这里的步骤
  • 您可以使用implementation 'androidx.legacy:legacy-support-v4:1.0.0' 而不是 AppCompat 支持
  • 我创建了新项目以查看问题出在哪里,然后当它构建时我有同样的错误,但我没有更改 gradle.app 的实现是依赖项 { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'androidx.appcompat:appcompat:1.1.0'
  • 实施 'com.google.android.material:material:1.0.0' 实施 'androidx.cardview:cardview:1.0.0' 实施 'androidx.constraintlayout:constraintlayout:1.1.3' testImplementation ' junit:junit:4.12' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }
猜你喜欢
  • 2019-07-06
  • 1970-01-01
  • 2015-05-09
  • 2016-03-06
  • 2018-04-22
  • 2016-09-03
  • 2021-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多