expo / expo-cli

Tools for creating, running, and deploying universal Expo and React Native apps
https://docs.expo.io/workflow/expo-cli/
2.61k stars 477 forks source link

There was a problem parsing the package, Android 12 after upgrading compileSdkVersion to 31 (Ejected Expo) #4335

Closed superjose closed 2 years ago

superjose commented 2 years ago

Summary

An ejected expo app without any other configuration besides changing the compileSdkVersion and targetSdkVersion to 31 will not let build the app.

Android 12 requires for <activity> <service> <provider> tags to be included with android:exported="true" or android:exported="false".

Changing the ones in AndroidManifest.xml does not seem to work.

I tried running it with

eas build --profile development --platform android

And after downloading the .apk I get hit by There was a problem parsing the package.

Funny thing is, that if I launch it within the preview, it will run correctly:

eas build --profile preview --platform android

Here's a StackOverflow link, and a forum link for further inquiries:

Environment

expo-env-info 1.0.3 environment info: System: OS: Windows 10 10.0.19044 Binaries: Node: 16.13.1 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.15 - C:\Program Files\nodejs\yarn.CMD npm: 8.1.2 - C:\Program Files\nodejs\npm.CMD IDEs: Android Studio: Version 2021.1.0.0 AI-211.7628.21.2111.8309675 npmPackages: expo: ~44.0.0 => 44.0.6 react: 17.0.1 => 17.0.1 react-dom: 17.0.1 => 17.0.1 react-native: 0.64.3 => 0.64.3 react-native-web: 0.17.1 => 0.17.1 Expo Workflow: bare

Please specify your device/emulator/simulator platform, model and version

Samsung Galaxy S10e - Android 12 - SM-G970U1

Error output

There was a problem parsing the package

Reproducible demo or steps to reproduce from a blank project

  1. From an ejected expo, change the compileSdkVersion and targetSdkVersion to 31.
  2. Compile the application via eas build --profile development --platform android
superjose commented 2 years ago

JESUS! I fixed it. There is a bug within Expo (Or at least I think there is).

Further inspecting the issue, I was able to finally pinpoint the problem and came up with a solution.

The problem lies within the merged AndroidManifest.xml version that resides within the .apk. I was able to inspect it using Android Studio (Create Empty Project and/or open an existing one -> Build -> Analyze APK). I found out there were several development packages from expo, mainly:

    <activity android:name="expo.modules.devlauncher.launcher.DevLauncherActivity" android:exported="true"/>
    <activity android:name="expo.modules.devlauncher.launcher.errors.DevLauncherErrorActivity" android:exported="true"/>

That did NOT include the exported feature.

I had to manually add them inside AndroidManifest.xml (I did this under /android/main/AndroidManifest.xml) to properly override them.

  <application android:name=".MainApplication" android:label="@string/app_name" android:icon="@mipmap/ic_launcher" android:roundIcon="@mipmap/ic_launcher_round" android:allowBackup="true" android:theme="@style/AppTheme" android:usesCleartextTraffic="true">
    <meta-data android:name="expo.modules.updates.ENABLED" android:value="true"/>
    <meta-data android:name="expo.modules.updates.EXPO_SDK_VERSION" android:value="44.0.0"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATES_CHECK_ON_LAUNCH" android:value="ALWAYS"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATES_LAUNCH_WAIT_MS" android:value="0"/>
    <meta-data android:name="expo.modules.updates.EXPO_UPDATE_URL" android:value="/>
    <activity android:name=".MainActivity" android:exported="true" android:label="@string/app_name" android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode" android:launchMode="singleTask" android:windowSoftInputMode="adjustResize" android:theme="@style/Theme.App.SplashScreen" android:screenOrientation="portrait">
      <intent-filter>
        <action android:name="android.intent.action.MAIN"/>
        <category android:name="android.intent.category.LAUNCHER"/>
      </intent-filter>
      <intent-filter>
        <! -- omitted just for reference -->
      </intent-filter>
    </activity>
<!-- These are the culprits -->
    <activity android:name="expo.modules.devlauncher.launcher.DevLauncherActivity" android:exported="true"/>
    <activity android:name="expo.modules.devlauncher.launcher.errors.DevLauncherErrorActivity" android:exported="true"/>
    <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false"/>
    <activity android:name="com.theartofdev.edmodo.cropper.CropImageActivity" android:exported="false"/>
    <activity android:name="io.intercom.android.sdk.helpcenter.collections.IntercomHelpCenterActivity" android:exported="false"/>
    <activity android:name="com.intercom.input.gallery.GalleryInputFullScreenActivity" android:exported="false"/>
    <activity android:name="com.intercom.input.gallery.GalleryLightBoxActivity" android:exported="false"/>
  </application>

I would then run

eas build --profile development --platform android

And FINALLY, the .apk would work without issues.

P.S: I didn't know how to properly add them under the debug. But these need to be fixed. The react-native library of intercom also had <actiivty> tags that were not exported. These had to be replaced as well.

Hopefully this will help someone.

EvanBacon commented 2 years ago

This seems like an issue with the packages in expo/expo. Great work tracking down the issue, I've sent it to the team so we can update our AndroidManifest.xml files.

kbrandwijk commented 2 years ago

An updated version of expo-dev-launcher has been released that includes these exports, and the changes have been backported to the version of expo-dev-client that is compatible with SDK 44, which is expo-dev-client@0.8.5. If you update your expo-dev-client dependency (either manually, or through expo doctor --fix-dependencies), you should be all set. Thank you for your analysis, and your patience!

superjose commented 2 years ago

Oooohhhh. Dang! I feel retarded. Thank you so much!!!