[英]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;
}
我有這段代碼試圖獲取可執行二進制文件的名稱,以便稍后執行。 該代碼在預 Q Android 設備上運行良好,在 Android Q 設備上以調試模式執行時也運行良好,但在發布模式下執行時返回null
。
我為此添加了一些日志記錄,似乎該文件在發布模式下的nativeLibraryDir
中不存在。
當涉及到本地的東西時,我並不是很擅長,我真的無法理解這里發生了什么。
試圖將android:extractNativeLibs
中的android:extractNativeLibs
設置為值true
或false
我也按照一些建議在gradle.propreties
文件中嘗試了android.bundle.enableUncompressedNativeLibs=false
但什么都沒有! 請幫忙。
幸運的是,我發現我必須在文件名的開頭添加lib
:
String name = context.getApplicationInfo().nativeLibraryDir + "/libbinary" + "." + abi + ".so";
我不知道為什么!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.