【发布时间】:2020-06-16 23:56:11
【问题描述】:
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
我还按照一些建议在gradle.propreties 文件中尝试了android.bundle.enableUncompressedNativeLibs=false
但什么都没有!请帮忙。
【问题讨论】:
标签: android java-native-interface android-native-library