123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
-
-
-
-
- const VERSION = '9.1.0';
-
- var path = require('path');
-
- var AndroidProject = require('./lib/AndroidProject');
- var PluginManager = require('cordova-common').PluginManager;
-
- var CordovaLogger = require('cordova-common').CordovaLogger;
- var selfEvents = require('cordova-common').events;
- var ConfigParser = require('cordova-common').ConfigParser;
- const prepare = require('./lib/prepare').prepare;
-
- var PLATFORM = 'android';
-
- function setupEvents (externalEventEmitter) {
- if (externalEventEmitter) {
-
- selfEvents.forwardEventsTo(externalEventEmitter);
- return externalEventEmitter;
- }
-
-
-
- CordovaLogger.get().subscribe(selfEvents);
- return selfEvents;
- }
-
-
- class Api {
- constructor (platform, platformRootDir, events) {
- this.platform = PLATFORM;
- this.root = path.resolve(__dirname, '..');
-
- setupEvents(events);
-
- const appMain = path.join(this.root, 'app', 'src', 'main');
- const appRes = path.join(appMain, 'res');
-
- this.locations = {
- root: this.root,
- www: path.join(appMain, 'assets', 'www'),
- res: appRes,
- platformWww: path.join(this.root, 'platform_www'),
- configXml: path.join(appRes, 'xml', 'config.xml'),
- defaultConfigXml: path.join(this.root, 'cordova', 'defaults.xml'),
- strings: path.join(appRes, 'values', 'strings.xml'),
- manifest: path.join(appMain, 'AndroidManifest.xml'),
- build: path.join(this.root, 'build'),
- javaSrc: path.join(appMain, 'java')
- };
-
- this._builder = require('./lib/builders/builders').getBuilder(this.root);
- }
-
-
-
- getPlatformInfo () {
- var result = {};
- result.locations = this.locations;
- result.root = this.root;
- result.name = this.platform;
- result.version = Api.version();
- result.projectConfig = this._config;
-
- return result;
- }
-
-
-
- prepare (cordovaProject, prepareOptions) {
- cordovaProject.projectConfig = new ConfigParser(cordovaProject.locations.rootConfigXml || cordovaProject.projectConfig.path);
-
- return prepare.call(this, cordovaProject, prepareOptions);
- }
-
-
-
- addPlugin (plugin, installOptions) {
- var project = AndroidProject.getProjectFile(this.root);
- var self = this;
-
- installOptions = installOptions || {};
- installOptions.variables = installOptions.variables || {};
-
- if (!installOptions.variables.PACKAGE_NAME) {
- installOptions.variables.PACKAGE_NAME = project.getPackageName();
- }
-
- return Promise.resolve().then(function () {
- return PluginManager.get(self.platform, self.locations, project).addPlugin(plugin, installOptions);
- }).then(function () {
- if (plugin.getFrameworks(this.platform).length === 0) return;
- selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
-
- this._builder.prepBuildFiles();
- }.bind(this))
-
- .then(() => true);
- }
-
-
-
- removePlugin (plugin, uninstallOptions) {
- var project = AndroidProject.getProjectFile(this.root);
-
- if (uninstallOptions && uninstallOptions.usePlatformWww === true) {
- uninstallOptions.usePlatformWww = false;
- }
-
- return PluginManager.get(this.platform, this.locations, project)
- .removePlugin(plugin, uninstallOptions)
- .then(function () {
- if (plugin.getFrameworks(this.platform).length === 0) return;
-
- selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
- this._builder.prepBuildFiles();
- }.bind(this))
-
- .then(() => true);
- }
-
-
-
- build (buildOptions) {
- var self = this;
-
- return require('./lib/check_reqs').run().then(function () {
- return require('./lib/build').run.call(self, buildOptions);
- }).then(function (buildResults) {
-
- return buildResults.paths.map(function (apkPath) {
- return {
- buildType: buildResults.buildType,
- buildMethod: buildResults.buildMethod,
- path: apkPath,
- type: path.extname(apkPath).replace(/\./g, '')
- };
- });
- });
- }
-
-
-
- run (runOptions) {
- var self = this;
- return require('./lib/check_reqs').run().then(function () {
- return require('./lib/run').run.call(self, runOptions);
- });
- }
-
-
-
- clean (cleanOptions) {
- var self = this;
-
- if (typeof cleanOptions === 'undefined') {
- cleanOptions = {};
- }
-
- return require('./lib/check_reqs').run().then(function () {
- return require('./lib/build').runClean.call(self, cleanOptions);
- }).then(function () {
- return require('./lib/prepare').clean.call(self, cleanOptions);
- });
- }
-
-
-
- requirements () {
- return require('./lib/check_reqs').check_all();
- }
-
-
-
- static createPlatform (destination, config, options, events) {
- events = setupEvents(events);
- var result;
- try {
- result = require('../../lib/create').create(destination, config, options, events).then(function (destination) {
- return new Api(PLATFORM, destination, events);
- });
- } catch (e) {
- events.emit('error', 'createPlatform is not callable from the android project API.');
- throw (e);
- }
- return result;
- }
-
-
-
- static updatePlatform (destination, options, events) {
- events = setupEvents(events);
- var result;
- try {
- result = require('../../lib/create').update(destination, options, events).then(function (destination) {
- return new Api(PLATFORM, destination, events);
- });
- } catch (e) {
- events.emit('error', 'updatePlatform is not callable from the android project API, you will need to do this manually.');
- throw (e);
- }
- return result;
- }
-
- static version () {
- return VERSION;
- }
- }
-
- module.exports = Api;
|