39 parser = argparse.ArgumentParser()
40
41 parser.add_argument('--aapt2-bin', type=str, required=True, help='The path to the aapt2 binary.')
42 parser.add_argument(
43 '--zipalign-bin', type=str, required=True, help='The path to the zipalign binary.'
44 )
45 parser.add_argument(
46 '--apksigner-bin', type=str, required=True, help='The path to the apksigner binary.'
47 )
48 parser.add_argument(
49 '--android-manifest', type=str, required=True, help='The path to the AndroidManifest.xml.'
50 )
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.')
53 parser.add_argument(
54 '--library', type=str, required=True, help='The path to the library to put in the apk.'
55 )
56 parser.add_argument(
57 '--keystore', type=str, required=True, help='The path to the debug keystore to sign the apk.'
58 )
59 parser.add_argument(
60 '--gen-dir', type=str, required=True, help='The directory for generated files.'
61 )
62 parser.add_argument(
63 '--android-abi', type=str, required=True, help='The android ABI of the library.'
64 )
65
66 args = parser.parse_args()
67
68 library_file = os.path.basename(args.library)
69 apk_name = os.path.basename(args.output_path)
70
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
74
76 env = dict(os.environ, PATH=java_path, JAVA_HOME=
java_home())
77
78
79 aapt2_command = [
80 args.aapt2_bin,
81 'link',
82 '-I',
83 args.android_jar,
84 '--manifest',
85 args.android_manifest,
86 '-o',
87 unaligned_apk_path,
88 ]
90
91
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))
94
95
96 zipalign_command = [
97 args.zipalign_bin,
98 '-p',
99 '-f',
100 '4',
101 unaligned_apk_path,
102 unsigned_apk_path,
103 ]
105
106
107 apksigner_command = [
108 args.apksigner_bin, 'sign', '--ks', args.keystore, '--ks-pass', 'pass:android', '--out',
109 apk_path, unsigned_apk_path
110 ]
112
113
114 os.remove(unaligned_apk_path)
115 os.remove(unsigned_apk_path)
116
117 return 0
118
119
def run_command_checked(command, env=None)
static SkString join(const CommandLineFlags::StringArray &)