I can not build android app aab format and api 30 in Quasar

Viewed 262

I don't have much experience. I'm trying to build an aab app for android api 30. Can I please see somewhere what version Gradle and Cordova must be in?

I am trying to use the Cordova version here: https://cordova.apache.org/announcements/2021/07/20/cordova-android-10.0.0.html?

I'm trying it on the default quasar project quasar 3.2.4 node 16.13.1 java version "17.0.1" 2021-10-19 LTS android studio 2020.3.1. patch 3 - sdk 14-31

But build still failed.

Can someone please direct me to a workable procedure please?

screenshot from console: https://ibb.co/hdxyHGf

1 Answers

I struggled with this my self for couple of days. I will try to answer it as detailed as I can. Maybe you will find some problems that are dependent on your application, but at least you will have something to work with.

As I can understand you have a quasar application that is using cordova and you want to build Android App Bundle (.aab) file to publish it to the Google Play Store, because now play store accepts only .aab files.

First quasar as a framework has nothing to do with this. Quasar framework just builds your web app and the build output is stored in src-cordova/www folder. It doesn't matter if you are using Quasar v1 or v2.

Cordova is a framework that will create the whole project structure (android / iOS) a.k.a cordova platforms and run the specific build tools to build the poject using command lines (gradle cli / xcode cli).

To build .aab file for Google Play Store you will also need to target Android API level 30. Cordova version that supports android API level 30 is version 10. I am using cordova-android-v10.0.0.

To install cordova-android-v10, first you will need to remove the android platform you have now i.e. src-cordova/platforms/android folder. After that navigate in src-cordova folder. And install cordova android platform v10 with following command cordova platform add android@10.0.0.

Now you will need to build the android project using gradle. Cordova android v10 needs gradle v7.1.1.

To find more about cordova android v10.0.0 and its compatible versions with other tools like gradle you can see the following link: https://cordova.apache.org/announcements/2021/07/20/cordova-android-10.0.0.html

You can download gradle v7.1.1 from the following link: https://gradle.org/releases/. I recommend downloading the complete package i.e. gradle-v7.1.1-all.zip.

Unpack the zip file in C:/Gradle/gradle-v7.1.1 if you are using windows. If you are using macOS I think you should extract it in /Library/Gradle/gradle-v7.1.1. After that you will need to add GRADLE_HOME environment variable (GRADLE_HOME=C:/Gradle/gradle-v7.1.1) and add gradle bin directory to the PATH i.e. PATH=...,%GRADLE_HOME%\bin.

Check if you have installed gradle successfully with gradle -v command in terminal to see the gradle version

Now you should be able to build the android cordova project with gradle. Go to src-cordova/aplatforms/android and execute gradle build. If everything is ok you can go to your root project folder end execute npm run build:android.

If everything passes you will see app-release.aab file in dist/cordova/android output folder.

IMPORTANT: There are couple of caveats that I want to point them out which will lead to unsuccessful build.

  1. First is the cordova android API level compatibility. Cordova v10.0.0 supports from API level 22 to API level 30. You will need to add the following xml in your cordova config.xml:
<platform name="android">
   <!-- other settings -->
  
   <preference name="android-minSdkVersion" value="22" />
   <preference name="android-targetSdkVersion" value="30" />
   
   <!-- other settings -->
</platform>

Following link gives you the supported API levels for android cordova and its versions: https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support

If you do not add minSdkVersion 22 you will have problems with MultiDex support. This is due to that API level 22 (Android 5.1) by default enables multi DEX files applications. If you min target below 22 you will have exceptions like:

java.lang.RuntimeException: Unable to instantiate application android.support.multidex.MultiDexApplication

There is a workaround for this but I will not get into it here. You can read more on this link: https://developer.android.com/studio/build/multidex#mdex-pre-l

  1. Second you need to generate your keystore file if you have not done that already and configure the build.json file. In build.json file you can define output packages for release and debug. In my project I have set them: debug to output apk and release to output aab file and also you can define the keystore file path.

You can find more about build.json on the following link: https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#using-buildjson

  1. Third thing is subjective, but I want to point it here because I think it might help. The 3rd thing are plugins. Many plugins are old (more that 3 years) and might not work with this new setup due to errors when trying to build them with gradle build command. I used qrscanner plugin in my app (cordova-plugin-qrscanner) which failed to build because of Androidx and support libraries. You can find more about this issue https://github.com/bitpay/cordova-plugin-qrscanner/issues/360. At the end I used new androidx qrscanner plugins.
# inside src-cordova folder
cordova plugin add cordova-plugin-qrscanner-androidx --save
cordova plugin add cordova-plugin-androidx-adapter --save

If you have troubles like this remove src-cordova/plugins folder and do cordova build android in src-cordova folder to reinstall all plugins. If error pops out try to install replacement plugin for the one that is failing.

Sorry for the long answer but this kind of problems are hard to explain, especially when using framework that uses framework, that uses framework....

Related