Iterate on build_sky_apk.dart
This commit is contained in:
@@ -12,12 +12,77 @@ const String kAndroidPlatformVersion = '22';
|
||||
const String kKeystoreKeyName = "chromiumdebugkey";
|
||||
const String kKeystorePassword = "chromium";
|
||||
|
||||
const String kICUDataFile = 'icudtl.dat';
|
||||
class AssetBuilder {
|
||||
final Directory outDir;
|
||||
|
||||
void run(String command, List<String> args) {
|
||||
ProcessResult result = Process.runSync(command, args);
|
||||
stdout.write(result.stdout);
|
||||
stderr.write(result.stderr);
|
||||
Directory _assetDir;
|
||||
|
||||
AssetBuilder(this.outDir) {
|
||||
_assetDir = new Directory('${outDir.path}/assets');
|
||||
_assetDir.createSync(recursive: true);
|
||||
}
|
||||
|
||||
void add(File asset, String assetName) {
|
||||
asset.copySync('${_assetDir.path}/$assetName');
|
||||
}
|
||||
|
||||
Directory get directory => _assetDir;
|
||||
}
|
||||
|
||||
class ApkBuilder {
|
||||
final String androidSDK;
|
||||
|
||||
File _androidJar;
|
||||
File _aapt;
|
||||
File _zipalign;
|
||||
String _jarsigner;
|
||||
|
||||
ApkBuilder(this.androidSDK) {
|
||||
_androidJar = new File('$androidSDK/platforms/android-$kAndroidPlatformVersion/android.jar');
|
||||
|
||||
String buildTools = '$androidSDK/build-tools/$kBuildToolsVersion';
|
||||
_aapt = new File('$buildTools/aapt');
|
||||
_zipalign = new File('$buildTools/zipalign');
|
||||
_jarsigner = 'jarsigner';
|
||||
}
|
||||
|
||||
void package(File androidManifest, Directory assets, File outputApk) {
|
||||
_run(_aapt.path, [
|
||||
'package',
|
||||
'-M', androidManifest.path,
|
||||
'-A', assets.path,
|
||||
'-I', _androidJar.path,
|
||||
'-F', outputApk.path,
|
||||
]);
|
||||
}
|
||||
|
||||
void add(Directory base, String resource, File outputApk) {
|
||||
_run(_aapt.path, [
|
||||
'add', '-f', outputApk.absolute.path, resource,
|
||||
], workingDirectory: base.path);
|
||||
}
|
||||
|
||||
void sign(File keystore, String keystorePassword, String keyName, File outputApk) {
|
||||
_run(_jarsigner, [
|
||||
'-keystore', keystore.path,
|
||||
'-storepass', keystorePassword,
|
||||
outputApk.path,
|
||||
keyName,
|
||||
]);
|
||||
}
|
||||
|
||||
void align(File unalignedApk, File outputApk) {
|
||||
_run(_zipalign.path, ['4', unalignedApk.path, outputApk.path]);
|
||||
}
|
||||
|
||||
void _run(String command, List<String> args, { String workingDirectory }) {
|
||||
ProcessResult result = Process.runSync(
|
||||
command, args, workingDirectory: workingDirectory);
|
||||
if (result.exitCode == 0)
|
||||
return;
|
||||
stdout.write(result.stdout);
|
||||
stderr.write(result.stderr);
|
||||
}
|
||||
}
|
||||
|
||||
main(List<String> argv) async {
|
||||
@@ -28,41 +93,27 @@ main(List<String> argv) async {
|
||||
|
||||
ArgResults args = parser.parse(argv);
|
||||
|
||||
File unalignedApk = new File('out/Example.apk.unaligned');
|
||||
File finalApk = new File('out/Example.apk');
|
||||
File androidManifest = new File('artifacts/AndroidManifest.xml');
|
||||
File classesDex = new File('artifacts/classes.dex');
|
||||
File icuDataFile = new File('artifacts/$kICUDataFile');
|
||||
File keystore = new File('artifacts/chromium-debug.keystore');
|
||||
Directory artifacts = new Directory('artifacts');
|
||||
File keystore = new File('${artifacts.path}/chromium-debug.keystore');
|
||||
File androidManifest = new File('${artifacts.path}/AndroidManifest.xml');
|
||||
File icuData = new File('${artifacts.path}/assets/icudtl.dat');
|
||||
File appSkyx = new File(args['skyx']);
|
||||
|
||||
String androidSDK = args['android-sdk'];
|
||||
String buildTools = '$androidSDK/build-tools/$kBuildToolsVersion';
|
||||
String aapt = '$buildTools/aapt';
|
||||
String zipalign = '$buildTools/zipalign';
|
||||
File androidJar = new File('$androidSDK/platforms/android-$kAndroidPlatformVersion/android.jar');
|
||||
String jarsigner = 'jarsigner';
|
||||
Directory outDir = new Directory('out');
|
||||
outDir.createSync(recursive: true);
|
||||
|
||||
Directory assets = new Directory('out/assets');
|
||||
await assets.create(recursive: true);
|
||||
AssetBuilder assetBuilder = new AssetBuilder(outDir);
|
||||
assetBuilder.add(icuData, 'icudtl.dat');
|
||||
assetBuilder.add(appSkyx, 'app.skyx');
|
||||
|
||||
icuDataFile.copy('${assets.path}/$kICUDataFile');
|
||||
ApkBuilder builder = new ApkBuilder(args['android-sdk']);
|
||||
|
||||
run(aapt, [
|
||||
'package',
|
||||
'-M', androidManifest.path,
|
||||
'-A', assets.path,
|
||||
'-I', androidJar.path,
|
||||
'-F', unalignedApk.path,
|
||||
]);
|
||||
File unalignedApk = new File('${outDir.path}/Example.apk.unaligned');
|
||||
File finalApk = new File('${outDir.path}/Example.apk');
|
||||
|
||||
run(aapt, [ 'add', '-f', unalignedApk.path, classesDex.path ]);
|
||||
|
||||
run(jarsigner, [
|
||||
'-keystore', keystore.path,
|
||||
'-storepass', kKeystorePassword,
|
||||
unalignedApk.path,
|
||||
kKeystoreKeyName,
|
||||
]);
|
||||
|
||||
run(zipalign, ['4', unalignedApk.path, finalApk.path]);
|
||||
builder.package(androidManifest, assetBuilder.directory, unalignedApk);
|
||||
builder.add(artifacts, 'classes.dex', unalignedApk);
|
||||
builder.add(artifacts, 'lib/armeabi-v7a/libsky_shell.so', unalignedApk);
|
||||
builder.sign(keystore, kKeystorePassword, kKeystoreKeyName, unalignedApk);
|
||||
builder.align(unalignedApk, finalApk);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user