-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed arm64 string, pushed version to v1.0.2
- Loading branch information
Showing
3 changed files
with
134 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-abi-filter" version="1.0.1"> | ||
<name>cordova-plugin-abi-filter</name> | ||
<description>Filter desired platform ABIs from your project build.</description> | ||
<license>Apache 2.0 License</license> | ||
<author>Paul Stresow</author> | ||
<keywords>cordova,android,build,abi,armeabi,armeabi-v7a,arm64-v8a,x86,x86_64</keywords> | ||
|
||
<engines> | ||
<engine name="cordova" version=">=7.0.0" /> | ||
</engines> | ||
|
||
<!-- Default - contains all platform abis --> | ||
<preference name="ABI_FILTER" default="armeabi-v7a,armeabi-v8a,x86,x86_64" /> | ||
|
||
<platform name="android"> | ||
<hook type="after_plugin_add" src="scripts/apply.js" /> | ||
<hook type="before_prepare" src="scripts/apply.js" /> | ||
<framework src="src/android/build-extras.gradle" custom="true" type="gradleReference" /> | ||
</platform> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-abi-filter" version="1.0.2"> | ||
<name>cordova-plugin-abi-filter</name> | ||
<description>Filter desired platform ABIs from your project build.</description> | ||
<license>Apache 2.0 License</license> | ||
<author>Paul Stresow</author> | ||
<keywords>cordova,android,build,abi,armeabi,armeabi-v7a,arm64-v8a,x86,x86_64</keywords> | ||
|
||
<engines> | ||
<engine name="cordova" version=">=7.0.0" /> | ||
</engines> | ||
|
||
<!-- Default - contains all platform abis --> | ||
<preference name="ABI_FILTER" default="armeabi-v7a,arm64-v8a,x86,x86_64" /> | ||
|
||
<platform name="android"> | ||
<hook type="after_plugin_add" src="scripts/apply.js" /> | ||
<hook type="before_prepare" src="scripts/apply.js" /> | ||
<framework src="src/android/build-extras.gradle" custom="true" type="gradleReference" /> | ||
</platform> | ||
</plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,114 @@ | ||
module.exports = function (context) { | ||
//only procecss android platform | ||
if (!context.opts.cordova.platforms.includes('android')) { | ||
return | ||
} | ||
|
||
console.log('ABI Filter applying changes...') | ||
|
||
//Requirements | ||
const Q = context.requireCordovaModule('q') | ||
const deferral = new Q.defer() | ||
|
||
const common = context.requireCordovaModule('cordova-common') | ||
const utils = context.requireCordovaModule('cordova-lib/src/cordova/util') | ||
const fs = context.requireCordovaModule('fs') | ||
const path = context.requireCordovaModule('path') | ||
const readline = context.requireCordovaModule('readline') | ||
const os = context.requireCordovaModule('os') | ||
|
||
const projectRoot = context.opts.projectRoot | ||
|
||
const gradleFilePath = path.join(projectRoot, 'platforms/android/' + context.opts.plugin.id) | ||
|
||
//helper funcs | ||
function searchFilesByFilterRecursive(startPath, filter, callback) { | ||
|
||
if (!fs.existsSync(startPath)) { | ||
console.log("no dir ", startPath) | ||
deferral.reject(new Error("folder " + startPath + " does not exist")) | ||
} | ||
|
||
var files = fs.readdirSync(startPath) | ||
for (var i = 0; i < files.length; i++) { | ||
var filename = path.join(startPath, files[i]) | ||
var stat = fs.lstatSync(filename) | ||
if (stat.isDirectory()) { | ||
searchFilesByFilterRecursive(filename, filter, callback) //recurse | ||
} | ||
else if (filter.test(filename)) callback(filename) | ||
} | ||
} | ||
|
||
//prefix changes according to project name - just searching for the file. folder is known anyway | ||
searchFilesByFilterRecursive(gradleFilePath, /\-build-extras.gradle$/, (filepath) => { | ||
|
||
//default values | ||
var abi_values = "armeabi-v7a,armeabi-v8a,x86,x86_64" | ||
|
||
//Variables can come from 3 different places | ||
|
||
try{ | ||
//plugin.xml | ||
//Prio 3 - default if user did not specify cli args or if plugin is just added | ||
if (context.opts.plugin.pluginInfo.getPreferences().ABI_FILTER) { | ||
abi_values = context.opts.plugin.pluginInfo.getPreferences().ABI_FILTER | ||
} | ||
|
||
//CLI Arg | ||
//Prio 2 - is present when plugin is added with --variable ABI_FILTER="a|b|c" | ||
if (context.opts.cli_variables && context.opts.cli_variables.ABI_FILTER) { | ||
abi_values = context.opts.cli_variables.ABI_FILTER | ||
} | ||
|
||
//config.xml | ||
//Prio 1 - plugin was already added or user added key to config.xml manually | ||
const configFile = new common.ConfigParser(utils.projectConfig(projectRoot)) | ||
if (configFile.getPlugin(context.opts.plugin.id).variables.ABI_FILTER) { | ||
abi_values = configFile.getPlugin(context.opts.plugin.id).variables.ABI_FILTER | ||
} | ||
} catch(error){ | ||
console.warn("Using defaults: " + abi_values); | ||
} | ||
|
||
//parse them values to a gradle readable string | ||
var abi_values_parsed = ""; | ||
let abi_arr = abi_values.split(","); | ||
for (var i = 0; i < abi_arr.length; ++i) { | ||
abi_values_parsed += '"' + abi_arr[i] + '"' + (abi_arr.length - 1 === i ? "" : ",") | ||
} | ||
|
||
//find the line "abiFilters" | ||
const line_key = "abiFilters" | ||
var replacement_line = " abiFilters " + abi_values_parsed | ||
var replacement_file = "" | ||
|
||
//read gradle file from project | ||
var reader = readline.createInterface({ | ||
input: fs.createReadStream(filepath) | ||
}) | ||
|
||
reader.on('line', (line) => { | ||
if(line.trim().includes(line_key)){ | ||
replacement_file += replacement_line + os.EOL | ||
} else { | ||
replacement_file += line + os.EOL | ||
} | ||
}) | ||
|
||
reader.on('close', () => { | ||
|
||
//save (override) gradle file from project | ||
fs.writeFile(filepath, replacement_file, {encoding:'utf8',flag:'w'}, function(err) { | ||
if(err) { | ||
deferral.reject(err) | ||
} | ||
|
||
console.log("Applied ABI-Filters: " + abi_values) | ||
deferral.resolve() | ||
}); | ||
}) | ||
}) | ||
|
||
return deferral.promise | ||
module.exports = function (context) { | ||
//only procecss android platform | ||
if (!context.opts.cordova.platforms.includes('android')) { | ||
return | ||
} | ||
|
||
console.log('ABI Filter applying changes...') | ||
|
||
//Requirements | ||
const Q = context.requireCordovaModule('q') | ||
const deferral = new Q.defer() | ||
|
||
const common = context.requireCordovaModule('cordova-common') | ||
const utils = context.requireCordovaModule('cordova-lib/src/cordova/util') | ||
const fs = context.requireCordovaModule('fs') | ||
const path = context.requireCordovaModule('path') | ||
const readline = context.requireCordovaModule('readline') | ||
const os = context.requireCordovaModule('os') | ||
|
||
const projectRoot = context.opts.projectRoot | ||
|
||
const gradleFilePath = path.join(projectRoot, 'platforms/android/' + context.opts.plugin.id) | ||
|
||
//helper funcs | ||
function searchFilesByFilterRecursive(startPath, filter, callback) { | ||
|
||
if (!fs.existsSync(startPath)) { | ||
console.log("no dir ", startPath) | ||
deferral.reject(new Error("folder " + startPath + " does not exist")) | ||
} | ||
|
||
var files = fs.readdirSync(startPath) | ||
for (var i = 0; i < files.length; i++) { | ||
var filename = path.join(startPath, files[i]) | ||
var stat = fs.lstatSync(filename) | ||
if (stat.isDirectory()) { | ||
searchFilesByFilterRecursive(filename, filter, callback) //recurse | ||
} | ||
else if (filter.test(filename)) callback(filename) | ||
} | ||
} | ||
|
||
//prefix changes according to project name - just searching for the file. folder is known anyway | ||
searchFilesByFilterRecursive(gradleFilePath, /\-build-extras.gradle$/, (filepath) => { | ||
|
||
//default values | ||
var abi_values = "armeabi-v7a,arm64-v8a,x86,x86_64" | ||
|
||
//Variables can come from 3 different places | ||
|
||
try{ | ||
//plugin.xml | ||
//Prio 3 - default if user did not specify cli args or if plugin is just added | ||
if (context.opts.plugin.pluginInfo.getPreferences().ABI_FILTER) { | ||
abi_values = context.opts.plugin.pluginInfo.getPreferences().ABI_FILTER | ||
} | ||
|
||
//CLI Arg | ||
//Prio 2 - is present when plugin is added with --variable ABI_FILTER="a|b|c" | ||
if (context.opts.cli_variables && context.opts.cli_variables.ABI_FILTER) { | ||
abi_values = context.opts.cli_variables.ABI_FILTER | ||
} | ||
|
||
//config.xml | ||
//Prio 1 - plugin was already added or user added key to config.xml manually | ||
const configFile = new common.ConfigParser(utils.projectConfig(projectRoot)) | ||
if (configFile.getPlugin(context.opts.plugin.id).variables.ABI_FILTER) { | ||
abi_values = configFile.getPlugin(context.opts.plugin.id).variables.ABI_FILTER | ||
} | ||
} catch(error){ | ||
console.warn("Using defaults: " + abi_values); | ||
} | ||
|
||
//parse them values to a gradle readable string | ||
var abi_values_parsed = ""; | ||
let abi_arr = abi_values.split(","); | ||
for (var i = 0; i < abi_arr.length; ++i) { | ||
abi_values_parsed += '"' + abi_arr[i] + '"' + (abi_arr.length - 1 === i ? "" : ",") | ||
} | ||
|
||
//find the line "abiFilters" | ||
const line_key = "abiFilters" | ||
var replacement_line = " abiFilters " + abi_values_parsed | ||
var replacement_file = "" | ||
|
||
//read gradle file from project | ||
var reader = readline.createInterface({ | ||
input: fs.createReadStream(filepath) | ||
}) | ||
|
||
reader.on('line', (line) => { | ||
if(line.trim().includes(line_key)){ | ||
replacement_file += replacement_line + os.EOL | ||
} else { | ||
replacement_file += line + os.EOL | ||
} | ||
}) | ||
|
||
reader.on('close', () => { | ||
|
||
//save (override) gradle file from project | ||
fs.writeFile(filepath, replacement_file, {encoding:'utf8',flag:'w'}, function(err) { | ||
if(err) { | ||
deferral.reject(err) | ||
} | ||
|
||
console.log("Applied ABI-Filters: " + abi_values) | ||
deferral.resolve() | ||
}); | ||
}) | ||
}) | ||
|
||
return deferral.promise | ||
} |