cordova-android icon indicating copy to clipboard operation
cordova-android copied to clipboard

Issue with gradleArg parameter not being used when created gradle wrapper

Open rharrwwis opened this issue 4 years ago • 1 comments

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

  • [x] I searched for existing GitHub issues
  • [x] I updated all Cordova tooling to most recent version
  • [x] I included all the necessary information above

rharrwwis avatar Jun 30 '21 13:06 rharrwwis

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

breautek avatar Sep 13 '21 01:09 breautek