mirror of
https://github.com/apache/cordova-android.git
synced 2025-03-04 00:13:20 +08:00
CB-13830: Add handlers for plugins that use non-Java source files, such as Camera
This commit is contained in:
parent
e32bcd88aa
commit
ea6477f4d3
2
bin/templates/cordova/Api.js
vendored
2
bin/templates/cordova/Api.js
vendored
@ -248,7 +248,7 @@ Api.prototype.addPlugin = function (plugin, installOptions) {
|
|||||||
}).then(function () {
|
}).then(function () {
|
||||||
if (plugin.getFrameworks(this.platform).length === 0) return;
|
if (plugin.getFrameworks(this.platform).length === 0) return;
|
||||||
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
selfEvents.emit('verbose', 'Updating build files since android plugin contained <framework>');
|
||||||
// This should pick the correct builder, not just get gradle
|
// This should pick the correct builder, not just get gradle
|
||||||
require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
|
require('./lib/builders/builders').getBuilder(this.builder).prepBuildFiles();
|
||||||
}.bind(this))
|
}.bind(this))
|
||||||
// CB-11022 Return truthy value to prevent running prepare after
|
// CB-11022 Return truthy value to prevent running prepare after
|
||||||
|
110
bin/templates/cordova/lib/builders/StudioBuilder.js
vendored
110
bin/templates/cordova/lib/builders/StudioBuilder.js
vendored
@ -215,28 +215,28 @@ StudioBuilder.prototype.prepBuildFiles = function () {
|
|||||||
StudioBuilder.prototype.prepEnv = function (opts) {
|
StudioBuilder.prototype.prepEnv = function (opts) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return check_reqs.check_gradle()
|
return check_reqs.check_gradle()
|
||||||
.then(function (gradlePath) {
|
.then(function (gradlePath) {
|
||||||
return self.runGradleWrapper(gradlePath);
|
return self.runGradleWrapper(gradlePath);
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return self.prepBuildFiles();
|
return self.prepBuildFiles();
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
// If the gradle distribution URL is set, make sure it points to version we want.
|
// If the gradle distribution URL is set, make sure it points to version we want.
|
||||||
// If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
|
// If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
|
||||||
// For some reason, using ^ and $ don't work. This does the job, though.
|
// For some reason, using ^ and $ don't work. This does the job, though.
|
||||||
var distributionUrlRegex = /distributionUrl.*zip/;
|
var distributionUrlRegex = /distributionUrl.*zip/;
|
||||||
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-4.1-all.zip';
|
var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-4.1-all.zip';
|
||||||
var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
|
var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
|
||||||
shell.chmod('u+w', gradleWrapperPropertiesPath);
|
shell.chmod('u+w', gradleWrapperPropertiesPath);
|
||||||
shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
|
shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);
|
||||||
|
|
||||||
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
|
var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
|
||||||
var propertiesFilePath = path.join(self.root, propertiesFile);
|
var propertiesFilePath = path.join(self.root, propertiesFile);
|
||||||
if (opts.packageInfo) {
|
if (opts.packageInfo) {
|
||||||
fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
|
fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
|
||||||
} else if (isAutoGenerated(propertiesFilePath)) {
|
} else if (isAutoGenerated(propertiesFilePath)) {
|
||||||
shell.rm('-f', propertiesFilePath);
|
shell.rm('-f', propertiesFilePath);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -248,33 +248,33 @@ StudioBuilder.prototype.build = function (opts) {
|
|||||||
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
|
var args = this.getArgs(opts.buildType === 'debug' ? 'debug' : 'release', opts);
|
||||||
|
|
||||||
return spawn(wrapper, args, {stdio: 'pipe'})
|
return spawn(wrapper, args, {stdio: 'pipe'})
|
||||||
.progress(function (stdio) {
|
.progress(function (stdio) {
|
||||||
if (stdio.stderr) {
|
if (stdio.stderr) {
|
||||||
/*
|
/*
|
||||||
* Workaround for the issue with Java printing some unwanted information to
|
* Workaround for the issue with Java printing some unwanted information to
|
||||||
* stderr instead of stdout.
|
* stderr instead of stdout.
|
||||||
* This function suppresses 'Picked up _JAVA_OPTIONS' message from being
|
* This function suppresses 'Picked up _JAVA_OPTIONS' message from being
|
||||||
* printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
|
* printed to stderr. See https://issues.apache.org/jira/browse/CB-9971 for
|
||||||
* explanation.
|
* explanation.
|
||||||
*/
|
*/
|
||||||
var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
|
var suppressThisLine = /^Picked up _JAVA_OPTIONS: /i.test(stdio.stderr.toString());
|
||||||
if (suppressThisLine) {
|
if (suppressThisLine) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
process.stderr.write(stdio.stderr);
|
||||||
|
} else {
|
||||||
|
process.stdout.write(stdio.stdout);
|
||||||
}
|
}
|
||||||
process.stderr.write(stdio.stderr);
|
}).catch(function (error) {
|
||||||
} else {
|
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
|
||||||
process.stdout.write(stdio.stdout);
|
return check_reqs.check_android_target(error).then(function () {
|
||||||
}
|
// If due to some odd reason - check_android_target succeeds
|
||||||
}).catch(function (error) {
|
// we should still fail here.
|
||||||
if (error.toString().indexOf('failed to find target with hash string') >= 0) {
|
return Q.reject(error);
|
||||||
return check_reqs.check_android_target(error).then(function () {
|
});
|
||||||
// If due to some odd reason - check_android_target succeeds
|
}
|
||||||
// we should still fail here.
|
return Q.reject(error);
|
||||||
return Q.reject(error);
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
return Q.reject(error);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
StudioBuilder.prototype.clean = function (opts) {
|
StudioBuilder.prototype.clean = function (opts) {
|
||||||
@ -284,16 +284,16 @@ StudioBuilder.prototype.clean = function (opts) {
|
|||||||
return Q().then(function () {
|
return Q().then(function () {
|
||||||
return spawn(wrapper, args, {stdio: 'inherit'});
|
return spawn(wrapper, args, {stdio: 'inherit'});
|
||||||
})
|
})
|
||||||
.then(function () {
|
.then(function () {
|
||||||
shell.rm('-rf', path.join(builder.root, 'out'));
|
shell.rm('-rf', path.join(builder.root, 'out'));
|
||||||
|
|
||||||
['debug', 'release'].forEach(function (config) {
|
['debug', 'release'].forEach(function (config) {
|
||||||
var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
|
var propertiesFilePath = path.join(builder.root, config + SIGNING_PROPERTIES);
|
||||||
if (isAutoGenerated(propertiesFilePath)) {
|
if (isAutoGenerated(propertiesFilePath)) {
|
||||||
shell.rm('-f', propertiesFilePath);
|
shell.rm('-f', propertiesFilePath);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = StudioBuilder;
|
module.exports = StudioBuilder;
|
||||||
|
33
bin/templates/cordova/lib/pluginHandlers.js
vendored
33
bin/templates/cordova/lib/pluginHandlers.js
vendored
@ -34,15 +34,7 @@ var handlers = {
|
|||||||
// a later plugins release. This is for legacy plugins to work with Cordova.
|
// a later plugins release. This is for legacy plugins to work with Cordova.
|
||||||
|
|
||||||
if (options && options.android_studio === true) {
|
if (options && options.android_studio === true) {
|
||||||
// If a Java file is using the new directory structure, don't penalize it
|
dest = studioPathRemap(obj);
|
||||||
if (!obj.targetDir.includes('app/src/main')) {
|
|
||||||
if (obj.src.endsWith('.java')) {
|
|
||||||
dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
|
||||||
} else if (obj.src.endsWith('.xml')) {
|
|
||||||
// We are making a huge assumption here that XML files will be going to res/xml or values/xml
|
|
||||||
dest = path.join('app/src/main', obj.targetDir, path.basename(obj.src));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options && options.force) {
|
if (options && options.force) {
|
||||||
@ -55,10 +47,16 @@ var handlers = {
|
|||||||
var dest = path.join(obj.targetDir, path.basename(obj.src));
|
var dest = path.join(obj.targetDir, path.basename(obj.src));
|
||||||
|
|
||||||
if (options && options.android_studio === true) {
|
if (options && options.android_studio === true) {
|
||||||
dest = path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
dest = studioPathRemap(obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteJava(project.projectDir, dest);
|
// TODO: Add Koltin extension to uninstall, since they are handled like Java files
|
||||||
|
if (obj.src.endsWith('java')) {
|
||||||
|
deleteJava(project.projectDir, dest);
|
||||||
|
} else {
|
||||||
|
// Just remove the file, not the whole parent directory
|
||||||
|
removeFile(project.projectDir, dest);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'lib-file': {
|
'lib-file': {
|
||||||
@ -318,3 +316,16 @@ function removeFileAndParents (baseDir, destFile, stopper) {
|
|||||||
function generateAttributeError (attribute, element, id) {
|
function generateAttributeError (attribute, element, id) {
|
||||||
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
|
return 'Required attribute "' + attribute + '" not specified in <' + element + '> element from plugin: ' + id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function studioPathRemap (obj) {
|
||||||
|
// If a Java file is using the new directory structure, don't penalize it
|
||||||
|
if (!obj.targetDir.includes('app/src/main')) {
|
||||||
|
if (obj.src.endsWith('.java')) {
|
||||||
|
return path.join('app/src/main/java', obj.targetDir.substring(4), path.basename(obj.src));
|
||||||
|
} else if (obj.src.endsWith('.xml')) {
|
||||||
|
// We are making a huge assumption here that XML files will be going to res/xml or values/xml
|
||||||
|
return path.join('app/src/main', obj.targetDir, path.basename(obj.src));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user