依赖项 'androidx.activity:activity:1.8.0' 需要依赖它的库或应用程序来编译兼容 Android API 的 34 版本或更高版本。

29
我在Android Studio中创建了一个新项目,但是当我运行应用程序进行测试时,它显示了以下错误:
An issue was found when checking AAR metadata:

  1.  Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that
      depend on it to compile against version 34 or later of the
      Android APIs.

      :app is currently compiled against android-33.

      Also, the maximum recommended compile SDK version for Android Gradle
      plugin 8.0.2 is 33.

      Recommended action: Update this project's version of the Android Gradle
      plugin to one that supports 34, then update this project to use
      compileSdk of at least 34.

      Note that updating a library or application's compileSdk (which
      allows newer APIs to be used) can be done separately from updating
      targetSdk (which opts the app in to new runtime behavior) and
      minSdk (which determines which devices the app can be installed
      on).

我不知道发生了什么事,但目前我正在使用最新的更新和库。
这些是依赖项:
dependencies {
    implementation 'androidx.appcompat:appcompat:1.6.1'
    implementation 'com.google.android.material:material:1.10.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    implementation 'com.github.bumptech.glide:glide:4.16.0'
    testImplementation 'junit:junit:4.13.2'

    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}

这是代码:
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;

import java.util.ArrayList;

public class AllBook extends AppCompatActivity {

    private RecyclerView bookRecView;
    BookRecAdapter bookAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_book);
        bookAdapter = new BookRecAdapter(this);
        bookRecView = findViewById(R.id.booksRecView);
        bookRecView.setAdapter(bookAdapter);
        bookRecView.setLayoutManager(new GridLayoutManager(this, 2));

        ArrayList<Book> books = new ArrayList<>();
        books.add(new Book(1, "1Q84", "Haruki Murakumi", 135, "https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1483103331l/10357575.jpg", "1Q84 is a novel written by Japanese writer Haruki Murakami, first published in three volumes in Japan in 2009–10."
        , "1Q84 is a novel written by Japanese writer Haruki Murakami, first published in three volumes in Japan in 2009–10. It covers a fictionalized year of 1984 in parallel with a \"real\" one. The novel is a story of how a woman named Aomame begins to notice strange changes occurring in the world"));

        bookAdapter.setBooks(books);
    }
}

1
错误很明显:您正在使用一个只适用于compileSdk >= 34的依赖项,而您的版本是33。要么降级依赖项,要么将您自己的compileSdk更新到34。 - undefined
感谢您的帮助。我已将材料版本从"implementation 'com.google.android.material:material:1.10.0'"更改为"implementation 'com.google.android.material:material:1.5.0'"。目前项目正在运行中。 - undefined
5
@jorn,恕我直言,这并不清楚,因为它没有说明那个依赖是什么。正如其他人所评论的,com.google.android.material:material 1.10.0 是问题所在,但你无法从错误信息中得知这一点。 - undefined
这个回答解决了你的问题吗?Android Studio错误:"检查AAR元数据时发现6个问题" 和那个问题一样,只是将版本更新到了9个月前的v34而不是v33。 - undefined
12个回答

50
将此实现替换为: implementation 'com.google.android.material:material:1.8.0', 而不是: implementation 'com.google.android.material:material:1.10.0'。

你知道如果我有一个组合项目,我可以改变什么吗? - undefined
帮我省了很多麻烦! - undefined
对我来说很有效,谢谢你。 - undefined

18
只需要在build.gradle.kts中将compileSdk = 33更新为34

11
我遇到了同样的问题,我将Material插件降级到了
implementation 'com.google.android.material:material:1.10.0'

implementation 'com.google.android.material:material:1.6.1'

现在它运行得很好。

你也可以将它更改为1.7.2 - undefined
支持1.8.0版本 - undefined

4
如果您访问material 1.10.0的Maven存储库页面,您会注意到一个名为'Compile Dependencies'的部分。这个部分列出了编译和正常运行所需的材料依赖项。通常情况下,当您在项目中声明主要依赖项时,这些编译依赖项会自动包含在内。
列表中的第一个依赖项是'activity 1.8.0',它只与'compileSdk'版本大于或等于34兼容。要解决这个兼容性问题,您可以降级材料依赖项或升级项目的'compileSdk'版本。

4
每个人都面临着同样的问题,因为新版本的Android Studio已经发布。你只需要将compileSdk的值从33改为34,或者将com.google.android.material:material的版本从10降级到9,也就是替换以下这行代码:

implementation 'com.google.android.material:material:1.10.0'

用以下这行代码替换:

implementation 'com.google.android.material:material:1.9.0'

这两种解决方案都应该在你的modulebuild.gradle文件中应用,而不是在你的project的文件中。

1
自上周以来,Android将其活动版本更新为1.8.0,要求您的最低sdkVersion为34。如果您将版本从1.8.0更改为1.7.2,问题将得到解决,因为该版本要求最低sdkVersion为33。

我只是在想:如果活动版本自动设置为特定值,为什么他们不直接将compileSdk的值也设置为特定值(在这种情况下为34),这样你就不必在每次创建新项目时手动更改它了。 - undefined
@bighugedev 你说得对。谷歌假装每个人都有他们所拥有的特权。他们最近开发的大部分应用都是这样,无法在市场上取得成功。 - undefined

0
遇到了同样的问题。建议的解决方法是将项目更新为使用较新的compileSdk。
为了做到这一点,导航到Gradle Scripts > build.gradle.kts (Module.app)。将compileSdk从33替换为34。点击右上角的“立即同步”按钮,问题应该就解决了。

0
我遇到了同样的问题。我将编译器版本更改为SDK 34,现在它正常工作了。如果有帮助,请告诉我。

0
将compileSdk更改为34
将targetSdk更改为34

0
我之前遇到了同样的问题,但已经使用了compileSDK=34。问题是通过检查我的所有实现来解决的。我有一些旧的实现仍在使用android.*依赖而不是androidx.*。在清理了这些实现并将它们改为androidx之后,gradle构建成功运行了。

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