mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 07:02:51 +08:00
Merge pull request #668 from brodybits/revert-pr-664
Revert "Remove uses-sdk from AndroidManifest.xml (#664)"
This commit is contained in:
commit
719acd3ab1
@ -321,6 +321,7 @@ exports.create = function (project_path, config, options, events) {
|
|||||||
|
|
||||||
var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
|
var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
|
||||||
manifest.setPackageId(package_name)
|
manifest.setPackageId(package_name)
|
||||||
|
.setTargetSdkVersion(target_api.split('-')[1])
|
||||||
.getActivity().setName(safe_activity_name);
|
.getActivity().setName(safe_activity_name);
|
||||||
|
|
||||||
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
|
var manifest_path = path.join(app_path, 'AndroidManifest.xml');
|
||||||
|
30
bin/templates/cordova/lib/AndroidManifest.js
vendored
30
bin/templates/cordova/lib/AndroidManifest.js
vendored
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
|
var et = require('elementtree');
|
||||||
var xml = require('cordova-common').xmlHelpers;
|
var xml = require('cordova-common').xmlHelpers;
|
||||||
|
|
||||||
var DEFAULT_ORIENTATION = 'default';
|
var DEFAULT_ORIENTATION = 'default';
|
||||||
@ -97,6 +98,31 @@ AndroidManifest.prototype.getActivity = function () {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
['minSdkVersion', 'maxSdkVersion', 'targetSdkVersion'].forEach(function (sdkPrefName) {
|
||||||
|
// Copy variable reference to avoid closure issues
|
||||||
|
var prefName = sdkPrefName;
|
||||||
|
|
||||||
|
AndroidManifest.prototype['get' + capitalize(prefName)] = function () {
|
||||||
|
var usesSdk = this.doc.getroot().find('./uses-sdk');
|
||||||
|
return usesSdk && usesSdk.attrib['android:' + prefName];
|
||||||
|
};
|
||||||
|
|
||||||
|
AndroidManifest.prototype['set' + capitalize(prefName)] = function (prefValue) {
|
||||||
|
var usesSdk = this.doc.getroot().find('./uses-sdk');
|
||||||
|
|
||||||
|
if (!usesSdk && prefValue) { // if there is no required uses-sdk element, we should create it first
|
||||||
|
usesSdk = new et.Element('uses-sdk');
|
||||||
|
this.doc.getroot().append(usesSdk);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (prefValue) {
|
||||||
|
usesSdk.attrib['android:' + prefName] = prefValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
AndroidManifest.prototype.getDebuggable = function () {
|
AndroidManifest.prototype.getDebuggable = function () {
|
||||||
return this.doc.getroot().find('./application').attrib['android:debuggable'] === 'true';
|
return this.doc.getroot().find('./application').attrib['android:debuggable'] === 'true';
|
||||||
};
|
};
|
||||||
@ -124,3 +150,7 @@ AndroidManifest.prototype.write = function (destPath) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = AndroidManifest;
|
module.exports = AndroidManifest;
|
||||||
|
|
||||||
|
function capitalize (str) {
|
||||||
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
|
}
|
||||||
|
3
bin/templates/cordova/lib/prepare.js
vendored
3
bin/templates/cordova/lib/prepare.js
vendored
@ -199,6 +199,9 @@ function updateProjectAccordingTo (platformConfig, locations) {
|
|||||||
manifest.setVersionName(platformConfig.version())
|
manifest.setVersionName(platformConfig.version())
|
||||||
.setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
|
.setVersionCode(platformConfig.android_versionCode() || default_versionCode(platformConfig.version()))
|
||||||
.setPackageId(androidPkgName)
|
.setPackageId(androidPkgName)
|
||||||
|
.setMinSdkVersion(platformConfig.getPreference('android-minSdkVersion', 'android'))
|
||||||
|
.setMaxSdkVersion(platformConfig.getPreference('android-maxSdkVersion', 'android'))
|
||||||
|
.setTargetSdkVersion(platformConfig.getPreference('android-targetSdkVersion', 'android'))
|
||||||
.write();
|
.write();
|
||||||
|
|
||||||
// Java file paths shouldn't be hard coded
|
// Java file paths shouldn't be hard coded
|
||||||
|
@ -31,6 +31,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"android-versions": "^1.3.0",
|
"android-versions": "^1.3.0",
|
||||||
"cordova-common": "^3.1.0",
|
"cordova-common": "^3.1.0",
|
||||||
|
"elementtree": "^0.1.7",
|
||||||
"nopt": "^4.0.1",
|
"nopt": "^4.0.1",
|
||||||
"properties-parser": "^0.3.1",
|
"properties-parser": "^0.3.1",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
|
@ -190,6 +190,78 @@ describe('AndroidManifest', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('minSdkVersion', () => {
|
||||||
|
it('should get minSdkVersion', () => {
|
||||||
|
expect(manifest.getMinSdkVersion()).toBe(MIN_SDK_VERSION);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set minSdkVersion', () => {
|
||||||
|
const newMinSdkVersion = `${MIN_SDK_VERSION}111`;
|
||||||
|
manifest.setMinSdkVersion(newMinSdkVersion);
|
||||||
|
expect(manifest.getMinSdkVersion()).toBe(newMinSdkVersion);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the uses-sdk node if it does not exist when setting minSdkVersion', () => {
|
||||||
|
const root = manifest.doc.getroot();
|
||||||
|
root.remove(root.find('./uses-sdk'));
|
||||||
|
|
||||||
|
expect(root.find('./uses-sdk')).toBe(null);
|
||||||
|
|
||||||
|
manifest.setMinSdkVersion(1);
|
||||||
|
|
||||||
|
expect(root.find('./uses-sdk')).not.toBe(null);
|
||||||
|
expect(manifest.getMinSdkVersion()).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('maxSdkVersion', () => {
|
||||||
|
it('should get maxSdkVersion', () => {
|
||||||
|
expect(manifest.getMaxSdkVersion()).toBe(MAX_SDK_VERSION);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set maxSdkVersion', () => {
|
||||||
|
const newMaxSdkVersion = `${MAX_SDK_VERSION}999`;
|
||||||
|
manifest.setMaxSdkVersion(newMaxSdkVersion);
|
||||||
|
expect(manifest.getMaxSdkVersion()).toBe(newMaxSdkVersion);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the uses-sdk node if it does not exist when setting maxSdkVersion', () => {
|
||||||
|
const root = manifest.doc.getroot();
|
||||||
|
root.remove(root.find('./uses-sdk'));
|
||||||
|
|
||||||
|
expect(root.find('./uses-sdk')).toBe(null);
|
||||||
|
|
||||||
|
manifest.setMaxSdkVersion(1);
|
||||||
|
|
||||||
|
expect(root.find('./uses-sdk')).not.toBe(null);
|
||||||
|
expect(manifest.getMaxSdkVersion()).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('targetSdkVersion', () => {
|
||||||
|
it('should get targetSdkVersion', () => {
|
||||||
|
expect(manifest.getTargetSdkVersion()).toBe(TARGET_SDK_VERSION);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set targetSdkVersion', () => {
|
||||||
|
const newTargetSdkVersion = `${TARGET_SDK_VERSION}555`;
|
||||||
|
manifest.setTargetSdkVersion(newTargetSdkVersion);
|
||||||
|
expect(manifest.getTargetSdkVersion()).toBe(newTargetSdkVersion);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the uses-sdk node if it does not exist when setting targetSdkVersion', () => {
|
||||||
|
const root = manifest.doc.getroot();
|
||||||
|
root.remove(root.find('./uses-sdk'));
|
||||||
|
|
||||||
|
expect(root.find('./uses-sdk')).toBe(null);
|
||||||
|
|
||||||
|
manifest.setTargetSdkVersion(1);
|
||||||
|
|
||||||
|
expect(root.find('./uses-sdk')).not.toBe(null);
|
||||||
|
expect(manifest.getTargetSdkVersion()).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('debuggable', () => {
|
describe('debuggable', () => {
|
||||||
it('should get debuggable', () => {
|
it('should get debuggable', () => {
|
||||||
expect(manifest.getDebuggable()).toBe(true);
|
expect(manifest.getDebuggable()).toBe(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user