39 parser = argparse.ArgumentParser()
41 parser.add_argument(
'--aapt2-bin', type=str, required=
True, help=
'The path to the aapt2 binary.')
43 '--zipalign-bin', type=str, required=
True, help=
'The path to the zipalign binary.'
46 '--apksigner-bin', type=str, required=
True, help=
'The path to the apksigner binary.'
49 '--android-manifest', type=str, required=
True, help=
'The path to the AndroidManifest.xml.'
51 parser.add_argument(
'--android-jar', type=str, required=
True, help=
'The path to android.jar.')
52 parser.add_argument(
'--output-path', type=str, required=
True, help=
'The path to the output apk.')
54 '--library', type=str, required=
True, help=
'The path to the library to put in the apk.'
57 '--keystore', type=str, required=
True, help=
'The path to the debug keystore to sign the apk.'
60 '--gen-dir', type=str, required=
True, help=
'The directory for generated files.'
63 '--android-abi', type=str, required=
True, help=
'The android ABI of the library.'
66 args = parser.parse_args()
68 library_file = os.path.basename(args.library)
69 apk_name = os.path.basename(args.output_path)
71 unaligned_apk_path = os.path.join(args.gen_dir,
'%s.unaligned' % apk_name)
72 unsigned_apk_path = os.path.join(args.gen_dir,
'%s.unsigned' % apk_name)
73 apk_path = args.output_path
75 java_path =
':'.join([
java_bin(), os.environ[
'PATH']])
76 env = dict(os.environ, PATH=java_path, JAVA_HOME=
java_home())
85 args.android_manifest,
92 with zipfile.ZipFile(unaligned_apk_path,
'a', compression=zipfile.ZIP_STORED)
as zipf:
93 zipf.write(args.library,
'lib/%s/%s' % (args.android_abi, library_file))
107 apksigner_command = [
108 args.apksigner_bin,
'sign',
'--ks', args.keystore,
'--ks-pass',
'pass:android',
'--out',
109 apk_path, unsigned_apk_path
114 os.remove(unaligned_apk_path)
115 os.remove(unsigned_apk_path)