Android 14, target SDK version 34

I’m working on submitting a new app to the Play store but getting this message:

Your app currently targets API level 33 and must target at least API level 34 to ensure it is built on the latest APIs optimized for security and performance.

Clicking Learn More takes me here: Learn More

That link says,

When you upload an APK, it must meet Google Play’s target API level requirements.

Starting August 31 2024:

New apps and app updates must target Android 14 (API level 34) or higher to be submitted to Google Play; except for Wear OS and Android TV apps, which must target Android 13 (API level 33) or higher

Today is July 4th, 2024, so I’m not sure why am I getting this message, but is there a way to target sdk version 34?

1 Like

@flint-mike

If you are using https://www.pwabuilder.com like me, there is a workaround at [PWA Builder]: Support for Android SDK 34 · Issue #4766 · pwa-builder/PWABuilder · GitHub

App.setPreference('android-targetSdkVersion', '34');

This is the way in Meteor-Cordova to achieve this I think, within the mobile-config.js file. This should be enough to see your android project in production to use the required version.

Otherwise, when building your android app for production, find the build.gradle file within the android project generated that contains targetSdkVersion and modify to targetSdkVersion 34. Rebuild your app, verify it works and re-upload in the store.

Has anybody tried creating Meteor Android app for sdkversion 34. For me it is giving error as it requires a higher gradle version and higher sdk version.
If anybody has successfully done it, can somebody share the mobile-config used please, also the gradle and sdk version

Looks like I was able to do a generation Couple of things I required

  1. update openjdk to 17.0.2
  2. update Android SDK to have 34/35
  3. update Android commandline tools
  4. add after_prepare hook to solve the duplicate permission issue problem
App.setPreference('android-targetSdkVersion', '34');
App.setPreference('android-minSdkVersion', '30');
App.setPreference("GradlePluginKotlinEnabled", true);
App.setPreference("GradlePluginKotlinVersion", "1.7.10");
App.addResourceFile ('hooks/after.js', 'hooks/after.js', 'android');
App.appendToConfig(`
  </platform>
  <platform name="android">
    <hook type="before_compile" src="../../local/cordova-build/platforms/android/hooks/after.js" />
     </platform>
  `);
  1. Override gradle by passing
export CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL=https://services.gradle.org/distributions/gradle-8.9-all.ziptype or paste code here
1 Like

Hi All ,

I was able to compile but the app refused to start …it went into a loop complaining ‘cordova not defined at package.js:1:1’

I see that there was similar error in older meteor. But I am trying to figure out what I am missing. Any pointers.

Also it looks like the ‘build’ path and ‘run’ path take different routes. For some reason whenever I do ‘run’ it does not take into account the after_prepare hook which is to remove the duplicates in Android Manifest, but if I ‘build’ and then do a ‘run’ it seems to work.

I just tested on a new app in Meteor 3.0 my case, however it should not work the same way in a 2.0 app. The steps you posted above are the requirements for any newer android sdk, along what I commented here.

Why did you have to add these? At first sight I feel one </platform> is wrong I believe. But I don’t have all this config on my app and I was able to.

App.setPreference("GradlePluginKotlinEnabled", true);
App.setPreference("GradlePluginKotlinVersion", "1.7.10");
App.addResourceFile ('hooks/after.js', 'hooks/after.js', 'android');
App.appendToConfig(`
  </platform>
  <platform name="android">
    <hook type="before_compile" src="../../local/cordova-build/platforms/android/hooks/after.js" />
     </platform>
  `);

I understand that your app could have specific requirements that might trigger other problems while upgrade, like specific cordova plugin usage or configuration. For that I would ask you to prepare a small repository with the setup that you get reproduced the problem of building but not starting your Meteor app. This way I can support you further by checking it out.

Platform step was needed as I use the camera plugin and file transfer plugin and it seems both try to add WRITE_EXTERNAL permission and it was giving merge conflict. So I had to to create a after_prepare hook ( it should not be before_compile as shown above). I found now the gardle version and android gradle plugin version can also be done using App.preference, kotlin plugin pinning was needed as it was complaining that I was using a lower version of kotlin.

my mobile config is now something like this

// Set PhoneGap/Cordova preferences
App.setPreference('android-targetSdkVersion', '34');
App.setPreference('android-minSdkVersion', '30');
App.setPreference("GradlePluginGoogleServicesEnabled", true);
App.setPreference("GradlePluginKotlinEnabled", true);
App.setPreference("GradlePluginKotlinVersion", "1.7.10");
App.setPreference("GradleVersion", "8.9");
App.setPreference("AndroidGradlePluginVersion", "8.5.0");

