Skip to content

Commit

Permalink
fixed arm64 string, pushed version to v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Ponsen committed May 8, 2019
1 parent bbe108e commit c4b4ee6
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 134 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-abi-filter",
"version": "1.0.1",
"version": "1.0.2",
"description": "Specify supported platform ABIs for your android build",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
Expand Down
40 changes: 20 additions & 20 deletions plugin.xml
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>
226 changes: 113 additions & 113 deletions scripts/apply.js
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
}

0 comments on commit c4b4ee6

Please sign in to comment.