diff --git a/bin/templates/cordova/lib/config/GradlePropertiesParser.js b/bin/templates/cordova/lib/config/GradlePropertiesParser.js index ac7f3863..b45c0a67 100644 --- a/bin/templates/cordova/lib/config/GradlePropertiesParser.js +++ b/bin/templates/cordova/lib/config/GradlePropertiesParser.js @@ -46,11 +46,17 @@ class GradlePropertiesParser { this.gradleFilePath = path.join(platformDir, 'gradle.properties'); } - configure () { + configure (userConfigs) { events.emit('verbose', '[Gradle Properties] Preparing Configuration'); this._initializeEditor(); - this._configureDefaults(); + + events.emit('verbose', '[Gradle Properties] Appending default configuration properties'); + this._configureProperties(this._defaults); + + events.emit('verbose', '[Gradle Properties] Appending custom configuration properties'); + this._configureProperties(userConfigs); + this._save(); } @@ -69,18 +75,19 @@ class GradlePropertiesParser { } /** - * Validate that defaults are set and set the missing defaults. + * Validate that defaults or user configuration properties are set and + * set the missing items. */ - _configureDefaults () { - // Loop though Cordova default properties and set only if missing. - Object.keys(this._defaults).forEach(key => { + _configureProperties (properties) { + // Iterate though the properties and set only if missing. + Object.keys(properties).forEach(key => { let value = this.gradleFile.get(key); if (!value) { - events.emit('verbose', `[Gradle Properties] Appended missing default: ${key}=${this._defaults[key]}`); - this.gradleFile.set(key, this._defaults[key]); - } else if (value !== this._defaults[key]) { - events.emit('info', `[Gradle Properties] Detected Gradle property "${key}" with the value of "${value}", Cordova's recommended value is "${this._defaults[key]}"`); + events.emit('verbose', `[Gradle Properties] Appending configuration item: ${key}=${properties[key]}`); + this.gradleFile.set(key, properties[key]); + } else if (value !== properties[key]) { + events.emit('info', `[Gradle Properties] Detected Gradle property "${key}" with the value of "${value}", Cordova's recommended value is "${properties[key]}"`); } }); } diff --git a/bin/templates/cordova/lib/prepare.js b/bin/templates/cordova/lib/prepare.js index 2eb08884..49e0a7d7 100644 --- a/bin/templates/cordova/lib/prepare.js +++ b/bin/templates/cordova/lib/prepare.js @@ -43,8 +43,14 @@ module.exports.prepare = function (cordovaProject, options) { this._config = updateConfigFilesFrom(cordovaProject.projectConfig, munger, this.locations); + // Get the min SDK version from config.xml + const minSdkVersion = this._config.getPreference('android-minSdkVersion', 'android'); + + let gradlePropertiesUserConfig = {}; + if (minSdkVersion) gradlePropertiesUserConfig.cdvMinSdkVersion = minSdkVersion; + let gradlePropertiesParser = new GradlePropertiesParser(this.locations.root); - gradlePropertiesParser.configure(); + gradlePropertiesParser.configure(gradlePropertiesUserConfig); // Update own www dir with project's www assets and plugins' assets and js-files return Q.when(updateWww(cordovaProject, this.locations)).then(function () { diff --git a/spec/unit/config/GradlePropertiesParser.spec.js b/spec/unit/config/GradlePropertiesParser.spec.js index 91af6270..4f4b9cbb 100644 --- a/spec/unit/config/GradlePropertiesParser.spec.js +++ b/spec/unit/config/GradlePropertiesParser.spec.js @@ -74,7 +74,7 @@ describe('Gradle Builder', () => { }); }); - describe('_configureDefaults method', () => { + describe('_configureProperties method', () => { let parser; let emitSpy; @@ -99,11 +99,11 @@ describe('Gradle Builder', () => { get: getSpy }; - parser._configureDefaults(); + parser._configureProperties(parser._defaults); expect(getSpy).toHaveBeenCalled(); expect(setSpy).toHaveBeenCalled(); - expect(emitSpy.calls.argsFor(0)[1]).toContain('Appended missing default'); + expect(emitSpy.calls.argsFor(0)[1]).toContain('Appending configuration item'); }); it('should not detect missing defaults and not call set.', () => { @@ -115,7 +115,7 @@ describe('Gradle Builder', () => { get: getSpy }; - parser._configureDefaults(); + parser._configureProperties(parser._defaults); expect(getSpy).toHaveBeenCalled(); expect(setSpy).not.toHaveBeenCalled(); @@ -130,7 +130,7 @@ describe('Gradle Builder', () => { get: getSpy }; - parser._configureDefaults(); + parser._configureProperties(parser._defaults); expect(getSpy).toHaveBeenCalled(); expect(setSpy).not.toHaveBeenCalled();