Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android builds: Failure when providing Cordova/Gradle arguments #2254

Closed
zarko-tg opened this issue May 10, 2017 · 3 comments
Closed

Android builds: Failure when providing Cordova/Gradle arguments #2254

zarko-tg opened this issue May 10, 2017 · 3 comments
Labels
Milestone

Comments

@zarko-tg
Copy link

Cannot build for Android when providing additional arguments (Cordova/Gradle). Problem that came with ionic@3.0.0

$ 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 
@imhoffd imhoffd added this to the CLI 3.0.1 milestone May 10, 2017
@imhoffd imhoffd added the bug label May 10, 2017
@imhoffd
Copy link
Contributor

imhoffd commented May 11, 2017

@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

@zarko-tg
Copy link
Author

I can confirm the command with "-- --" works as expected with ionic@canary.

@zarko-tg
Copy link
Author

#2354 for iOS seems similar to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants