Ragesh Pikalmunde
Ragesh Pikalmunde

Reputation: 1403

unable to generating an Android App Bundle from your Ionic app (without Android Studio)

This is mostly Duplicate of build fail for android but no answer is yet available and my scenario is little different so putting it again.

In my my case I am able to build apk properly and I want to create a app bundle after successful of command

ionic cordova build android --prod --release by running this cmd I am able to generate the apk.

After that I am going to /platform/android and running ./gradlew bundle and here I am getting this error

The Task.leftShift(Closure) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use Task.doLast(Action) instead.


FAILURE: Build failed with an exception.

* What went wrong:
Task 'bundle' is ambiguous in root project 'android'. Candidates are: 'bundleAppClassesDebug', 'bundleAppClassesDebugAndroidTest', 'bundleAppClassesDebugUnitTest', 'bundleAppClassesRelease', 'bundleAppClassesReleaseUnitTest', 'bundleDebug', 'bundleRelease'

How to fix it?

Upvotes: 4

Views: 8957

Answers (7)

Yogita Jakhade
Yogita Jakhade

Reputation: 11

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

This is the right answer

Upvotes: 1

Irfan Ashraf
Irfan Ashraf

Reputation: 2460

This works for me, keys are already generated.

cordova build android --prod --release -- --packageType=bundle

Upvotes: 0

jtrk
jtrk

Reputation: 31

My requirements were different to the original question but this still might be useful for some. After upgrading Cordova the build command below was producing an .aab file where prior to update it was producing an .apk. Our build pipeline was set up for signing an APK file so I wanted to make APK the default.

$ ionic cordova build android --prod --release

When I upgraded from cordova 8.x.x to 10.x.x This command defaulted to an .aap file being produced

adding the -- --packageType=apk did not work.

I had to create a build.json in the root cordova app directory with the following:

{
    "android": {
        "debug": {
            "packageType": "apk"
        },
        "release": {
            "packageType": "apk"
        }
    }
}

This worked perfect.

Upvotes: 3

adamdport
adamdport

Reputation: 12603

For those that end up here and find that the --packageType=bundle flag doesn't seem to work, pay close attention to the note here:

Note: You should use double -- to indicate that these are platform-specific arguments, for example:

cordova run android --release -- --keystore=../my-release-key.keystore --storePassword=password --alias=alias_name --password=password --packageType=bundle.

Notice the empty -- after --release. The below assumes you already have your keystore and password configuration in build.json:

cordova build android --packageType=bundle // flag is silently ignored, generates apk
cordova build android -- --packageType=bundle // flag works, generates aab

Upvotes: 8

李文豪
李文豪

Reputation: 21

I got it to build successfully by updating build.json and running the command cordova run android --release!

What I did is:

  1. Upgrade Gradle form v6.7.1 to v7.3.3 (Windows version, download .zip and setup "Path").
  2. build.json add ,"packageType": "apk".

Build app-release.apk successful:

enter image description here

Upvotes: 1

Rehum
Rehum

Reputation: 600

Ionic has built-in command line to generate the .aab format.

AAB:

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

It will generate automatically the .aab at android/app/build/outputs/bundle/release

APK:

ionic cordova build android --prod --release 

May it helps someone. Thanks

Upvotes: 5

Vincenzo
Vincenzo

Reputation: 168

In other answers it seems that you can run:

./gradlew bundleRelease

In my case it's not working. I solved upgrading android platform version for ionic.

ionic cordova platform rm android
ionic cordova platform add android@8
ionic cordova build android --prod --release

After that, if you go in platforms\android folder you are able to do

./gradlew bundle

I didn't check gradle versions for both android versions but I suppose it's changed.

Regards,Vincenzo

Upvotes: 3

Related Questions