Index: testing/android/generate_native_test.py |
diff --git a/testing/android/generate_native_test.py b/testing/android/generate_native_test.py |
index 2062144bcd88f265302cba1907c61fdd34474363..eaef995c744a21d1dc82ab237f19d76b98cb0b18 100755 |
--- a/testing/android/generate_native_test.py |
+++ b/testing/android/generate_native_test.py |
@@ -136,8 +136,11 @@ class NativeTestApkGenerator(object): |
logging.warn('%s --> %s' % (jar, dest)) |
shutil.copyfile(jar, dest) |
- def CreateBundle(self): |
+ def CreateBundle(self, ant_compile): |
"""Create the apk bundle source and assemble components.""" |
+ if not ant_compile: |
+ self._SOURCE_FILES.append('Android.mk') |
+ self._REPLACEME_FILES.append('Android.mk') |
self._CopyTemplateFiles() |
self._ReplaceStrings() |
self._CopyLibraryAndJars() |
@@ -161,6 +164,16 @@ class NativeTestApkGenerator(object): |
logging.error('Ant return code %d' % p.returncode) |
sys.exit(p.returncode) |
+ def CompileAndroidMk(self): |
+ """Build the generated apk within Android source tree using Android.mk.""" |
+ try: |
+ import compile_android_mk # pylint: disable=F0401 |
+ except: |
+ raise AssertionError('Not in Android source tree. ' |
+ 'Please use --ant-compile.') |
+ compile_android_mk.CompileAndroidMk(self._native_library, |
+ self._output_directory) |
+ |
def main(argv): |
parser = optparse.OptionParser() |
@@ -173,7 +186,9 @@ def main(argv): |
parser.add_option('--output', |
help='Output directory for generated files.') |
parser.add_option('--ant-compile', action='store_true', |
- help='If specified, build the generated apk with ant') |
+ help='If specified, build the generated apk with ant. ' |
+ 'Otherwise assume compiling within the Android ' |
+ 'source tree using Android.mk.') |
parser.add_option('--ant-args', |
help='extra args for ant') |
@@ -188,12 +203,19 @@ def main(argv): |
if options.verbose: |
logging.basicConfig(level=logging.DEBUG, format=' %(message)s') |
+ # Ignore --ant-compile when building with Android source. |
+ if 'ANDROID_BUILD_TOP' in os.environ: |
+ options.ant_compile = False |
+ |
ntag = NativeTestApkGenerator(native_library=options.native_library, |
jars=options.jar, |
output_directory=options.output) |
- ntag.CreateBundle() |
+ ntag.CreateBundle(options.ant_compile) |
+ |
if options.ant_compile: |
ntag.Compile(options.ant_args) |
+ else: |
+ ntag.CompileAndroidMk() |
logging.warn('COMPLETE.') |