Keyworks Logo
Published on

Migrating from Android API level 30 to 31/32 or App Crashing After Updating Target Sdk Version to 31/32

Authors

The below solution will work for React Native or Core Android App.

React Native Hero

When uploading our release.aab file to Google Play Store we got an issue that said:

Your app currently targets API level 30 and must target at least API level 31/32 to ensure that it is built on the latest APIs optimised for security and performance. Change your app’s target API level to atleast 31.

App Bundles

Our React Native App version was 0.65.3

To fix the issue follow the below steps

Step 1: In the File, android > build.gradle, change compiledSdkVersion, targetSdkVersion and ndkVersion.

buildscript {
  ext {
    buildToolsVersion = "30.0.2"
    minSdkVersion = 21
    compileSdkVersion = 32
    targetSdkVersion = 32
    ndkVersion = "23.1.7779620"
    firebaseMessagingVersion = "+"
    googlePlayServicesVersion = "17.0.0"
    androidMapsUtilsVersion = "+"
  }
}

If you have subprojects section with compiledSdkVerion then change that version like the below:

subprojects {
  afterEvaluate {project ->
    if (project.hasProperty("android")) {
      android {
        compileSdkVersion 32
        buildToolsVersion = "30.0.2"
      }
    }
  }
}

Step 2: In the File, android > app > build.gradle, add the below line.

For Java:

dependencies {
  ...
  ...
  implementation 'androidx.work:work-runtime:2.7.1' // For Java
  ...
  ...
}

For Kotlin:

dependencies {
  ...
  ...
  implementation 'androidx.work:work-runtime-ktx:2.7.1' // For Kotlin
  ...
  ...
}

Step 3: In the File, android > app > src > main > AndroidManifest.xml, add android.exported= “true” in <activity>, <receiver>, <service> tags, i.e wherever you have <intent-filter> inside, like the below.

<activity
  android:name=".MainActivity"
  android:label="@string/app\_name"
  android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
  android:launchMode="singleTask"
  android:windowSoftInputMode="adjustResize"
  android:screenOrientation="portrait"
  android:exported="true"
  >
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
    <action android:name="android.intent.action.DOWNLOAD\_COMPLETE"/>
  </intent-filter>
</activity>

<receiver android:exported="true" android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
  <intent-filter>
    <action android:name="android.intent.action.BOOT\_COMPLETED" />
    <action android:name="android.intent.action.QUICKBOOT\_POWERON" />
    <action android:name="com.htc.intent.action.QUICKBOOT\_POWERON"/>
  </intent-filter>
</receiver>

<service
  android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationListenerService"
  android:exported="true" >
  <intent-filter>
    <action android:name="com.google.firebase.MESSAGING\_EVENT" />
  </intent-filter>
</service>

Hope this has helped you.

If you need any help building Android, iOS or Web apps, please get in touch with us at people@keyworks.cloud