blob: d7b5e0cad2ddb57e837f46e595a3dfce9a8362ef [file] [log] [blame]
lambroslambroue1172c52015-10-16 21:42:581#!/usr/bin/env python
2#
Avi Drissmand6cdf9b2022-09-15 19:52:533# Copyright 2015 The Chromium Authors
lambroslambroue1172c52015-10-16 21:42:584# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6
7"""Extracts a native library from an Android JAR."""
8
9import os
10import sys
11import zipfile
12
13
14def main():
15 if len(sys.argv) != 4:
16 print 'Usage: %s <android_app_abi> <jar file> <output file>' % sys.argv[0]
17 sys.exit(1)
18
19 android_app_abi = sys.argv[1] # e.g. armeabi-v7a
20 jar_file = sys.argv[2] # e.g. path/to/foo.jar
21 output_file = sys.argv[3] # e.g. path/to/libfoo.so
22
23 library_filename = os.path.basename(output_file)
24 library_in_jar = os.path.join('lib', android_app_abi, library_filename)
25
26 with zipfile.ZipFile(jar_file, 'r') as archive:
27 with open(output_file, 'wb') as target:
28 content = archive.read(library_in_jar)
29 target.write(content)
30
31
32if __name__ == '__main__':
33 sys.exit(main())