extract_android_native_lib.py 909 B

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