title: 安卓开发踩坑记录
date: 2023-5-30
categories: 技术分享

tags: 安卓开发

该死的依赖和版本兼容

Gradle、AGP、compilerSDK,JDK,还有一般的dependences,这几个东西相互依赖和支持,必须保证能一起工作,不然就呵呵呵……

Gradle和AGP

一般遇到:

Caused by: org.gradle.api.internal.plugins.PluginApplicationException: Failed to apply plugin [id ‘com.android.application’]

就是Gradle和AGP版本不兼容,需要调整Gradle版本,或者调整AGP版本。

依赖与compilerSDK与AGP版本不兼容

4 issues were found when checking AAR metadata:

  1. Dependency ‘androidx.activity:activity:1.9.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 7.4.1 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
    compileSdkVerion of at least 34.
    Note that updating a library or application’s compileSdkVersion (which
    allows newer APIs to be used) can be done separately from updating
    targetSdkVersion (which opts the app in to new runtime behavior) and
    minSdkVersion (which determines which devices the app can be installed
    on).

一般这种很大白话,意思就是跟你说你有哪些依赖需要compilerSDK 34,但是你的SDK版本不支持,需要更新SDK版本从33到34.但是支持34的AGP版本又是有限制的。

设备模拟器

遇到过

E/Fence: waitForever: Throttling EGL Production: fence 94 didn’t signal in 3000 ms

这个问题,是因为模拟器的性能不够,可以
进入AVD Manager,更改设备的设置。例如,在“Emulated Performance”部分中将“Graphics”设置为“Hardware GLSE 2.0”。

但是呢,并不是说想改就能改的,我原本的pixel 3 API 34就不给我改,这个选项是灰色的。

Can’t change emulated performance of AVD in Android Studio

https://stackoverflow.com/questions/44328225/cant-change-emulated-performance-of-avd-in-android-studio#:~:text=The%20solution%20is%20to%20edit%20AVD%20and,under%20Emulated%20Performance%2C%20change%20the%20grpahics%20to%20Software.

查资料之后发现只能重新创建一个新的模拟器,然后要在创建AVD时创建一个新的“硬件配置文件”。重新下载一遍相关的镜像和API,新的设备就能跑这个应用了。

参考资料