Migration of Android App API Level to 31 (Android 12) in React-Native

Sanjeev Kumar
VectoScalar
Published in
3 min readDec 13, 2023

I have recently upgraded my android application to API level to 31 (Android 12). I had deal with some issue while migrating the android app to API level to 31 (Android 12).

Android 12

Currently my project pointing to 30 (Android 11).

> How to migrate android app to API level 31 (Android 12):-

Step 1) Update targetSdkVersion and compileSdkVersion

In order to update the target level upgrade targetSdkVersion and compileSdkVersion in app/build.gradle

android {
compileSdkVersion 31

defaultConfig {
minSdkVersion 23
targetSdkVersion 31
applicationId "com.example.applicationname"
versionCode 1
versionName "1.0"
resConfigs "en"
multiDexEnabled true
}

Step2) Add android:exported in android/app/src/main/AndroidManifest.xml

Add android:exported="true/false" attribute in <activity>...</activity>, <service>…</service>, <receiver>…</receiver> and <provider>…</provider> like:

Example of android:exported = “true/false”

When to use true and false :-

Whether the broadcast receiver can receive messages from non-system sources outside its application — “true" if it can, and "false" if not. If "false", the only messages the broadcast receiver can receive are those sent by the system, components of the same application, or applications with the same user ID.

If unspecified, the default value depends on whether the broadcast receiver contains intent filters. If the receiver contains at least one intent filter, then the default value is “true". Otherwise, the default value is "false".

In Short:-

We need to set exported as true if any components need to be accessible from outside of our app (either by OS or other apps).

NOTE: If we don't add android:exported="true/false". App will not run

Step 3) Update<uses-permissions /> and Libraries:-

You must have to update some user permission in android/app/src/main/AndroidManifest.xml. Consider official documentation for permission upgradation.

Step 4) Sync and run the application:-

Sync your application in android studio and try to run the application. It will run successfully.

If you face problem to run the application due to some other libraries then try upgrade the library to latest version which supports the API level 31 (Android 12).

  • > Still having problem in running the application:-
  1. Open android/app/src/main/AndroidManifest.xml file in Android Studio.
  2. Open Merged Manifest which will show the error in errors section if there is any.
Merged Manifest

3. Find the errors in Merged Manifest and make the changes

Merged Manifest Error Example

4. Open AndroidManifest.xml from Merged Manifest of different libraries which are giving the android:exported error and add the android:exported="true/false" attribute.

5. Patch the library using below commands:

Supposing you have mylib.aar in your current directory, try the following:

$ unzip myLib.aar -d tempFolder # or other extracting tool
# Change whatever you need
$ jar cvf myNewLib.aar -C tempFolder/ .

6. Sync and run the application.

--

--