expo: 🤖 [Android v12] SDK 45 Crash with PendingIntent (Tested on EAS BUILD)(With Workaround Patch ✅)

Summary

🥳 Workaround

📝 Original issue

✅ No issue on Android 11 or below

When I use my Android 11 “One plus” phone it works.

❌ Starting Android 12, build succeed but app startup crashes

With a Google Pixel 5 Android 12, I get the following error:

FATAL EXCEPTION: pool-3-thread-1
Process: com.power.stride.staging, PID: 31865
java.lang.IllegalArgumentException: com.power.stride.staging: 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.getBroadcastAsUser(PendingIntent.java:645)
	at android.app.PendingIntent.getBroadcast(PendingIntent.java:632)
	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:1167)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
	at java.lang.Thread.run(Thread.java:920)

🕵🏻‍♂️ Observations

  • It crashes without booting the JavaScript, as the dev-client screen is not shown.

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

45

Environment

ENGINE : HERMES
  expo-env-info 1.0.3 environment info:
    System:
      OS: macOS 12.0.1
      Shell: 5.8 - /bin/zsh
    Binaries:
      Node: 16.14.2 - ~/.volta/tools/image/node/16.14.2/bin/node
      Yarn: 1.22.18 - ~/.volta/tools/image/yarn/1.22.18/bin/yarn
      npm: 8.5.0 - ~/.volta/tools/image/node/16.14.2/bin/npm
      Watchman: 2022.03.21.00 - /usr/local/bin/watchman
    Managers:
      CocoaPods: 1.11.3 - /usr/local/bin/pod
    SDKs:
      iOS SDK:
        Platforms: DriverKit 21.2, iOS 15.2, macOS 12.1, tvOS 15.2, watchOS 8.3
      Android SDK:
        Android NDK: 24.0.8215888
    IDEs:
      Android Studio: 2021.1 AI-211.7628.21.2111.8309675
      Xcode: 13.2.1/13C100 - /usr/bin/xcodebuild
    npmPackages:
      expo: ^45.0.0 => 45.0.2 
      react: 17.0.2 => 17.0.2 
      react-dom: 17.0.2 => 17.0.2 
      react-native: 0.68.1 => 0.68.1 
      react-native-web: 0.17.7 => 0.17.7 
    Expo Workflow: managed
{
  "name": "my_project",
  "version": "1.0.0",
  "scripts": {
    "start": "expo start --dev-client",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "build:tailwind": "tailwindcss --input input.css --output tailwind.css --no-autoprefixer && tailwind-rn",
    "dev:tailwind": "concurrently \"tailwindcss --input input.css --output tailwind.css --no-autoprefixer --watch\" \"tailwind-rn --watch\""
  },
  "dependencies": {
    "@formatjs/intl-datetimeformat": "^5.0.1",
    "@formatjs/intl-getcanonicallocales": "^1.9.2",
    "@formatjs/intl-locale": "^2.4.47",
    "@formatjs/intl-numberformat": "^7.4.3",
    "@formatjs/intl-pluralrules": "^4.3.3",
    "@gorhom/bottom-sheet": "^4",
    "@hookform/resolvers": "^2.8.8",
    "@react-native-async-storage/async-storage": "~1.17.3",
    "@react-navigation/native": "^6.0.10",
    "@react-navigation/native-stack": "^6.6.2",
    "@stadtkatalog/openinghours": "^3.2.0",
    "@stripe/stripe-react-native": "^0.9.0",
    "@xstate/react": "^3.0.0",
    "axios": "^0.27.1",
    "expo": "^45.0.0",
    "expo-apple-authentication": "~4.2.1",
    "expo-auth-session": "~3.6.0",
    "expo-barcode-scanner": "~11.3.0",
    "expo-camera": "~12.2.0",
    "expo-dev-client": "~0.9.5",
    "expo-font": "~10.1.0",
    "expo-haptics": "~11.2.0",
    "expo-linking": "~3.1.0",
    "expo-localization": "~13.0.0",
    "expo-location": "~14.2.2",
    "expo-notifications": "~0.15.2",
    "expo-random": "~12.2.0",
    "expo-splash-screen": "~0.15.1",
    "expo-status-bar": "~1.3.0",
    "expo-store-review": "~5.2.0",
    "expo-updates": "~0.13.1",
    "expo-web-browser": "~10.2.0",
    "geolib": "^3.3.3",
    "i18next": "^21.6.16",
    "lodash-es": "^4.17.21",
    "lottie-react-native": "5.0.1",
    "luxon": "^2.3.2",
    "react": "17.0.2",
    "react-countdown": "^2.3.2",
    "react-dom": "17.0.2",
    "react-hook-form": "^7.30.0",
    "react-i18next": "^11.16.7",
    "react-native": "0.68.2",
    "react-native-clusterer": "focux/react-native-clusterer#67d4c3e797c37f9ca388f33d7fa84337aad954fb",
    "react-native-confirmation-code-field": "^7.3.0",
    "react-native-fast-image": "^8.5.11",
    "react-native-gesture-handler": "~2.2.1",
    "react-native-maps": "0.30.1",
    "react-native-pager-view": "5.4.15",
    "react-native-reanimated": "~2.8.0",
    "react-native-safe-area-context": "4.2.4",
    "react-native-screens": "~3.11.1",
    "react-native-shadow-2": "^6.0.4",
    "react-native-snap-carousel": "4.0.0-beta.6",
    "react-native-svg": "12.3.0",
    "react-native-web": "0.17.7",
    "react-use": "^17.3.2",
    "recoil": "^0.7.2",
    "swr": "^1.3.0",
    "tailwind-rn": "^4.2.0",
    "xstate": "^4.31.0",
    "yup": "^0.32.11",
    "yup-password": "^0.2.2"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/lodash-es": "^4.17.6",
    "@types/luxon": "^2.3.1",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.67.6",
    "@types/react-native-snap-carousel": "^3.8.5",
    "babel-plugin-module-resolver": "^4.1.0",
    "concurrently": "^7.1.0",
    "postcss": "^8.4.12",
    "prettier": "^2.6.2",
    "prettier-plugin-tailwindcss": "^0.1.10",
    "tailwindcss": "^3.0.24",
    "typescript": "~4.3.5"
  },
  "resolutions": {
    "@types/react": "~17.0.21"
  },
  "private": true,
  "volta": {
    "node": "16.14.2",
    "yarn": "1.22.18"
  }
}