App.setPreference('BackgroundColor', '0xffffffff');
App.setPreference('HideKeyboardFormAccessoryBar', true);
App.setPreference("AndroidLaunchMode", "singleInstance");
App.setPreference("BackupWebStorage", "local");
App.setPreference('AutoHideSplashScreen', 'true');
App.setPreference('SplashScreenDelay', '10000'); //10 seconds delay
App.setPreference('ShowSplashScreenSpinner', true); 
App.accessRule('data:*', {type: 'navigation'});
App.accessRule('http://*', {type: 'navigation'});
App.accessRule('https://*', {type: 'navigation'});
App.accessRule('*', {type: 'navigation'});
App.accessRule('ws://*', {type: 'navigation'});
App.accessRule('wss://*', {type: 'navigation'});
App.accessRule("*");
App.accessRule("blob:*");

 
 
App.addResourceFile ('google-services.json', 'app/google-services.json', 'android');
App.addResourceFile ('GoogleService-Info.plist', 'app/GoogleService-Info.plist', 'ios');
App.addResourceFile ('hooks/after.js', 'hooks/after.js', 'android');
App.appendToConfig(
    
  </platform>
  <platform name="android">
   
    <hook type="before_compile" src="../../local/cordova-build/platforms/android/hooks/after.js" />
     </platform>
  
  `);
 

corodova plugins that I use

cordova-plugin-android-permissions@1.1.5
cordova-plugin-appinfo@2.1.2
cordova-plugin-calendar@5.1.6
cordova-plugin-camera@6.0.0
cordova-plugin-device@3.0.0
cordova-plugin-file@8.1.0
cordova-plugin-file-transfer@https://github.com/apache/cordova-plugin-file-transfer.git#5c29f9a0e1b0cddb9c0cdf7b79139ae8e523e5c1
cordova-plugin-inappbrowser@5.0.0
cordova-plugin-local-notification@https://github.com/fquirin/cordova-plugin-local-notifications.git#8a67e65f2a24b0287d58265aa9894956fe646857
cordova-plugin-media-capture@5.0.0
cordova-plugin-meteor-webapp@2.0.4
cordova-plugin-network-information@3.0.0



Ok, which is also your specific Meteor version?

Could you get a repository with these configured and with your current error message showing?

Sure …let me create a barebone repository.

I am on meteor 2.16
But I notice it also shows this error is it possible that is causing the issue

npm WARN notsup Unsupported engine for cordova-android@12.0.1: wanted: {"node":">=16.13.0"} (current: {"node":"14.21.4","npm":"6.14.18"})
npm WARN notsup Not compatible with your version of node/npm: cordova-android@12.0.1
npm WARN notsup Unsupported engine for cordova-common@5.0.0: wanted: {"node":">=16.0.0"} (current: {"node":"14.21.4","npm":"6.14.18"})
npm WARN notsup Not compatible with your version of node/npm: cordova-common@5.0.0

Wanted to update if I use meteor run android …this was not running (that will make the changes more difficult). But when I build using meteor build and use aab file to install, the app was coming up. I need to check throughly if it works.

npm WARN notsup Unsupported engine for cordova-android@12.0.1: wanted: {"node":">=16.13.0"} (current: {"node":"14.21.4","npm":"6.14.18"})
npm WARN notsup Not compatible with your version of node/npm: cordova-android@12.0.1
npm WARN notsup Unsupported engine for cordova-common@5.0.0: wanted: {"node":">=16.0.0"} (current: {"node":"14.21.4","npm":"6.14.18"})
npm WARN notsup Not compatible with your version of node/npm: cordova-common@5.0.0

This doesn’t look well, eventhough it is a warning. I wonder if that could be related with the problem.

In this commit, cordova-android was upgraded from 10.x to version 12.0.0 and later to 12.0.1.

cordova-android 12 is restricted to Node 16.x, while Meteor 2.x is limited to Node 14.x.

However, eventhough it’s restricted, it might still be compatible as cordova-android hasn’t had any incompatible updates using new Node API. I am about to double check it with the author of this upgrade.

This happened almost a year ago starting from Meteor 2.14, and Cordova has worked well since then in all my tests, and no failure report anytime.

I will do the sdk upgrade as part of a Meteor 2.x app. Since Meteor 3.x uses the latest Node, it could have avoided the issue when I tested initially. I believe having a reproducible repository is still the best way to assist you.

Edit: Just tested an app in 2.16 and can be upgraded to Android SDK 34.

@nachocodoner I found the issue. I had kept the hooks folder inside meteor folder and it was causing issue, once I moved it out of meteor folder it started working.

I was able to ‘run’ and ‘build’ cordova app when I removed the plugins that needed WRITE_EXTERNAL permission (except for one …I think it is the camera) removed the hooks as well. I also had to downgrade gradle and AGP (notsure if it was needed).

But as soon as I added another plugin with WRITE_EXTERNAL permission, I had to add the hook back – here the ‘run’ fails complaining Android Manifest has two entries for WRITE_EXTERNAL but the ‘build’ works. On closer analysis it looks like after_prepare steps is executed twice first time it executes the hook script, but second time it does not and build errors out.
On the build process however it builds and works as well.

1 Like

It seems that even though you can build Android SDK 34 apps in Meteor 2.16, the Play Store rejects them. I created a new topic for this problem: