java - Android Studio 编译错误 : Could not find runtime-2. 4.0.aar

标签 java android build.gradle

当尝试在我的 android 设备上运行我的应用程序时,出现以下错误:

Execution failed for task ':app:checkDebugAarMetadata'.
> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not find runtime-2.4.0.aar (androidx.lifecycle:lifecycle-runtime:2.4.0).
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/androidx/lifecycle/lifecycle-runtime/2.4.0/runtime-2.4.0.aar

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

我试过:

  1. 将我的 compileSdkVersion 和 minSdkVersion 设置为 31
  2. 检查该库是否确实存在于 maven 存储库中 here

我的build.gradle(应用级别)


    plugins {
        id 'com.android.application'
        id 'com.google.gms.google-services'
    }
    
    android {
        compileSdkVersion 31
    
        defaultConfig {
            applicationId "com.brianokoth.skillsapp"
            minSdkVersion 21
            targetSdkVersion 31
            versionCode 1
            versionName "1.0"
    
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    dependencies {
    
        implementation 'androidx.appcompat:appcompat:1.4.0'
        implementation 'com.google.firebase:firebase-auth:21.0.1'
        implementation 'com.google.android.material:material:1.4.0'
        implementation 'de.hdodenhof:circleimageview:3.0.0'
        implementation 'com.google.firebase:firebase-storage:20.0.0'
        implementation 'com.squareup.picasso:picasso:2.71828'
        implementation 'com.firebaseui:firebase-ui-firestore:4.1.0'
        implementation "androidx.cardview:cardview:1.0.0"
        implementation 'androidx.recyclerview:recyclerview:1.2.1'
        implementation 'androidx.annotation:annotation:1.3.0'
        implementation 'androidx.lifecycle:lifecycle-runtime:2.4.0'
    }

我的build.gradle(项目级别)


    // Top-level build file where you can add configuration options common to all sub-projects/modules.
    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:4.2.2"
            classpath 'com.google.gms:google-services:4.3.10'
            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
            jcenter() // Warning: this repository is going to shut down soon
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

我期待任何帮助。

最佳答案

首先,您可以尝试 File -> Sync Project With Gradle Files 以确保它已正确导入。其次,最好添加所有 life cycle dependencies 而不是只添加一个,那已经过时了。所以删除当前的并改用这些:

 implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.0-alpha02"
 implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
 implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"

关于java - Android Studio 编译错误 : Could not find runtime-2. 4.0.aar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70275458/

相关文章:

java - 循环数组队列中的余数操作数有什么意义

Java 泛型比较器单例

java - 在 Java 中更改变量的值一定时间

java - 尝试在 Java 中使用 lambda 进行小规模重构

java - 使用按钮 onClick 发起 Skype 通话

java - 向 android studio 项目添加字体导致构建失败

android - 使用旧学校服务进行改造

java - 从 Android 模拟器连接到 localhost

gradle - CorDapp JaCoCo代码覆盖率

gitlab - 为什么 gitlab-ci.yml 不识别 sonarqube -Dsonar 命令?