cordova-android: not working and keep asking for 29
Bug Report
Problem
It seems setting targetSdkVersion to 30 not working, it sounds like the same issue as the one closed #846 , I set <preference name="android-targetSdkVersion" value="30" />
in config.xml and I installed only platform-30
it keeps asking me to install version 29:
#13 394.1 Checking the license for package Android SDK Platform 29 in /opt/android-sdk-linux/licenses
#13 394.1 License for package Android SDK Platform 29 accepted.
#13 394.1 Preparing "Install Android SDK Platform 29 (revision: 5)".
#13 394.1 Warning: Failed to read or create install properties file.
#13 394.2
#13 394.2 FAILURE: Build failed with an exception.
#13 394.2
#13 394.2 * What went wrong:
#13 394.2 Could not determine the dependencies of task ':app:bundleReleaseResources'.
#13 394.2 > Failed to install the following SDK components:
#13 394.2 platforms;android-29 Android SDK Platform 29
#13 394.2 Install the missing components using the SDK manager in Android Studio.
There is no other information to put but it is the same issue as #846 nothing new.
Version information
What are relevant versions you are using? Latest everything, Cordova 10 and cordova-android 9.0.0
Checklist
- I searched for existing GitHub issues
- I updated all Cordova tooling to most recent version
- I included all the necessary information above
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 24 (5 by maintainers)
Commits related to this issue
- A silly code to workaround issue https://github.com/apache/cordova-android/issues/1178 — committed to capellasolutions/ionic-cordova-docker by almothafar 3 years ago
- Revert "A silly code to workaround issue https://github.com/apache/cordova-android/issues/1178" This reverts commit 626ff047863bfc1b1b15ee0cc025f010d98e0ce8. — committed to capellasolutions/ionic-cordova-docker by almothafar 3 years ago
you can try
Adding to the importance of resolving this issue is very soon Google store won’t accept submission of sdk level less than 30.
I was able finally to build it using
before_build
hook https://github.com/capellasolutions/ionic-cordova-docker/tree/develop/example-app/scriptsUntil this issue is resolved here, maybe in cordova-android 10 or 9.something
This is not related to this issue. Targeting API 30 still works via
android-targetSdkVersion
preference, so that’s not a problem. Additionally we will bump our default target SDKs on our major releases to match the requirement of Google Play store.The issue described in this ticket is Cordova will still attempt to the default platform SDK (currently API 29) even when targetSdkVersion is set to a different API level. So the current workaround is to simply have both platform 29 & 30 installed.
I’ve had a chance to do some digging on the cause and I’ve found 3 things that Cordova tooling must do:
(1) Ensure compileSdkVersion matches targetSdkVersion
compileSdkVersion
is the SDK that the application is compiled against, while thetargetSdkVersion
is an assertion that you’ve tested your application at the target SDK level for compatibility. If the platform API level is higher of the target, then the platform will enable backwards-compatibility behaviours.There isn’t any real reason to have a
compileSdkVersion
set that is different than thetargetSdkVersion
and doing so can cause an unstable application. Currently, theandroid-targetSdkVersion
overrides but doesn’t modifycompileSdkVersion
creating this possibility. Cordova should forcecompileSdkVersion
andtargetSdkVersion
to be equal.There is currently no
config.xml
preference to set thecompileSdkVersion
, and the lack of this feature should remain. There is a cdvCompileSdkVersion cordova gradle flag, which I think should become deprecated and potentially removed incordova-android@10
and replaced with acdvTargetSdkVersion
flag to match theconfig.xml
’sandroid-targetSdkVersion
preference.(2) Ensure android/project.properties has the correct target
Currently, Cordova does not modify the
target
attribute inside/platforms/android/project.properties
and it remains set toandroid-29
which will cause the Android Gradle Plugin (AGP) to download Platform 29.(3) Ensure android/CordovaLib/project.properties has the correct target
Currently, Cordova does not modify the
target
attribute inside/platforms/android/CordovaLib/project.properties
and it remains set toandroid-29
which will cause AGP to download Platform 29.Additionally, a warning should be printed for when the SDK is overridden and uses a value other than the Cordova default target SDK, similar to the min sdk override warning. Using an alternate SDK level is not really a supported feature, so this preference is more-or-less “use at your own risk” (and really should be documented as such).
All 3 actions must be done in order for the AGP to not download API 29.
I cannot give any timeline for when I’ll personally be able to do the above, but I’ll support any PR that does what is described above.
ICYMI: You can workaround this issue by installing both Platform 29 & 30. You can still build APKs targeted against API 30.
We are in an odd state right now because the current cordova CLI will auto-add the whitelist plugin when you create a new cordova project, which is deprecated and incompatible with the latest major version of cordova-android. The next major cordova CLI will solve this problem.
remove whitelist plugin using
cordova plugin rm cordova-plugin-whitelist
it is mentioned on that plugin page https://github.com/apache/cordova-plugin-whitelistAs noted in my notes above but the workaround will still build a target 30 SDK, which will still enable API changes that API 30 will introduce.
If using API 30 platform SDK is a requirement, a temporary full workaround is to modify the following:
/platforms/android/project.properties:
/platforms/android/CordovaLib/project.properties:
Currently the compile SDK version is can be overrided using the
cdvCompileSdkVersion
flag e.g:Lastly, of course you still need the
android-targetSdkVersion
preference in yourconfig.xml
file:Cordova may overwrite changes to files inside
/platforms/
so I’d advise crafting abefore_build
hook.I think this might be a cosmetic issue. I was using this the other day and despite the cordova build output stating using android-29, the final output of both an apk or app bundle still produced api 30 package.
Are you able to confirm you see the same behavior?