• Android Target 从 30 升到 31


    背景:11月1号起,上传aab 到 google play 必须是target 31,然后产品被拒,那只能升级了。



    步骤如下:

    1.从主工程target 从30升到31

    2.位置信息:

    用户可以请求应用只检索大致位置信息。请求 ACCESS_FINE_LOCATION 时,

    必须同时请求 ACCESS_COARSE_LOCATION 权限。

    3.Intent 过滤器:

    如果您的应用包含使用 intent 过滤器的 activity、服务或广播接收器

    您必须为这些组件明确声明 android:exported 属性。

    含有intent-filter的activity就显示指明精确值就行,默认设置为true。

    (如果是第三方库或者子库等,需要手动去每个manifest.xmal修改,)

    当然这里有个比较高大小的做法,大家可以参考这里:
    Android targetSdk 31 适配 - 掘金
     

    4.数据迁移,

    这个我们应该没有,已经采用分区存储,但是要留意一下

    在Android11中,因为无法访问sdcard/根目录下的非公共目录的文件,而以前应用喜欢在这里乱搞,而为了让应用迁移数据,Android11提供了preserveLegacyExternalStorage标记,使用此标记后,应用可以使用旧的存储模型,但是此标记只适用于升级,一旦卸载了此标记就失效了。

    5.关于包可见性的说明

      若应用以 Android 11 或更高版本为目标平台,且有拉起其他应用进行登录、分享等操作的应用场景,则应用需要在自身的 AndroidManifest.xml 中添加 元素,并声明相应的应用包名。

            比如分享到微信,建议加上微信的包名。

    6.Pendingintent 的flag 需设置 PendingIntent.FLAG_MUTABLE

    问题描述:

    在target到Android12之后,PendingIntent创建需要指定可变性FLAG_IMMUTABLE 或者 FLAG_MUTABLE

    解决办法:

    大部分情况下如果不希望创建的PendingIntent被外部应用修改,那么需要设置成PendingIntent.FLAG_IMMUTABLE既可。一些特殊情况可以设置成FLAG_MUTABLE(参考:https://developer.android.com/guide/components/intents-filters#DeclareMutabilityPendingIntent)

    7.传感器刷新问题

    问题描述:

    当使用SensorManager时,如果监听的频率太快,例如sensorManager.registerListener(this, sensor, SensorManager.SENSOR_DELAY_FASTEST);,且没有改定义permission HIGH_SAMPLING_RATE_SENSORS权限的话会有这个崩溃。

    解决办法:

    大部分情况下我们并不需要太快的监听频率,可以设置成SensorManager.SENSOR_DELAY_UI。在某些确实需要快速频率监听的话,需要加上HIGH_SAMPLING_RATE_SENSORS权限

    8.蓝牙啥的,我公司app没有,就不处理了。

    官网升级地址:https://developer.android.com/google/play/requirements/target-sdk#pre12

    9.升级遇到gms的crash,然后升级google的bom就好了,可能会有不少库不兼容


    Fatal Exception: java.lang.IllegalArgumentException: ****: 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:375)
           at android.app.PendingIntent.getActivityAsUser(PendingIntent.java:458)
           at android.app.PendingIntent.getActivity(PendingIntent.java:444)
           at android.app.PendingIntent.getActivity(PendingIntent.java:408)
           at com.google.android.gms.common.GoogleApiAvailabilityLight.getErrorResolutionPendingIntent(GoogleApiAvailabilityLight.java:3)
           at com.google.android.gms.common.GoogleApiAvailabilityLight.getErrorResolutionPendingIntent(GoogleApiAvailabilityLight.java:1)
           at com.google.android.gms.common.GoogleApiAvailability.getErrorResolutionPendingIntent(GoogleApiAvailability.java:1)
           at com.google.android.gms.common.GoogleApiAvailability.getErrorResolutionPendingIntent(GoogleApiAvailability.java:4)
           at com.google.android.gms.common.GoogleApiAvailability.zac(GoogleApiAvailability.java:1)
           at com.google.android.gms.common.api.internal.GoogleApiManager.zap(GoogleApiManager.java:1)
           at com.google.android.gms.common.api.internal.zabl.zac(zabl.java:21)
           at com.google.android.gms.common.api.internal.zabl.zam(zabl.java:7)
           at com.google.android.gms.common.api.internal.zabl.zad(zabl.java:8)
           at com.google.android.gms.common.api.internal.GoogleApiManager.handleMessage(GoogleApiManager.java:64)
           at android.os.Handler.dispatchMessage(Handler.java:102)
           at android.os.Looper.loopOnce(Looper.java:210)
           at android.os.Looper.loop(Looper.java:299)
           at android.os.HandlerThread.run(HandlerThread.java:67)

  • 相关阅读:
    数据库篇--八股文学习第十八天| MySQL和Redis的区别是什么;Redis有什么优缺点?为什么用Redis查询会比较快
    【java爬虫】使用selenium获取某宝联盟淘口令
    模板 主席树查询区间k小
    vivo鲁班RocketMQ平台的消息灰度方案
    VScode
    JAVA并发编程--3 理解volatile
    工作流自动化 低代码是关键
    react中的hooks
    java并发编程学习三——wait/notify与park/unpark
    sql实例-2
  • 原文地址:https://blog.csdn.net/u012482178/article/details/127897495