Issue
In Android API 29, we cannot execute a process from the data folder due to W^X violation. Google seems to recommend that we must execute them from the /lib/[arch] folder. However, only files in the format lib[name].so will be installed, even if included in the APK there. Furthermore, when attempting to execute a file that just happens to be be named with that format, it just returns exit code 1 with no exception when doing so. The program does not execute.
This answer indicates something similar, but doesn't mention a "misnamed" file executing: https://stackoverflow.com/a/62394766/449722
From what I can tell, running native executables included with an APK is now impossible, rather than just calling into shared libraries when targeting API 29. Is this correct, or is there something specific that we need to do.
Solution
Google are aware that we need to counterintuitively rename our executables to match the lib….so
pattern, but they seem to be comfortable with that, and on several occasions they expressed determination not to break support of running native executables through Runtime.exec()
. Actually, it's probably too late to expect them to change the naming convention which has been enacted since Android Cupcake.
This said, there are few extras to take care of:
Make sure that the files are extracted (by default,
android:extractNativeLibs="false"
when you build a bundle).Make sure that the executable does not have unsatisfied dependencies (e.g. c++_shared).
If your executable needs non-system libraries (on load or through
dlopen()
), you must provide theLD_LIBRARY_PATH
to your lib directory (unlikeSystem.loadLibrary()
, this is not resolved for you).Don't hardcode the path for
exec()
, usegetApplicationInfo().nativeLibraryDir
.
Answered By - Alex Cohn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.