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

Fix Android builds when gradle args and project dir have spaces #2648

Merged
merged 1 commit into from
Mar 24, 2017

Conversation

rosen-vladimirov
Copy link
Contributor

In case you try building application, it will fail in case the following conditions are applied:

  • build on Windows
  • build for Android
  • build in release
  • path to project dir has spaces
  • path to certificate (keystore) has spaces OR the certificate(keystore) name itself has spaces OR the password has spaces

The problem is in Node.js's child_process when spawn is used - on Windows it has issues when both the command (in our case this is the FULL PATH to gradlew.bat executable in platforms dir of the project) and ANY of the arguments passed to child_process's spawn have spaces.
As we are also setting the current working directory of the spawned process to be the path to <project dir>/platforms/android, change the command passed to spawn to be just gradlew. This way we'll never have spaces in the command and we'll not hit this issue.

More information for the Node.js issue: nodejs/node-v0.x-archive#25895

There's a similar issue (linked in the comments of the above) for newer node.js versions. The suggested solution there is to use { shell: true} parameter to spawn method, but this will require handling of all spaces in the args on our own.

}

return this.$childProcess.spawnFromEvent(gradleBin, ["--stop", "--quiet"], "close", { stdio: "inherit", cwd: projectRoot });
// TODO: Check if we have to pass compileSdk and other options here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we help with this TODO?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping @Plamen5kov , @Pip3r4o for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we need to call stop and should we pass other options...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just tested it without args and it's working fine, so I'll remove the TODOD

Copy link
Contributor

@petekanev petekanev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -504,6 +492,19 @@ export class AndroidProjectService extends projectServiceBaseLib.PlatformProject

return versionInManifest;
}

private async executeGradleCommand(projectRoot: string, gradleArgs: string[], childProcessOpts?: SpawnOptions, spawnFromEventOptions?: ISpawnFromEventOptions): Promise<ISpawnResult> {
const gradleBin = this.$hostInfo.isWindows ? "gradlew.bat" : "./gradlew";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rename this const to "gradlew" as it points to the wrapper, not gradle itself.

In case you try building application, it will fail in case the following conditions are applied:
* build on Windows
* build for Android
* build in release
* path to project dir has spaces
* path to certificate (keystore) has spaces OR the certificate(keystore) name itself has spaces OR the password has spaces

The problem is in Node.js's `child_process` when `spawn` is used - on Windows it has issues when both the command (in our case this is the FULL PATH to gradlew.bat executable in platforms dir of the project) and ANY of the arguments passed to `child_process's spawn` have spaces.
As we are also setting the current working directory of the spawned process to be the path to `<project dir>/platforms/android`, change the `command` passed to `spawn` to be just `gradlew`. This way we'll never have spaces in the command and we'll not hit this issue.
@rosen-vladimirov rosen-vladimirov force-pushed the vladimirov/fix-android-spaces branch from 9dee3af to e87415f Compare March 24, 2017 11:27
@rosen-vladimirov rosen-vladimirov merged commit 8e0647c into master Mar 24, 2017
@rosen-vladimirov rosen-vladimirov deleted the vladimirov/fix-android-spaces branch March 24, 2017 11:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants