2

I am trying to follow advice from https://issuetracker.google.com/issues/128554619#comment4 (not on Android 10 yet, but want my code to work there as well):

While exec() no longer works on files within the application home directory, it continues to be supported for files within the read-only /data/app directory. In particular, it should be possible to package the binaries into your application's native libs directory and enable android:extractNativeLibs=true, and then call exec() on the /data/app artifacts. A similar approach is done with the wrap.sh functionality, documented at https://developer.android.com/ndk/guides/wrap-script#packaging_wrapsh .

as suggested in this answer: https://stackoverflow.com/a/58748468/9204

However, in my case the directory to which the native libs are extracted is not

File(filesDir.parentFile!!, "lib")

as in that answer but

File(File(packageCodePath).parentFile!!, "lib/arm64")

This is obviously hacky (especially hardcoding arm64) and may depend on specific Android version and/or device.

Is there a documented way to find the native libs directory?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487

1 Answers1

3

It's applicationInfo.nativeLibraryDir (on a Context).

Also even though https://developer.android.com/ndk/guides/wrap-script#packaging_wrapsh says

Android Studio only packages .so files from the lib/ directories, so if you're an Android Studio user, you'll need to place your wrap.sh files in the src/main/resources/lib/* directories instead, so that they'll be packaged correctly.

at least on one device files placed src/main/resources/lib/* were packaged in the APK but not extracted afterwards if it wasn't named lib*.so. Fixed by renaming the executable file, happily nothing depended on the name itself.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • I have an executable file in the src/main/resources/lib/ABI/ folder, when I build for debug the executable file is copied and found in ```applicationInfo.nativeLibraryDir``` however when I build for release it is not, is it related to the above post? any ideas how to get around it? – MandelDuck Aug 18 '20 at 22:41
  • Sorry, I don't know. – Alexey Romanov Aug 19 '20 at 07:24
  • thanks for the reply, are you able to say if you get the same issue? or does it build fine on release? if it doesnt it makes me think its something with react native breaking things – MandelDuck Aug 19 '20 at 11:04
  • I can't check at the moment. – Alexey Romanov Aug 19 '20 at 16:47