cordova-android icon indicating copy to clipboard operation
cordova-android copied to clipboard

Generate .apk instead of .aab file (Ionic Project)

Open Morgs007 opened this issue 3 years ago • 6 comments

Bug Report

I am trying to generate a .apk file but whatever command I try I keep getting a .aab file. What is the new command to use in order for one to successfully generate a .apk file?

Problem

I used the following commands to no success:

  • ionic cordova build android --release --packageType=apk
  • ionic cordova build android --prod --release -- --packageType=apk
  • cordova build android --release -- --packageType=apk
  • cordova build android --prod --release -- -- --packageType=apk

What is expected to happen?

Produce a .apk file

What does actually happen?

All the commands produces a .aab file

Command or Code

ionic cordova build android --release --packageType=apk ionic cordova build android --prod --release -- --packageType=apk cordova build android --release -- --packageType=apk cordova build android --prod --release -- -- --packageType=apk

Version information

Cordova Platforms : android 12.0.1 Cordova CLI : 12.0.0 ([email protected]) Ionic CLI : 6.20.8 @angular-devkit/build-angular : 15.2.7 @angular-devkit/schematics : 15.2.7 @angular/cli : 15.2.7 @ionic/angular-toolkit : 9.0.0 native-run : 1.7.2 Android SDK Tools : 26.1.1 NodeJS : v18.16.1 npm : 9.6.0 OS : Windows 10

Morgs007 avatar Oct 04 '23 22:10 Morgs007

The Cordova CLI uses cordova build android --release -- --packageType=apk.

I can't speak for third-party CLI's like ionic and all information below is assuming pure cordova environment.

On windows, if you're using Command Prompt or Powershell, I think the intermediate -- needs to be in quotations: cordova build android --release "--" --packageType=apk, for the shell to properly pass-through the arguments

Also note that I believe the build output will print out all apks/bundles thats in your build output directory. So it will include text stating that it "built" a file even if that file wasn't actually built from your last command, but purely because the file already existed in the build/outputs directories.

In otherwords, you should see the APK in platforms/android/app/build/outputs/apk/release/ and you should see that printout, but you may also (incorrectly) see printouts about it building aab files as well. This might be a source of confusion.

The command hasn't changed since it was first introduced in v10 and building both AABs and APKs is part of my workflow so I'm pretty confident it works (On Linux/Mac machines anyway). Let me know if this helps.

breautek avatar Oct 04 '23 22:10 breautek

The Cordova CLI uses cordova build android --release -- --packageType=apk.

I can't speak for third-party CLI's like ionic and all information below is assuming pure cordova environment.

On windows, if you're using Command Prompt or Powershell, I think the intermediate -- needs to be in quotations: cordova build android --release "--" --packageType=apk, for the shell to properly pass-through the arguments

Also note that I believe the build output will print out all apks/bundles thats in your build output directory. So it will include text stating that it "built" a file even if that file wasn't actually built from your last command, but purely because the file already existed in the build/outputs directories.

In otherwords, you should see the APK in platforms/android/app/build/outputs/apk/release/ and you should see that printout, but you may also (incorrectly) see printouts about it building aab files as well. This might be a source of confusion.

The command hasn't changed since it was first introduced in v10 and building both AABs and APKs is part of my workflow so I'm pretty confident it works (On Linux/Mac machines anyway). Let me know if this helps.

See below screenshot of what I am talking about: image

Morgs007 avatar Oct 05 '23 12:10 Morgs007

Can you try cordova build android --release "--" --packageType=apk ?

I don't use windows so I kinda forget but I'm pretty sure windows requires that separating -- to be enclosed quotations like above.

breautek avatar Oct 05 '23 12:10 breautek

@breautek that worked, thanks a lot. I see a lot of people are complaining about the same issue on stackoverflow so I will go and answer using your recommendation

Morgs007 avatar Oct 05 '23 13:10 Morgs007

I've created a ticket on the docs repo (https://github.com/apache/cordova-docs/issues/1336) as well, so that we can improve our docs on this caveat.

I'm closing this issue because it's not really a bug.

breautek avatar Oct 05 '23 13:10 breautek

Thanks for your help

Morgs007 avatar Oct 05 '23 13:10 Morgs007