如何解决“ERROR: Failed to resolve: androidx”错误?

4

我又回到工作状态,准备完成我的应用程序,但当应用程序开始同步时,它报错了:

无法解决:androidx 受影响的模块:href="openFile:D:/.android/Step View/Application/Source Code/app/build.gradle">app

我看到过类似的问题,但对我没用。对于我的糟糕英语表示抱歉。

这是我的 gradle. app 文件:

buildscript {
    repositories {
        maven { url 'https://plugins.gradle.org/m2/' }
    }
    dependencies {
        classpath 'gradle.plugin.com.onesignal:onesignal-gradle-plugin:[0.11.0, 0.99.99]'
    }
}
apply plugin: 'com.onesignal.androidsdk.onesignal-gradle-plugin'

repositories {
    maven {
        url 'https://maven.google.com'
    }
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.xcoder.stepview"
        minSdkVersion 17
        targetSdkVersion 28
        multiDexEnabled true
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.connection_light.runner.AndroidJUnitRunner"
        manifestPlaceholders = [
                onesignal_app_id               : '6a2c7692-81ec-4d12-b973-6b78f71f380e',
                // Project number pulled from dashboard, local value is ignored.
                onesignal_google_project_number: 'REMOTE'
        ]
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    buildToolsVersion '28.0.3'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'
    implementation 'com.google.firebase:firebase-core:16.0.6'
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.github.kittinunf.fuel:fuel-android:1.12.1'
    implementation 'com.google.firebase:firebase-ads:17.1.2'
    implementation 'com.github.bassaer:chatmessageview:1.10.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
    implementation 'com.github.markushi:circlebutton:1.1'
    implementation 'com.google.android.material:material:1.1.0-alpha02'
    implementation 'com.google.firebase:firebase-database:16.0.5'
    implementation 'com.github.ybq:Android-SpinKit:1.2.0'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'commons-io:commons-io:2.5'
    implementation 'androidx.percentlayout:percentlayout:1.0.0'
    implementation 'com.onesignal:OneSignal:[3.9.1, 3.99.99]'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.connection_light:runner:1.1.1'
    androidTestImplementation 'androidx.connection_light.espresso:espresso-core:3.1.1'
}

apply plugin: 'com.google.gms.google-services'

https://dev59.com/f7Xna4cB1Zd3GeqPIk-m#57198973 - Sumit Shukla
5个回答

3
在我的情况下,这是由于build.gradle中的一个错别字引起的:
//androidTestImplementation 'androidx  .test.espresso:espresso-core:3.2.0' // wrong!
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

我通过在命令行中使用stacktrace选项运行Gradle包装器找到了错误:

./gradlew clean build --stacktrace

输出结果:

错误原因: org.gradle.internal.resolve.ModuleVersionNotFoundException: 未找到 androidx. test.espresso:espresso-core:3.2.0.


0

你需要升级所有基础库

修改它

    implementation 'androidx.appcompat:appcompat:1.1.0-alpha01'

    implementation 'androidx.appcompat:appcompat:1.+'

并且

 androidTestImplementation 'androidx.connection_light:runner:1.1.1'

 androidTestImplementation 'androidx.test:runner:1.+'

并且

 androidTestImplementation 'androidx.connection_light.espresso:espresso-core:3.1.1'

androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'

0

对我来说,这是

implementation 'androidx.appcompat:appcompat:1.1.0'

必须是

implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'

这意味着检查版本并为您拥有的每个AndroidX实现最新版本。


0

尝试将所有的com.android*更新为可用的com.androidx*版本。

确保你已经...

android.enableJetifier=true
android.useAndroidX=true

已添加到您的gradle.properties文件中。

或者您也可以直接执行

With Android Studio 3.2 and higher, you can quickly migrate an existing project 
to use AndroidX by selecting Refactor > Migrate to AndroidX from the menu bar.

https://developer.android.com/jetpack/androidx/migrate


0

您在一个项目中同时使用了support libraryandroidx library,这就是问题所在。

将支持库更改为首选的AndroidX库。

您还可以从Android Studio迁移到AndroidX

只需转到重构 > 迁移到AndroidX > 迁移

gradle.properties文件中添加以下代码

android.enableJetifier=true
android.useAndroidX=true

有关迁移检查的更多信息this


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