我创建了一个安装在Android系统中的应用,我的应用使用本机库,我尝试使用此代码加载本机库:
//Load Libffmpeg
try {
if (new File("/data/data/"+ packageName +"/lib/"+ "libffmpeg-linphone-" + ffmpegAbi+".so").exists()) {
System.load("/data/data/"+ packageName +"/lib/"+ "libffmpeg-linphone-" + ffmpegAbi+".so");
}else if(new File("/system/lib/"+ "libffmpeg-linphone-" + ffmpegAbi+".so").exists()){
System.load("/system/lib/"+ "libffmpeg-linphone-" + ffmpegAbi+".so");
} else if(new File("/system/app/"+ packageName +"/lib/"+ "libffmpeg-linphone-" + ffmpegAbi+".so").exists()){
System.load("/system/app/"+ packageName +"/lib/"+ "libffmpeg-linphone-" + ffmpegAbi+".so");
}else {
System.loadLibrary("ffmpeg-linphone-" + ffmpegAbi);
}
} catch (Throwable e) {
Log.w("LinphoneCoreFactoryImpl", "Unable to load optional library lib" + "ffmpeg-linphone-" + ffmpegAbi);
}
//Load Main Library
try {
if (new File("/data/data/"+ packageName +"/lib/"+ "linphone-" + abi+".so").exists()) {
System.load("/data/data/"+ packageName +"/lib/"+ "linphone-" + abi+".so");
}else if(new File("/system/lib/"+ "linphone-" + abi+".so").exists()){
System.load("/system/lib/"+ "linphone-" + abi+".so");
} else if(new File("/system/app/"+ packageName +"/lib/"+ "linphone-" + abi+".so").exists()){
System.load("/system/app/"+ packageName +"/lib/"+ "linphone-" + abi+".so");
}else {
System.loadLibrary("linphone-" + abi);
}
Log.i("LinphoneCoreFactoryImpl", "Loading done with " + abi);
libLoaded=true;
break;
}catch(Throwable e) {
if (firstException == null) firstException=e;
}
起初出现了这个错误:
java.lang.RuntimeException:java.lang.UnsatisfiedLinkError:dlopen 失败:无法映射" /system/lib/liblinphone-armeabi-v7a.so"分割 2:许可被拒绝
之后我尝试将此代码放入:
try {
process = Runtime.getRuntime().exec("su");
dataOutputStream = new DataOutputStream(process.getOutputStream());
dataOutputStream.writeBytes("chmod 644 /system/lib/\n");
dataOutputStream.writeBytes("exit\n");
dataOutputStream.flush();
process.waitFor();
} catch (Exception e) {
} finally {
try {
if (dataOutputStream != null) {
dataOutputStream.close();
}
process.destroy();
} catch (Exception e) {
}
}
但同样的错误再次出现,是不可能使系统中的Android应用程序访问系统/ lib或我的代码错误?