2021年11月27日 星期六

Android targetSdkVersion up to 31(Android 12)

今天將 side project 升上 android 12 後,在模擬器上連裝都不能裝,原來無法無痛升級QQ

首先遇到這個 INSTALL_PARSE_FAILED_MANIFEST_MALFORME ,官網說如果是四大組件有用到 intent-filter 就要聲明 exported 的值。

Safer component exporting

If your app targets Android 12 or higher and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the android:exported attribute for these app components.

第二個遇到

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.
解法就是這個,添加依賴

implementation 'androidx.work:work-runtime-ktx:2.7.1'

就解了。


若有原本有 play service ads,將其升級到

implementation 'com.google.android.gms:play-services-ads:20.5.0'

就不需要添加 work 依賴了

沒有留言:

張貼留言