Android push to playstore targetsdk upgrade
Google has mandated targetsdk 31 and any api below 31 cannot be deployed in play store. In this blog I have mentioned how I set up my development environment in MacOS, for a quick upgrade in 30 mins time. I developed an application using react native. Initially my application was set up with targetSDK 30. When I submitted this to play store, here is what I received as error message:
“Your app currently targets API level 30 and must target at least API level 31 to ensure it is built on the latest APIs optimized for security and performance. Change your app’s target API level to at least 31
Here’s the guide from google: https://developer.android.com/google/play/requirements/target-sdk#pre12“
A typical react native application has build scripts using grade as a build tool. Android Studio is the best way to setup the environment, though command line tools along with SDKManager can also be used to setup the environment. There are changes to be made to our development environment, our build files.
Here is the modification to gradle files. The build tools version and ndk have been chosen based on the latest that works with this combination. The minSDK version, can be changed to the requirement. the compileSdk version can be setup for higher targets as a matter of good practice. (build.gradle)
buildscript {
ext {
buildToolsVersion = "30.0.3"
minSdkVersion = 21
compileSdkVersion = 31
targetSdkVersion = 31
ndkVersion = "25.1.8937393"
}
There are certain changes required to Android manifest also as we have to specify Intent behaviour as well.
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:exported="true"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|uiMode"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize">
The next set of changes are required to set up our environment in place. This SDK requires a Java upgrade as compared to earlier versions, we required Java 8, but here we require Java 11. So following changes are required
JAVA_HOME environment variable to point to java 11
The system path should pick up Java 11 SDK binaries. For MacOS I used home-brew to install openjdk11.
Taken form the link - https://formulae.brew.sh/formula/openjdk@11
https://github.com/Homebrew/discussions/discussions/2405
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk@11 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.
If you need to have openjdk@11 first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk@11 you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk@11/include"
The error below was resolved once Java version was changes
> Task :react-native-device-info:compileDebugJavaWithJavac FAILED
143 actionable tasks: 20 executed, 123 up-to-date
An exception has occurred in the compiler (1.8.0_311). Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) after checking the Bug Database (http://bugs.java.com) for duplicates. Include your program and the following diagnostic in your report. Thank you.
java.lang.AssertionError: annotationType(): unrecognized Attribute name MODULE (class com.sun.tools.javac.util.UnsharedNameTable$NameImpl)
If android manifest does not have declarations for intent, the error below might be seen.
error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
/Users/../AndroidManifest.xml Error:
Apps targeting Android 12 and higher are required to specify an explicit value for `android:exported` when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
All the above errors are seen when we do an:
npm start
npm run android
For one last time I got an out of memory error, but then this was a one off situation and got resolved automatically in the second run.
Execution failed for task ‘:app:packageDebug’.
> A failure occurred while executing com.android.build.gradle.tasks.PackageAndroidArtifact$IncrementalSplitterRunnable
> java.lang.OutOfMemoryError (no error message)
After this I was able to get my app to run. I hope this works for you too. Let me know if you have issues.
——————–
Links referred
https://stackoverflow.com/questions/68387270/android-studio-error-installed-build-tools-revision-31-0-0-is-corrupted
https://stackoverflow.com/questions/67412084/android-studio-error-manifest-merger-failed-apps-targeting-android-12
https://stackoverflow.com/questions/68344424/unrecognized-attribute-name-module-class-com-sun-tools-javac-util-sharednametab
https://developer.android.com/studio/command-line/sdkmanager
https://docs.oracle.com/en/java/javase/11/install/installation-jdk-macos.html#GUID-E8A251B6-D9A9-4276-ABC8-CC0DAD62EA33
https://formulae.brew.sh/formula/openjdk@11