image

Reproducible demo

Not sure how, I’ve no idea what’s causing that 😢

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 33 (8 by maintainers)

Most upvoted comments

Take care of rm -rf node_modules before doing the following manipulation.


I’m totally not an expert on working with Expo Config Plugins and the API is pretty opaque and not documented about withAppBuildGradle function.

However, I managed to make the following plugin for Android

Managed workflow build with EAS

You need a custom plugin and then add it to expo.plugins in your app.json

// test-fix.js
const { withAppBuildGradle } = require("@expo/config-plugins");

module.exports = function withAndroidXWorkRuntimeFix(config) {
  // Return the modified config.
  return withAppBuildGradle(config, (c) => {
    c.modResults.contents = c.modResults.contents.replace(
      /dependencies\s?{/,
      `dependencies {
      // FIX FOR EXPO PendingIntent https://github.com/expo/expo/issues/17432
      def work_version = "2.7.0"

      // (Java only)
      implementation "androidx.work:work-runtime:$work_version"
      // Kotlin + coroutines
      implementation "androidx.work:work-runtime-ktx:$work_version"`,
    );

    return c;
  });
};



// app.json (or equivalent)
{
  // … other configs
  plugins: [
    "./test-fix",
    // …Others plugins
  ]
}

Bare workflow

For Bare workflow add to app/build.gradle in dependencies

// FIX FOR EXPO PendingIntent https://github.com/expo/expo/issues/17432
def work_version = "2.7.0"
// (Java only)
implementation "androidx.work:work-runtime:$work_version"
// Kotlin + coroutines
implementation "androidx.work:work-runtime-ktx:$work_version"`,

We definitely need some documentation on this kind of function like createRunOncePlugin and mergeContents

After uninstalling existing version in Google Play(not updating), it works with your plugin fix 😃

But why? Did you remember:

https://docs.expo.dev/build-reference/migrating/#custom--main--entry-point-in

I don’t have any custom main entrypoint. I don’t think the issue is related to that…

Where do you add: implementation ‘androidx.work:work-runtime:2.7.0-alpha05’ in a managed Expo app ?

The core team of @brentvatne should implement the fix I guess if this is verified being the issue, in the meantime I’ll make a custom config plugin just like this one and test if it works, I’ll edit my comment when I get more insights : https://github.com/expo/config-plugins/blob/main/packages/android-jsc-intl/src/withAndroidJscIntl.ts