Android 10 - alternative to launching executable as subproccess stored in app home directory

Viewed 2045

I have an android app (C#, Xamarin) that

  1. bundles a python environment with its apk.
  2. extracts the python files into an the app files directory.
  3. runs python code, by executing the python executable as a sub process.

This worked for years, but now on android 10, I'm getting:

Write fault on path /[Unknown] error (which is likely the Xamarin wrapper of the real error).

I assume this is caused by the following android 10 changes: "Removed execute permission for app home directory"

(Although if I adb in and runas the app user, executing the python executable works fine.)

My testing showed that: In general running subproccess still works. (eg /system/bin/echo) But executing any subprocess, that exists in the apps home/files directory generates the Write fault on path /[Unknown] error.

In the android 10 changes file, the suggested alternative approach is to:

Apps should load only the binary code that's embedded within an app's APK file.

As far as I'm aware one can't get a file path to an embedded apk file.

Is there a way of executing (eg. Runtime.exec()) a (binary/native) file embedded in the apk?

2 Answers

I was unable to find a way to execute a binary/native file embedded inside an APK. However, since android automatically extracts files in the lib/ABI/ folder on install, I was able to put my python executable in that folder.

In addition, even though the docs seem to imply that only files of the form lib<name>.so are extracted, I found that all files in that folder were extracted. (UPDATE: apparently only for DEBUG builds?) Sub folders are always ignored and never extracted.

UPDATE: while the above is true for lots of android environments , I found that chromebook android environments, only files of the form lib<name>.so are installed. Even files of the form lib<name>.so.<version> are ignored.


The process was like this:

  • place binary/native files in the lib/ABI folder of the APK.

I used the jar.exe tool to add files to my apk. (for other build environment there is prolly easier ways)

  • In application code, find the install location of the apk. (not the data dir)

I used:

PackageManager.GetApplicationInfo("my.app.name", PackageInfoFlags.SharedLibraryFiles).NativeLibraryDir
  • Exec binary/native prog from that folder.

It will be something like this.

/data/app/my.app.name-RmBFingPOpsEA-S577DoZg==/lib/x86_64

An added benefit of this approach is that the app doesn't have to extract the native files itself, rather that is done automatically on install. This improves app startup time.

This is a just a short term workaround (rather than a proper answer):

change android targetSdkVersion from 29 to 28

This means, that things should work even on android 10 devices, however it has the following limitations:

  1. You can never upgrade the target sdk version.
  2. At some point in future the google play store will not allow app uploads that target older sdk versions, means you can't post upgrades to your app.
Related