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?
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