Index: build/android/incremental_install/installer.py |
diff --git a/build/android/incremental_install/installer.py b/build/android/incremental_install/installer.py |
index feebadbbbec7799fb2519555968960e5cf975bfe..b5b1d050e5510261198775f8e5fe52a2a743bff4 100755 |
--- a/build/android/incremental_install/installer.py |
+++ b/build/android/incremental_install/installer.py |
@@ -13,6 +13,7 @@ import os |
import posixpath |
import shutil |
import sys |
+import zipfile |
sys.path.append( |
os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))) |
@@ -63,6 +64,12 @@ def _GetDeviceIncrementalDir(package): |
return '/data/local/tmp/incremental-app-%s' % package |
+def _HasClasses(jar_path): |
+ """Returns whether the given jar contains classes.dex.""" |
+ with zipfile.ZipFile(jar_path) as jar: |
+ return 'classes.dex' in jar.namelist() |
+ |
+ |
def Uninstall(device, package, enable_device_cache=False): |
"""Uninstalls and removes all incremental files for the given package.""" |
main_timer = time_profile.TimeProfile() |
@@ -138,7 +145,10 @@ def Install(device, apk, split_globs=None, native_libs=None, dex_files=None, |
# Ensure no two files have the same name. |
transformed_names = _TransformDexPaths(dex_files) |
for src_path, dest_name in zip(dex_files, transformed_names): |
- shutil.copy(src_path, os.path.join(temp_dir, dest_name)) |
+ # Binary targets with no extra classes create .dex.jar without a |
+ # classes.dex (which Android chokes on). |
+ if _HasClasses(src_path): |
+ shutil.copy(src_path, os.path.join(temp_dir, dest_name)) |
device.PushChangedFiles([(temp_dir, device_dex_dir)], |
delete_device_stale=True) |
push_dex_timer.Stop(log=False) |