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;
}
我有这段代码试图获取可执行二进制文件的名称,以便稍后执行它。该代码在 Q 之前的 Android 设备上运行良好,在 Android Q 设备上以调试模式执行时也运行良好,但null
在发布模式下执行时返回。
我为此添加了一些日志记录,似乎该文件nativeLibraryDir
在发布模式下不存在。
当谈到原生的东西时,我不是很擅长,我真的无法理解这里发生了什么。
尝试android:extractNativeLibs
在清单中设置为任一值true
,或者false
我也按照一些建议android.bundle.enableUncompressedNativeLibs=false
在文件中尝试了gradle.propreties
但什么都没有!请帮忙。