cordova通过platforms\android\cordova\lib\builders\StudioBuilder.js 生成settings.gradle文件。
// 通过遍历subProjects生成
var settingsGradlePaths = subProjects.map(function (p) {
var realDir = p.replace(/[/\\]/g, ':');
var libName = realDir.replace(name + '-', '');
var str = 'include ":' + libName + '"\n';
if (realDir.indexOf(name + '-') !== -1) {
str += 'project(":' + libName + '").projectDir = new File("' + p + '")\n';
}
return str;
});
var propertiesObj = this.readProjectProperties();
var subProjects = propertiesObj.libs;
// readProjectProperties 方法生成subProjects
StudioBuilder.prototype.readProjectProperties = function () {
function findAllUniq (data, r) {
var s = {};
var m;
while ((m = r.exec(data))) {
s[m[1]] = 1;
}
return Object.keys(s);
}
var data = fs.readFileSync(path.join(this.root, 'project.properties'), 'utf8');
return {
libs: findAllUniq(data, /^\s*android\.library\.reference\.\d+=(.*)(?:\s|$)/mg),
gradleIncludes: findAllUniq(data, /^\s*cordova\.gradle\.include\.\d+=(.*)(?:\s|$)/mg),
systemLibs: findAllUniq(data, /^\s*cordova\.system\.library\.\d+=(.*)(?:\s|$)/mg)
};
};
? ? var data = fs.readFileSync(path.join(this.root, 'project.properties'), 'utf8');
project.properties中配置如下即可生成需要的module
android.library.reference.1=app
android.library.reference.2=module1
?
|