Cannot build for Android when providing additional arguments (Cordova/Gradle). Problem that came with [email protected]
$ ionic cordova build android --verbose --device --prod --release -- --gradleArg=-PcdvBuildMultipleApks=true
[DEBUG] !!! ERROR ENCOUNTERED !!!
TypeError: Cannot read property 'private' of undefined
[DEBUG] TypeError: Cannot read property 'private' of undefined
at inputs.filter (/Users/zarko/app/node_modules/@ionic/cli-utils/dist/lib/command/command.js:89:31)
at Array.filter (native)
at BuildCommand.getCleanInputsForTelemetry (/Users/zarko/app/node_modules/@ionic/cli-utils/dist/lib/command/command.js:88:18)
at BuildCommand.<anonymous> (/Users/zarko/app/node_modules/@ionic/cli-utils/dist/lib/command/command.js:63:46)
at next (native)
at fulfilled (/Users/zarko/app/node_modules/@ionic/cli-utils/dist/lib/command/command.js:4:58)
Remove everything after "--release" in the command and everything's fine.
global packages:
@ionic/cli-utils : 1.0.0
Cordova CLI : 6.5.0
Ionic CLI : 3.0.0
local packages:
@ionic/app-scripts : 1.3.7
@ionic/cli-plugin-cordova : 1.0.0
@ionic/cli-plugin-ionic-angular : 1.0.0
Ionic Framework : ionic-angular 3.2.0
System:
Node : v6.10.3
OS : macOS Sierra
Xcode : Xcode 8.3.2 Build version 8E2002
ios-deploy : 1.9.1
ios-sim : 5.0.13
@zarko-tg Interesting. So there was a bug related to not being able to handle the extra options. But then I realized we're going to have to do something a bit... odd. The --
separator is a special symbol that, by convention, tells the program to stop parsing args afterwards. In Cordova's case, as they show in their docs, arguments after --
(when using the cordova
) get passed onto Cordova Android, which then continues to parse them, looking for --gradleArgs
, which it then finally passes to gradle, as you know.
We are _wrapping_ this yet further by slapping ionic
at the front of it. But it's actually more complicated than just prepending a word. We have our own set of options, such as --prod
and the livereload options for run
and emulate
.
To pass options _unparsed_ to Cordova, one would do:
ionic cordova build ios -- --cordovaOpt=...
which the Ionic CLI would transform to ultimately run:
cordova build ios --cordovaOpt=...
But, to mark unparsed options for Cordova Android, one must first also mark unparsed options for Cordova. So we get a double --
:
ionic cordova build android -- --cordovaOpt=... -- --gradleArg=...
which the Ionic CLI would transform to ultimately run:
cordova build android --cordovaOpt=... -- --gradleArg=...
To run the command you want to run at the top of your issue, one would do this:
ionic cordova build android --verbose --device --prod --release -- -- --gradleArg=-PcdvBuildMultipleApks=true
which the Ionic CLI would transform to ultimately run:
cordova build android --device --release -- --gradleArg=-PcdvBuildMultipleApks=true
This is what happens when you wrap several tools into one! 馃槃 Very confusing. But that's sort of the nature of the beast. The Cordova docs I linked to show alternative ways to configure gradle.
But we're still interested in having it work for our users solely via command line. I've just pushed a fix, would you be willing to give it a try?
npm i -g ionic@canary
I can confirm the command with "-- --" works as expected with ionic@canary.
https://github.com/driftyco/ionic-cli/issues/2354 for iOS seems similar to this.
Most helpful comment
@zarko-tg Interesting. So there was a bug related to not being able to handle the extra options. But then I realized we're going to have to do something a bit... odd. The
--
separator is a special symbol that, by convention, tells the program to stop parsing args afterwards. In Cordova's case, as they show in their docs, arguments after--
(when using thecordova
) get passed onto Cordova Android, which then continues to parse them, looking for--gradleArgs
, which it then finally passes to gradle, as you know.We are _wrapping_ this yet further by slapping
ionic
at the front of it. But it's actually more complicated than just prepending a word. We have our own set of options, such as--prod
and the livereload options forrun
andemulate
.To pass options _unparsed_ to Cordova, one would do:
ionic cordova build ios -- --cordovaOpt=...
which the Ionic CLI would transform to ultimately run:
cordova build ios --cordovaOpt=...
But, to mark unparsed options for Cordova Android, one must first also mark unparsed options for Cordova. So we get a double
--
:ionic cordova build android -- --cordovaOpt=... -- --gradleArg=...
which the Ionic CLI would transform to ultimately run:
cordova build android --cordovaOpt=... -- --gradleArg=...
To run the command you want to run at the top of your issue, one would do this:
ionic cordova build android --verbose --device --prod --release -- -- --gradleArg=-PcdvBuildMultipleApks=true
which the Ionic CLI would transform to ultimately run:
cordova build android --device --release -- --gradleArg=-PcdvBuildMultipleApks=true
This is what happens when you wrap several tools into one! 馃槃 Very confusing. But that's sort of the nature of the beast. The Cordova docs I linked to show alternative ways to configure gradle.
But we're still interested in having it work for our users solely via command line. I've just pushed a fix, would you be willing to give it a try?
npm i -g ionic@canary