将Android版本升级到31我在expo facebook:中遇到了一个新错误
Targeting S+ (version 31 and above) requires that one of FLAG_IMMUTABLE or FLAG_MUTABLE be specified when creating a PendingIntent.
我试图按照这个SO线程中指定的方式添加implementation 'androidx.work:work-runtime-ktx:2.7.0'
,但仍然收到错误。
除了降级目标安卓版本,我还有什么其他解决方案?
在android/app/build.gradle
:中添加这些行
dependencies {
.....
implementation "androidx.work:work-runtime:$work_version"
implementation "androidx.work:work-runtime-ktx:$work_version"
implementation 'com.facebook.android:facebook-android-sdk:12.3.0'
}
然后查找这些文件和行,并对其进行修改。
/node_modules/expo-notifications/android/src/main/java/expo/modules/notifications/service/NotificationsService.kt
线路(463(:PendingIntent.FLAG_UPDATE_CURRENT
修改为:PendingIntent.FLAG_IMMUTABLE
/node_modules/expo-task-manager/android/src/main/java/expo/modules/taskManager/TaskManagerUtils.java
线路(463(:PendingIntent.FLAG_UPDATE_CURRENT
修改为:PendingIntent.FLAG_IMMUTABLE
/node_modules/expo-location/android/src/main/java/expo/modules/location/services/LocationTaskService.java
线路(463(:PendingIntent.FLAG_UPDATE_CURRENT
修改为:PendingIntent.FLAG_IMMUTABLE
然后只需运行安装在模拟器或设备上的命令,即可100%工作