apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.65k stars 1.54k forks source link

Issue with gradleArg parameter not being used when created gradle wrapper #1249

Open rharrwwis opened 3 years ago

rharrwwis commented 3 years ago

Bug Report

Problem

gradleArg is not being passed to the gradle command when it is creating the wrapper and I was using gradleArg=--project-cache-dir=/tmp because my project directory is on a Windows file server. If I ran the gradle command manually with my --project-cache-dir everything worked fine, but I could not build using the cordova command directly.

What is expected to happen?

Extra gradle arguments are passed through the command line to gradle using cordova commands.

What does actually happen?

It works except when cordova is creating the gradle wrapper during prepEnv.

Information

To get this to work I added an opts parameter to runGradleWrapper in ProjectBuilder.js. This passed in the arguments successfully and I was able to generate an APK using a Mac device with my project folder existing on a Windows file server using the --gradleArg=--project-cache-dir=/tmp.

Command or Code

Added opts to ProjectBuilder.js:

/*
* This returns a promise
*/
runGradleWrapper (gradle_cmd, opts) {
    var gradlePath = path.join(this.root, 'gradlew');
    var wrapperGradle = path.join(this.root, 'wrapper.gradle');
    if (fs.existsSync(gradlePath)) {
        // Literally do nothing, for some reason this works, while !fs.existsSync didn't on Windows
    } else if (opts.extraArgs) {
        return execa(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle, opts.extraArgs], { stdio: 'inherit' });
    }
    else {
        return execa(gradle_cmd, ['-p', this.root, 'wrapper', '-b', wrapperGradle], { stdio: 'inherit' });
    }
}

prepEnv (opts) {
    var self = this;
    return check_reqs.check_gradle()
        .then(function (gradlePath) {
            return self.runGradleWrapper(gradlePath, opts);
        }).then(function () {
            return self.prepBuildFiles();
        }).then(() => {

Environment, Platform, Device

Mac OS with project on Windows file server (SMB).

Version information

Checklist

breautek commented 3 years ago

Wonder if this should re-use the existing gradleArgs argument, or if it should be a separate argument specifically for the wrapper command...

I'm thinking the former...