Search code examples
androidjava-native-interfaceandroid-native-library

Android Q execute binary file on release build


public String getBinaryFileName(Context context) {
    String[] abis = Build.SUPPORTED_ABIS;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
        // this part is working fine for pre-q android
        return name;
    else
         //Android Q does not allow executing files outside lib folder
         for (String abi : abis) {
            String name = context.getApplicationInfo().nativeLibraryDir + "/binary" + "." + abi + ".so";
            File executable = new File(name);
            if (executable.exists())
               return name;
         }
    return null;
}

I have this code which tries to get the name of an executable binary in ordre to execute it later. The code is working fine for pre-Q Android devices, and also it works fine when executed in debug mode on Android Q devices, but it returns null when executed in release mode.

I added some logging to this, and it seems that the file does not exist in nativeLibraryDir in release mode.

I am not really good when it comes to native stuff, and I really can't understand what's going on here.

Tried to set android:extractNativeLibs in the manifest to either values true or false I also tried android.bundle.enableUncompressedNativeLibs=false in the gradle.propreties file as some suggested

But NOTHING! Please help.


Solution

  • By pure luck, I found out that I had to add lib to the beginning of the file name:

    String name = context.getApplicationInfo().nativeLibraryDir + "/libbinary" + "." + abi + ".so";
    

    I have no clue why!