Skip to content

Instantly share code, notes, and snippets.

@Cool04ek
Last active February 28, 2018 10:44
Show Gist options
  • Save Cool04ek/a4f1f8795494ede3fe6ac3cce053f967 to your computer and use it in GitHub Desktop.
Save Cool04ek/a4f1f8795494ede3fe6ac3cce053f967 to your computer and use it in GitHub Desktop.
const exec = require('shell-utils').exec;
const _ = require('lodash');
run();
function findFileRecursively(dir, filelist) {
var fs = fs || require('fs'),
files = fs.readdirSync(dir);
filelist = filelist || [];
files.forEach(function (file) {
if (fs.statSync(dir + '/' + file).isDirectory()) {
filelist = findFileRecursively(dir + '/' + file, filelist);
}
else {
filelist.push(dir + '/' + file);
}
});
return filelist;
};
function getReleaseApkPath() {
var fileList = findFileRecursively('./android/app/build/outputs', fileList);
for (path of fileList) {
if (_.includes(path, 'release') && _.includes(path, '.apk'))
return path;
}
throw new Error('no release apk');
}
function run() {
const apk = getReleaseApkPath();
exec.execSync(`apktool d ${apk} -s -o ./tmp`);
exec.execSync('react-native bundle --platform android --entry-file index.js --bundle-output ./tmp/assets/index.android.bundle --assets-dest ./tmp/res');
exec.execSync(`apktool b ./tmp -o result.apk`);
exec.execSync('jarsigner -keystore ~/Documents/test/keystore.jks -storepass qwerty123 -verbose result.apk key0');
exec.execSync('rm -rf tmp/');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment