diff --git a/framework/AndroidManifest.xml b/framework/AndroidManifest.xml
index 320c2538..77a4bf7a 100755
--- a/framework/AndroidManifest.xml
+++ b/framework/AndroidManifest.xml
@@ -18,5 +18,6 @@
under the License.
-->
+ android:versionName="1.0"
+ android:versionCode="1">
diff --git a/framework/build.gradle b/framework/build.gradle
index 05b0f7ae..d1f1d4fe 100644
--- a/framework/build.gradle
+++ b/framework/build.gradle
@@ -44,6 +44,8 @@ allprojects {
apply plugin: 'com.android.library'
android {
+ namespace 'org.apache.cordova'
+
compileSdkVersion cordovaConfig.COMPILE_SDK_VERSION
buildToolsVersion cordovaConfig.BUILD_TOOLS_VERSION
diff --git a/framework/cdv-gradle-config-defaults.json b/framework/cdv-gradle-config-defaults.json
index e7481d32..605b9989 100644
--- a/framework/cdv-gradle-config-defaults.json
+++ b/framework/cdv-gradle-config-defaults.json
@@ -2,14 +2,15 @@
"MIN_SDK_VERSION": 24,
"SDK_VERSION": 33,
"COMPILE_SDK_VERSION": null,
- "GRADLE_VERSION": "7.4.2",
+ "GRADLE_VERSION": "7.6",
"MIN_BUILD_TOOLS_VERSION": "33.0.2",
- "AGP_VERSION": "7.2.1",
+ "AGP_VERSION": "7.4.2",
"KOTLIN_VERSION": "1.5.21",
"ANDROIDX_APP_COMPAT_VERSION": "1.6.1",
"ANDROIDX_WEBKIT_VERSION": "1.6.0",
"ANDROIDX_CORE_SPLASHSCREEN_VERSION": "1.0.0",
"GRADLE_PLUGIN_GOOGLE_SERVICES_VERSION": "4.3.15",
"IS_GRADLE_PLUGIN_GOOGLE_SERVICES_ENABLED": false,
- "IS_GRADLE_PLUGIN_KOTLIN_ENABLED": false
+ "IS_GRADLE_PLUGIN_KOTLIN_ENABLED": false,
+ "PACKAGE_NAMESPACE": "io.cordova.helloCordova"
}
diff --git a/framework/cordova.gradle b/framework/cordova.gradle
index f929911f..8ce3b9f6 100644
--- a/framework/cordova.gradle
+++ b/framework/cordova.gradle
@@ -125,14 +125,6 @@ def doExtractIntFromManifest(name) {
return new BigInteger(matcher.group(1))
}
-def doExtractStringFromManifest(name) {
- def manifestFile = file(android.sourceSets.main.manifest.srcFile)
- def pattern = Pattern.compile(name + "=\"(\\S+)\"")
- def matcher = pattern.matcher(manifestFile.getText())
- matcher.find()
- return matcher.group(1)
-}
-
def doGetConfigXml() {
def xml = file("src/main/res/xml/config.xml").getText()
// Disable namespace awareness since Cordova doesn't use them properly
@@ -231,7 +223,6 @@ ext {
privateHelpers.getProjectTarget = { doGetProjectTarget() }
privateHelpers.applyCordovaConfigCustomization = { doApplyCordovaConfigCustomization() }
privateHelpers.extractIntFromManifest = { name -> doExtractIntFromManifest(name) }
- privateHelpers.extractStringFromManifest = { name -> doExtractStringFromManifest(name) }
privateHelpers.ensureValueExists = { filePath, props, key -> doEnsureValueExists(filePath, props, key) }
// These helpers can be used by plugins / projects and will not change.
diff --git a/lib/AndroidManifest.js b/lib/AndroidManifest.js
index 22ffd822..f8ab241c 100644
--- a/lib/AndroidManifest.js
+++ b/lib/AndroidManifest.js
@@ -50,15 +50,6 @@ class AndroidManifest {
return this;
}
- getPackageId () {
- return this.doc.getroot().attrib.package;
- }
-
- setPackageId (pkgId) {
- this.doc.getroot().attrib.package = pkgId;
- return this;
- }
-
getActivity () {
const activity = this.doc.getroot().find('./application/activity');
return {
diff --git a/lib/AndroidProject.js b/lib/AndroidProject.js
index e85aa360..d0b0ad09 100644
--- a/lib/AndroidProject.js
+++ b/lib/AndroidProject.js
@@ -20,8 +20,8 @@
const fs = require('fs');
const path = require('path');
const properties_parser = require('properties-parser');
-const AndroidManifest = require('./AndroidManifest');
const pluginHandlers = require('./pluginHandlers');
+const CordovaGradleConfigParserFactory = require('./config/CordovaGradleConfigParserFactory');
let projectFileCache = {};
@@ -63,17 +63,17 @@ class AndroidProject {
this.projectDir = projectDir;
this.platformWww = path.join(this.projectDir, 'platform_www');
this.www = path.join(this.projectDir, 'app/src/main/assets/www');
+ this.cordovaGradleConfigParser = CordovaGradleConfigParserFactory.create(this.projectDir);
}
/**
- * Reads the package name out of the Android Manifest file
+ * Reads the package name out of the Cordova's Gradle Config file
*
* @param {String} projectDir The absolute path to the directory containing the project
* @return {String} The name of the package
*/
getPackageName () {
- const manifestPath = path.join(this.projectDir, 'app/src/main/AndroidManifest.xml');
- return new AndroidManifest(manifestPath).getPackageId();
+ return this.cordovaGradleConfigParser.getPackageName();
}
getCustomSubprojectRelativeDir (plugin_id, src) {
diff --git a/lib/builders/ProjectBuilder.js b/lib/builders/ProjectBuilder.js
index d253e73e..4410cd5b 100644
--- a/lib/builders/ProjectBuilder.js
+++ b/lib/builders/ProjectBuilder.js
@@ -27,6 +27,7 @@ const check_reqs = require('../check_reqs');
const PackageType = require('../PackageType');
const { compareByAll } = require('../utils');
const { createEditor } = require('properties-parser');
+const CordovaGradleConfigParserFactory = require('../config/CordovaGradleConfigParserFactory');
const MARKER = 'YOUR CHANGES WILL BE ERASED!';
const SIGNING_PROPERTIES = '-signing.properties';
@@ -145,19 +146,6 @@ class ProjectBuilder {
};
}
- extractRealProjectNameFromManifest () {
- const manifestPath = path.join(this.root, 'app', 'src', 'main', 'AndroidManifest.xml');
- const manifestData = fs.readFileSync(manifestPath, 'utf8');
- const m = /} The parsed JSON object representing the gradle config.
+ */
+ _readConfig (configPath) {
+ return fs.readJSONSync(configPath, 'utf-8');
+ }
+
+ setPackageName (packageName) {
+ events.emit('verbose', '[Cordova Gradle Config] Setting "PACKAGE_NAMESPACE" to ' + packageName);
+ this._cdvGradleConfig.PACKAGE_NAMESPACE = packageName;
+ return this;
+ }
+
+ getPackageName () {
+ return this._cdvGradleConfig.PACKAGE_NAMESPACE;
+ }
+
+ getProjectNameFromPackageName () {
+ const packageName = this._cdvGradleConfig.PACKAGE_NAMESPACE;
+ return packageName.substring(packageName.lastIndexOf('.') + 1);
+ }
+
+ /**
+ * Saves any changes that has been made to the properties file.
+ */
+ write () {
+ events.emit('verbose', '[Cordova Gradle Config] Saving File');
+ fs.writeJSONSync(this._cdvGradleConfigFilePath, this._cdvGradleConfig, 'utf-8');
+ }
+}
+
+module.exports = CordovaGradleConfigParser;
diff --git a/lib/config/CordovaGradleConfigParserFactory.js b/lib/config/CordovaGradleConfigParserFactory.js
new file mode 100644
index 00000000..27ad4fab
--- /dev/null
+++ b/lib/config/CordovaGradleConfigParserFactory.js
@@ -0,0 +1,35 @@
+
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+const CordovaGradleConfigParser = require('./CordovaGradleConfigParser');
+
+/**
+ * Builds new gradle config parsers
+ */
+module.exports = class CordovaGradleConfigParserFactory {
+ /**
+ * Loads and Edits Gradle Properties File.
+ *
+ * @param {String} platformDir is the path of the Android platform directory
+ */
+ static create (platformDir) {
+ return new CordovaGradleConfigParser(platformDir);
+ }
+};
diff --git a/lib/create.js b/lib/create.js
index 6ee2387c..7f5d6013 100755
--- a/lib/create.js
+++ b/lib/create.js
@@ -23,6 +23,7 @@ const utils = require('./utils');
const check_reqs = require('./check_reqs');
const ROOT = path.join(__dirname, '..');
const { createEditor } = require('properties-parser');
+const CordovaGradleConfigParserFactory = require('./config/CordovaGradleConfigParserFactory');
const CordovaError = require('cordova-common').CordovaError;
const AndroidManifest = require('./AndroidManifest');
@@ -249,6 +250,11 @@ exports.create = function (project_path, config, options, events) {
fs.ensureDirSync(assets_path);
fs.ensureDirSync(resource_path);
+ // store package name in cdv-gradle-config
+ const cdvGradleConfig = CordovaGradleConfigParserFactory.create(project_path);
+ cdvGradleConfig.setPackageName(package_name)
+ .write();
+
// interpolate the activity name and package
const packagePath = package_name.replace(/\./g, path.sep);
const activity_dir = path.join(java_path, packagePath);
@@ -261,8 +267,7 @@ exports.create = function (project_path, config, options, events) {
utils.replaceFileContents(activity_path, /__ID__/, package_name);
const manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
- manifest.setPackageId(package_name)
- .getActivity().setName(safe_activity_name);
+ manifest.getActivity().setName(safe_activity_name);
const manifest_path = path.join(app_path, 'AndroidManifest.xml');
manifest.write(manifest_path);
diff --git a/lib/prepare.js b/lib/prepare.js
index 5a93f9e4..b855940f 100644
--- a/lib/prepare.js
+++ b/lib/prepare.js
@@ -34,6 +34,7 @@ const utils = require('./utils');
const gradleConfigDefaults = require('./gradle-config-defaults');
const checkReqs = require('./check_reqs');
const GradlePropertiesParser = require('./config/GradlePropertiesParser');
+const CordovaGradleConfigParserFactory = require('./config/CordovaGradleConfigParserFactory');
function parseArguments (argv) {
return nopt({
@@ -278,20 +279,22 @@ function updateProjectAccordingTo (platformConfig, locations) {
// Java packages cannot support dashes
const androidPkgName = (platformConfig.android_packageName() || platformConfig.packageName()).replace(/-/g, '_');
- const manifest = new AndroidManifest(locations.manifest);
- const manifestId = manifest.getPackageId();
+ // updating cdv-gradle-config with new androidPkgName.
+ const cdvGradleConfig = CordovaGradleConfigParserFactory.create(locations.root);
+ cdvGradleConfig.setPackageName(androidPkgName)
+ .write();
+ const manifest = new AndroidManifest(locations.manifest);
manifest.getActivity()
.setOrientation(platformConfig.getPreference('orientation'))
.setLaunchMode(findAndroidLaunchModePreference(platformConfig));
manifest.setVersionName(platformConfig.version())
.setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
- .setPackageId(androidPkgName)
.write();
// Java file paths shouldn't be hard coded
- const javaDirectory = path.join(locations.javaSrc, manifestId.replace(/\./g, '/'));
+ const javaDirectory = path.join(locations.javaSrc, androidPkgName.replace(/\./g, '/'));
const java_files = glob.sync('**/*.java', { cwd: javaDirectory, absolute: true }).filter(f => {
const contents = fs.readFileSync(f, 'utf-8');
return /extends\s+CordovaActivity/.test(contents);
diff --git a/lib/run.js b/lib/run.js
index cb350987..d3bbaee6 100644
--- a/lib/run.js
+++ b/lib/run.js
@@ -23,6 +23,7 @@ const build = require('./build');
const PackageType = require('./PackageType');
const AndroidManifest = require('./AndroidManifest');
const { CordovaError, events } = require('cordova-common');
+const CordovaGradleConfigParserFactory = require('./config/CordovaGradleConfigParserFactory');
/**
* Builds a target spec from a runOptions object
@@ -78,6 +79,7 @@ module.exports.run = async function (runOptions = {}) {
}
const manifest = new AndroidManifest(this.locations.manifest);
+ const cordovaGradleConfigParser = CordovaGradleConfigParserFactory.create(this.locations.root);
- return target.install(resolvedTarget, { manifest, buildResults });
+ return target.install(resolvedTarget, { manifest, buildResults, cordovaGradleConfigParser });
};
diff --git a/lib/target.js b/lib/target.js
index 8c29788f..69066db9 100644
--- a/lib/target.js
+++ b/lib/target.js
@@ -127,9 +127,9 @@ exports.resolve = async (spec, buildResults) => {
};
};
-exports.install = async function ({ id: target, arch, type }, { manifest, buildResults }) {
+exports.install = async function ({ id: target, arch, type }, { manifest, buildResults, cordovaGradleConfigParser }) {
const apk_path = build.findBestApkForArchitecture(buildResults, arch);
- const pkgName = manifest.getPackageId();
+ const pkgName = cordovaGradleConfigParser.getPackageName();
const launchName = pkgName + '/.' + manifest.getActivity().getName();
events.emit('log', 'Using apk: ' + apk_path);
diff --git a/spec/fixtures/android_studio_project/gradle/wrapper/gradle-wrapper.properties b/spec/fixtures/android_studio_project/gradle/wrapper/gradle-wrapper.properties
index 68ff47a2..a0fb37c6 100644
--- a/spec/fixtures/android_studio_project/gradle/wrapper/gradle-wrapper.properties
+++ b/spec/fixtures/android_studio_project/gradle/wrapper/gradle-wrapper.properties
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-all.zip
diff --git a/spec/unit/AndroidManifest.spec.js b/spec/unit/AndroidManifest.spec.js
index 97b8867f..e156efdc 100644
--- a/spec/unit/AndroidManifest.spec.js
+++ b/spec/unit/AndroidManifest.spec.js
@@ -110,18 +110,6 @@ describe('AndroidManifest', () => {
});
});
- describe('packageId', () => {
- it('should get the package ID', () => {
- expect(manifest.getPackageId()).toBe(PACKAGE_ID);
- });
-
- it('should set the package ID', () => {
- const newPackageId = `${PACKAGE_ID}new`;
- manifest.setPackageId(newPackageId);
- expect(manifest.getPackageId()).toBe(newPackageId);
- });
- });
-
describe('activity', () => {
let activity;
diff --git a/spec/unit/AndroidProject.spec.js b/spec/unit/AndroidProject.spec.js
index 9da35a47..79d57f2f 100644
--- a/spec/unit/AndroidProject.spec.js
+++ b/spec/unit/AndroidProject.spec.js
@@ -19,6 +19,8 @@
const path = require('path');
const rewire = require('rewire');
+const MockCordovaGradleConfigParser = require('./mocks/config/MockCordovaGradleConfigParser');
+const CordovaGradleConfigParserFactory = require('../../lib/config/CordovaGradleConfigParserFactory');
describe('AndroidProject', () => {
const PROJECT_DIR = 'platforms/android';
@@ -30,6 +32,8 @@ describe('AndroidProject', () => {
AndroidStudioSpy = jasmine.createSpyObj('AndroidStudio', ['isAndroidStudioProject']);
AndroidProject.__set__('AndroidStudio', AndroidStudioSpy);
+
+ spyOn(CordovaGradleConfigParserFactory, 'create').and.returnValue(new MockCordovaGradleConfigParser(PROJECT_DIR));
});
describe('constructor', () => {
@@ -87,26 +91,20 @@ describe('AndroidProject', () => {
});
describe('getPackageName', () => {
- let AndroidManifestSpy;
- let AndroidManifestFns;
let androidProject;
beforeEach(() => {
- AndroidManifestFns = jasmine.createSpyObj('AndroidManifestFns', ['getPackageId']);
- AndroidManifestSpy = jasmine.createSpy('AndroidManifest').and.returnValue(AndroidManifestFns);
- AndroidProject.__set__('AndroidManifest', AndroidManifestSpy);
-
androidProject = new AndroidProject(PROJECT_DIR);
});
- it('should get the package name AndroidManifest', () => {
+ it('should get the package name Cordova Gradle Config file', () => {
+ spyOn(MockCordovaGradleConfigParser.prototype, 'getPackageName');
androidProject.getPackageName();
- expect(AndroidManifestSpy).toHaveBeenCalledWith(path.join(PROJECT_DIR, 'app/src/main/AndroidManifest.xml'));
+ expect(MockCordovaGradleConfigParser.prototype.getPackageName).toHaveBeenCalled();
});
it('should return the package name', () => {
const packageName = 'io.cordova.unittest';
- AndroidManifestFns.getPackageId.and.returnValue(packageName);
expect(androidProject.getPackageName()).toBe(packageName);
});
diff --git a/spec/unit/builders/ProjectBuilder.spec.js b/spec/unit/builders/ProjectBuilder.spec.js
index 9cb2eb7c..7d954910 100644
--- a/spec/unit/builders/ProjectBuilder.spec.js
+++ b/spec/unit/builders/ProjectBuilder.spec.js
@@ -21,8 +21,6 @@ const fs = require('fs-extra');
const path = require('path');
const rewire = require('rewire');
-const CordovaError = require('cordova-common').CordovaError;
-
describe('ProjectBuilder', () => {
const rootDir = '/root';
@@ -143,30 +141,6 @@ describe('ProjectBuilder', () => {
expect(execaSpy).not.toHaveBeenCalledWith('/my/sweet/gradle', jasmine.any(Array), jasmine.any(Object));
});
});
-
- describe('extractRealProjectNameFromManifest', () => {
- it('should get the project name from the Android Manifest', () => {
- const projectName = 'unittestproject';
- const projectId = `io.cordova.${projectName}`;
- const manifest = `
- `;
-
- spyOn(fs, 'readFileSync').and.returnValue(manifest);
-
- expect(builder.extractRealProjectNameFromManifest()).toBe(projectName);
- });
-
- it('should throw an error if there is no package in the Android manifest', () => {
- const manifest = `
- `;
-
- spyOn(fs, 'readFileSync').and.returnValue(manifest);
-
- expect(() => builder.extractRealProjectNameFromManifest()).toThrow(jasmine.any(CordovaError));
- });
- });
-
describe('build', () => {
beforeEach(() => {
spyOn(builder, 'getArgs');
diff --git a/spec/unit/create.spec.js b/spec/unit/create.spec.js
index 298fb8e3..8c9c4304 100644
--- a/spec/unit/create.spec.js
+++ b/spec/unit/create.spec.js
@@ -23,8 +23,16 @@ const create = rewire('../../lib/create');
const check_reqs = require('../../lib/check_reqs');
const fs = require('fs-extra');
const path = require('path');
+const MockCordovaGradleConfigParser = require('./mocks/config/MockCordovaGradleConfigParser');
+const CordovaGradleConfigParserFactory = require('../../lib/config/CordovaGradleConfigParserFactory');
describe('create', function () {
+ const PROJECT_DIR = 'platforms/android';
+
+ beforeAll(() => {
+ spyOn(CordovaGradleConfigParserFactory, 'create').and.returnValue(new MockCordovaGradleConfigParser(PROJECT_DIR));
+ });
+
describe('validatePackageName helper method', function () {
describe('happy path (valid package names)', function () {
const valid = [
diff --git a/spec/unit/mocks/config/MockCordovaGradleConfigParser.js b/spec/unit/mocks/config/MockCordovaGradleConfigParser.js
new file mode 100644
index 00000000..8e33083c
--- /dev/null
+++ b/spec/unit/mocks/config/MockCordovaGradleConfigParser.js
@@ -0,0 +1,32 @@
+/**
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+*/
+
+const CordovaGradleConfigParser = require('../../../../lib/config/CordovaGradleConfigParser');
+
+module.exports = class MockCordoCordovaGradleConfigParservaGradleConfigParser extends CordovaGradleConfigParser {
+ _readConfig (configPath) {
+ return {
+ PACKAGE_NAMESPACE: 'io.cordova.unittest'
+ };
+ }
+
+ write () {
+ // Pretend write :)
+ }
+};
diff --git a/spec/unit/pluginHandlers/handlers.spec.js b/spec/unit/pluginHandlers/handlers.spec.js
index 5175b1fb..33e8b266 100644
--- a/spec/unit/pluginHandlers/handlers.spec.js
+++ b/spec/unit/pluginHandlers/handlers.spec.js
@@ -32,6 +32,9 @@ const android_studio_project = path.join(__dirname, '../../fixtures/android_stud
const PluginInfo = require('cordova-common').PluginInfo;
const AndroidProject = require('../../../lib/AndroidProject');
+const MockCordovaGradleConfigParser = require('../mocks/config/MockCordovaGradleConfigParser');
+const CordovaGradleConfigParserFactory = require('../../../lib/config/CordovaGradleConfigParserFactory');
+
const dummyPluginInfo = new PluginInfo(dummyplugin);
const valid_source = dummyPluginInfo.getSourceFiles('android');
const valid_resources = dummyPluginInfo.getResourceFiles('android');
@@ -41,6 +44,12 @@ const faultyPluginInfo = new PluginInfo(faultyplugin);
const invalid_source = faultyPluginInfo.getSourceFiles('android');
describe('android project handler', function () {
+ const PROJECT_DIR = 'platforms/android';
+
+ beforeAll(() => {
+ spyOn(CordovaGradleConfigParserFactory, 'create').and.returnValue(new MockCordovaGradleConfigParser(PROJECT_DIR));
+ });
+
describe('installation', function () {
const copyFileOrig = common.__get__('copyFile');
const copyFileSpy = jasmine.createSpy('copyFile');
diff --git a/spec/unit/prepare.spec.js b/spec/unit/prepare.spec.js
index 56ee3cc5..05164177 100644
--- a/spec/unit/prepare.spec.js
+++ b/spec/unit/prepare.spec.js
@@ -23,6 +23,8 @@ const CordovaError = require('cordova-common').CordovaError;
const GradlePropertiesParser = require('../../lib/config/GradlePropertiesParser');
const utils = require('../../lib/utils');
const et = require('elementtree');
+const MockCordovaGradleConfigParser = require('./mocks/config/MockCordovaGradleConfigParser');
+const CordovaGradleConfigParserFactory = require('../../lib/config/CordovaGradleConfigParserFactory');
const PATH_RESOURCE = path.join('platforms', 'android', 'app', 'src', 'main', 'res');
@@ -93,6 +95,12 @@ describe('prepare', () => {
let emitSpy;
let updatePathsSpy;
+ const PROJECT_DIR = 'platforms/android';
+
+ beforeAll(() => {
+ spyOn(CordovaGradleConfigParserFactory, 'create').and.returnValue(new MockCordovaGradleConfigParser(PROJECT_DIR));
+ });
+
beforeEach(() => {
prepare = rewire('../../lib/prepare');
@@ -912,9 +920,7 @@ describe('prepare', () => {
}),
setVersionName: jasmine.createSpy('setVersionName').and.returnValue({
setVersionCode: jasmine.createSpy('setVersionCode').and.returnValue({
- setPackageId: jasmine.createSpy('setPackageId').and.returnValue({
- write: jasmine.createSpy('write')
- })
+ write: jasmine.createSpy('write')
})
})
}));
diff --git a/spec/unit/run.spec.js b/spec/unit/run.spec.js
index 3ed2f69f..93d76b2e 100644
--- a/spec/unit/run.spec.js
+++ b/spec/unit/run.spec.js
@@ -19,10 +19,19 @@
const rewire = require('rewire');
const builders = require('../../lib/builders/builders');
+const MockCordovaGradleConfigParser = require('./mocks/config/MockCordovaGradleConfigParser');
+const CordovaGradleConfigParser = require('../../lib/config/CordovaGradleConfigParser');
+const CordovaGradleConfigParserFactory = require('../../lib/config/CordovaGradleConfigParserFactory');
describe('run', () => {
let run;
+ const PROJECT_DIR = 'platforms/android';
+
+ beforeAll(() => {
+ spyOn(CordovaGradleConfigParserFactory, 'create').and.returnValue(new MockCordovaGradleConfigParser(PROJECT_DIR));
+ });
+
beforeEach(() => {
run = rewire('../../lib/run');
run.__set__({
@@ -84,7 +93,8 @@ describe('run', () => {
buildResults: {
buildType: 'debug',
apkPaths: ['fake.apk']
- }
+ },
+ cordovaGradleConfigParser: jasmine.any(CordovaGradleConfigParser)
}
);
});
diff --git a/spec/unit/target.spec.js b/spec/unit/target.spec.js
index e175c77a..5ae2090d 100644
--- a/spec/unit/target.spec.js
+++ b/spec/unit/target.spec.js
@@ -19,10 +19,18 @@
const rewire = require('rewire');
const { CordovaError } = require('cordova-common');
+const MockCordovaGradleConfigParser = require('./mocks/config/MockCordovaGradleConfigParser');
+const CordovaGradleConfigParserFactory = require('../../lib/config/CordovaGradleConfigParserFactory');
describe('target', () => {
let target;
+ const PROJECT_DIR = 'platforms/android';
+
+ beforeAll(() => {
+ spyOn(CordovaGradleConfigParserFactory, 'create').and.returnValue(new MockCordovaGradleConfigParser(PROJECT_DIR));
+ });
+
beforeEach(() => {
target = rewire('../../lib/target');
});
@@ -228,14 +236,18 @@ describe('target', () => {
describe('install', () => {
let AdbSpy;
let buildSpy;
- let installTarget, manifest, appSpec;
+ let installTarget, manifest, cordovaGradleConfigParser, appSpec;
beforeEach(() => {
installTarget = { id: 'emulator-5556', type: 'emulator', arch: 'atari' };
- manifest = jasmine.createSpyObj('manifestStub', ['getPackageId', 'getActivity']);
+ manifest = jasmine.createSpyObj('manifestStub', ['getActivity']);
manifest.getActivity.and.returnValue(jasmine.createSpyObj('Activity', ['getName']));
- appSpec = { manifest, buildResults: {} };
+
+ cordovaGradleConfigParser = jasmine.createSpyObj('cordovaGradleConfigParserStub', ['getPackageName']);
+ cordovaGradleConfigParser.getPackageName.and.returnValue('unittestapp');
+
+ appSpec = { manifest, buildResults: {}, cordovaGradleConfigParser };
buildSpy = jasmine.createSpyObj('build', ['findBestApkForArchitecture']);
target.__set__('build', buildSpy);
@@ -267,7 +279,7 @@ describe('target', () => {
const apkPath = 'my/apk/path/app.apk';
buildSpy.findBestApkForArchitecture.and.returnValue(apkPath);
- return target.install(installTarget, { manifest, buildResults }).then(() => {
+ return target.install(installTarget, { manifest, buildResults, cordovaGradleConfigParser: CordovaGradleConfigParserFactory.create(PROJECT_DIR) }).then(() => {
expect(buildSpy.findBestApkForArchitecture).toHaveBeenCalledWith(buildResults, installTarget.arch);
expect(AdbSpy.install.calls.argsFor(0)[1]).toBe(apkPath);
@@ -308,7 +320,7 @@ describe('target', () => {
it('should start the newly installed app on the device', () => {
const packageId = 'unittestapp';
const activityName = 'TestActivity';
- manifest.getPackageId.and.returnValue(packageId);
+ cordovaGradleConfigParser.getPackageName.and.returnValue(packageId);
manifest.getActivity().getName.and.returnValue(activityName);
return target.install(installTarget, appSpec).then(() => {
diff --git a/templates/project/AndroidManifest.xml b/templates/project/AndroidManifest.xml
index bf4a9a4d..06b7fd6c 100644
--- a/templates/project/AndroidManifest.xml
+++ b/templates/project/AndroidManifest.xml
@@ -18,7 +18,9 @@
under the License.
-->
+ android:versionName="1.0"
+ android:versionCode="1"
+ android:hardwareAccelerated="true">