当前位置: 首页 > news >正文

Android targetSdkVersion改成33遇到的坑

targetSdkVersion 改成 33 ,遇到一些坑。

需要注意的地方:

  • 修改 targetSdkVersion 为 33。
  • AndroidManifest.xml 里添加 android:exported=“true”
  • 升级 Gradle 版本。
  • 升级第三方库。

修改 app 的 build.gradle

android {compileSdkVersion 33defaultConfig {targetSdkVersion 33}
}

修改 AndroidManifest.xml ,为 activity 、service 等四大组件配置 android:exported="true"

编译报错,提示

We recommend using a newer Android Gradle plugin to use compileSdk = 33This Android Gradle plugin (7.1.1) was tested up to compileSdk = 32This warning can be suppressed by addingandroid.suppressUnsupportedCompileSdk=33
to this project's gradle.propertiesThe build will continue, but you are strongly encouraged to update your project to
use a newer Android Gradle Plugin that has been tested with compileSdk = 33

需要升级 Gradle 版本,修改 project 的 build.gradle

buildscript {repositories {google()mavenCentral()}dependencies {//classpath "com.android.tools.build:gradle:7.1.1"classpath "com.android.tools.build:gradle:7.4.2"// NOTE: Do not place your application dependencies here; they belong// in the individual module build.gradle files}
}

修改 gradle-wrapper.properties ,使用 gradle-7.5-bin.zip ,

#Thu Aug 08 18:55:44 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

编译OK,功能验证报错,

java.lang.IllegalArgumentException: com.xxx: Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
Strongly consider using FLAG_IMMUTABLE, only use FLAG_MUTABLE if some functionality depends on the PendingIntent being mutable, e.g. if it needs to be used with inline replies or bubbles.at android.app.PendingIntent.checkFlags(PendingIntent.java:401)at android.app.PendingIntent.getBroadcastAsUser(PendingIntent.java:671)at android.app.PendingIntent.getBroadcast(PendingIntent.java:658)at androidx.work.impl.utils.ForceStopRunnable.getPendingIntent(ForceStopRunnable.java:273)at androidx.work.impl.utils.ForceStopRunnable.isForceStopped(ForceStopRunnable.java:151)at androidx.work.impl.utils.ForceStopRunnable.forceStopRunnable(ForceStopRunnable.java:171)at androidx.work.impl.utils.ForceStopRunnable.run(ForceStopRunnable.java:102)at androidx.work.impl.utils.SerialExecutor$Task.run(SerialExecutor.java:91)at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137)at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637)

wtf ? 我都没有使用 PendingIntent 。

多次尝试后,最后发现是导入了第三方库导致的。

解决办法:更新第三方库。 旧版本的第三方库可能没有做 targetSdkVersion 33 的适配。

http://www.lryc.cn/news/421601.html

相关文章:

  • 1985-2023年中国城市统计年鉴(PDF+EXCEL)
  • 从AI小白到大神的7个细节:让你开窍逆袭
  • AIxBoard部署BLIP模型进行图文问答
  • 小白零基础学数学建模应用系列(一):探索自由下落模型——以“坠落的硬币”为例
  • linux主机间免密登录
  • 【海思SS626 | VB】关于 视频缓存池 的理解
  • RCE漏洞及绕过
  • 非对称加密算法-ECDHE
  • 10分钟学会Docker的安装和使用
  • 江科大/江协科技 STM32学习笔记P20
  • CSS 实现两边固定宽,中间自适应
  • C#图片批量下载Demo
  • 部署Springboot + Vue 项目到远程服务器Windows10系统的详细配置
  • 智驭灌区,科技领航—— 高效灌区信息化系统管理平台
  • 下载免费设计素材,有这7个网站就够了
  • 【漏洞复现】某赛通数据泄露防护(DLP)系统 NetSecConfigAjax SQL注入漏洞
  • c++中的仿函数
  • springboot整合mybatis-plus和pagehelper插件报错,
  • 趋动科技荣登「AIGC赋能金融创新引领者TOP20」
  • SOPHGO算能科技BM1684盒子占用空间满的问题解决
  • Spring Boot实用小技巧 - - 第523篇
  • 安卓App开发 篇二:Android UI和布局
  • k8s基本介绍
  • go http启动应用程序
  • Redis:概念、部署、配置、优化
  • 华为OD-D卷找座位
  • Go sdk下载和配置环境变量
  • qt的项目结构
  • 【NLP】文本特征处理:n-gram特征和文本长度规范
  • ESP32人脸识别开发 ---partitions.csv配置的一些说明(五)