Fix mobile-install v1 error when incrementally installing the native
libs' manifest onto the device

Somewhere between 28 and 29, when creating directories as part of adb push, the behavior changed w.r.t. directory permissions.

On 28, the created directories via adb push have the permissions drwxrwxr-x.
On 29, the permissions are drwxrwx--x. The difference is the read permission for others. For some reason, this causes the adb push to fail.

It turns out that inserting a adb shell mkdir -p /data/local/tmp/incrementaldeployment/com.example.android.bazel/native/ before pushing the files creates the directory with the correct permissions, allowing native_manifest to be pushed correctly.

Fixes https://github.com/bazelbuild/examples/issues/77
Fixes https://github.com/bazelbuild/bazel/issues/6814

RELNOTES: Fixed mobile-install v1 error when installing an app with native libraries onto an Android 9 (Pie) device. See https://github.com/bazelbuild/examples/issues/77
PiperOrigin-RevId: 224928364
diff --git a/tools/android/incremental_install.py b/tools/android/incremental_install.py
index c07a9b0..0638c1b 100644
--- a/tools/android/incremental_install.py
+++ b/tools/android/incremental_install.py
@@ -557,6 +557,12 @@
     # If we couldn't fetch the device manifest or if this is a non-incremental
     # install, wipe the slate clean
     adb.Delete(targetpath.join(app_dir, "native"))
+
+    # From Android 28 onwards, `adb push` creates directories with insufficient
+    # permissions, resulting in errors when pushing files. `adb shell mkdir`
+    # works correctly however, so we create the directory here.
+    # See https://github.com/bazelbuild/examples/issues/77 for more information.
+    adb.Mkdir(targetpath.join(app_dir, "native"))
   else:
     # Otherwise, parse the manifest. Note that this branch is also taken if the
     # manifest is empty.