关于androidx.appcompat:appcompat-resources:1.6.1要求使用更高版本进行编译的问题,要怎么解决合适?

我在我的工程中可能依赖了androidx.appcompat:appcompat-resources:1.6.1相关的库,导致异常,它建议我更换成android-33
8 issues were found when checking AAR metadata:

  1. Dependency 'androidx.appcompat:appcompat-resources:1.6.1' requires libraries and applications that
    depend on it to compile against version 33 or later of the
    Android APIs.

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 33, for example 33.

    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).

  2. Dependency 'androidx.appcompat:appcompat:1.6.1' requires libraries and applications that
    depend on it to compile against version 33 or later of the
    Android APIs.

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 33, for example 33.

    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).

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

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 33, for example 33.

    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).

  4. Dependency 'androidx.emoji2:emoji2-views-helper:1.2.0' requires libraries and applications that
    depend on it to compile against version 32 or later of the
    Android APIs.

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 32, for example 33.

    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).

  5. Dependency 'androidx.emoji2:emoji2:1.2.0' requires libraries and applications that
    depend on it to compile against version 32 or later of the
    Android APIs.

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 32, for example 33.

    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).

  6. Dependency 'androidx.core:core-ktx:1.9.0' requires libraries and applications that
    depend on it to compile against version 33 or later of the
    Android APIs.

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 33, for example 33.

    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).

  7. Dependency 'androidx.core:core:1.9.0' requires libraries and applications that
    depend on it to compile against version 33 or later of the
    Android APIs.

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 33, for example 33.

    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).

  8. Dependency 'androidx.annotation:annotation-experimental:1.3.0' requires libraries and applications that
    depend on it to compile against version 33 or later of the
    Android APIs.

    :app is currently compiled against android-31.

    Recommended action: Update this project to use a newer compileSdk
    of at least 33, for example 33.

    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).

我尝试将android-31更换成android-34,可以编译通过,但我的项目是android-31的,我需要在android-31去编译,我是否能通过将androidx.appcompat:appcompat-resources:1.6.1的版本降低到能够兼容android-31的版本,要怎么做,或者有更合适的方法推荐嘛

当我将保持 minSdkVersion 和 targetSdkVersion 为31,将 compileSdkVersion 更新为 33 或更高。可以编译通过并在我的平台安装,但是我尝试将jni的so放入我的工程,发现出现了这个异常
Cause: out extracted from path E: lib**_jni.so is not an ABI
我的so的信息为
file /system/lib64/lib**_jni.so
/system/lib64/lib**_jni.so: ELF shared object, 64-bit LSB arm64, for Android 31, BuildID=74ea3efed6754c43fce9f6b07e937eea, stripped
这要怎么做合适呢

阅读 1.6k
avatarAI BotBETA

为了解决你遇到的问题,同时保持你的项目在 android-31 上编译,你有几个选项可以考虑:

1. 降级依赖库版本

如果可能的话,你可以尝试查找与 android-31 兼容的较低版本的库。但是,这可能需要你手动查找每个库的文档或发布说明来确定哪个版本是兼容的。此外,这可能会引入其他兼容性问题,因为较旧的库版本可能不包含你需要的某些功能或修复。

2. 使用条件编译

如果项目中只有部分模块或功能需要这些新版本的库,并且这些模块或功能不是必需的,你可以考虑使用条件编译来排除这些库。但这通常不是一个可行的解决方案,因为大多数库都是全局依赖的。

3. 更新 compileSdkVersion

尽管你提到项目需要在 android-31 上编译,但更新 compileSdkVersion 到更高版本(如 android-33android-34)通常不会影响应用的运行时兼容性。compileSdkVersion 主要影响编译时API的可用性,而运行时兼容性主要由 minSdkVersiontargetSdkVersion 决定。

  • 更新 compileSdkVersion: 在你的 build.gradle 文件中,将 compileSdkVersion 更新为 33 或更高。
  • 保持 minSdkVersiontargetSdkVersion 不变: 确保这些值保持为你需要的值(例如 android-31),以维持运行时兼容性。

4. 使用 Jetifier

如果你使用的是旧版本的 Android Gradle 插件,并且某些库需要更新到仅支持更高 API 级别的版本,你可以考虑使用 Jetifier。Jetifier 是一个转换工具,可以将库中的旧版支持库 API 调用转换为 AndroidX 等效项。但是,对于 compileSdkVersion 的要求,Jetifier 可能无法直接解决。

推荐的做法

由于大多数现代 Android 开发都倾向于使用较新的 API 和库版本,更新 compileSdkVersionandroid-33 或更高 是最推荐的解决方案。这样做可以确保你能够使用最新的 API 和库功能,同时仍然通过调整 minSdkVersiontargetSdkVersion 来维护运行时兼容性。

如果你确实需要在 android-31 上编译,但遇到了无法解决的依赖问题,那么可能需要重新评估你的项目需求或寻找替代的库版本。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题