我正在编写一个需要提取7z档案的Android应用程序。按时间,我正在搜索可以在我的项目中使用的第三方库或源代码。
我将.so文件复制到/ libs文件夹
应用\ SRC \主\ jniLibs \ armeabi \ libun7z.so
我无法在android
中提取7z文件运行此行后AndUn7z.extract7z(My7z,My7zPath);
我有这个错误:
java.lang.UnsatisfiedLinkError中:未找到对于int com.darkgamers.pepsiman.browser.mainmenu.AndUn7z.un7zip(java.lang.String中,java.lang.String中)执行(试图Java_com_darkgamers_pepsiman_browser_mainmenu_AndUn7z_un7zip和Java_com_darkgamers_pepsiman_browser_mainmenu_AndUn7z_un7zip__Ljava_lang_String_2Ljava_lang_String_2) 在com.darkgamers.pepsiman.browser.mainmenu.AndUn7z.un7zip(原生方法)
这是我的代码:
public class AndUn7z {
public static boolean extract7z(String filePath, String outPath)
{
File outDir = new File(outPath);
if(!outDir.exists() || !outDir.isDirectory())
{
outDir.mkdirs();
}
return (AndUn7z.un7zip(filePath, outPath) == 1);
}
/**
* Extract from assets
* @param context
* @param assetPath
* @param outPath
* @return
* @throws Exception
*/
public static boolean extractAssets(Context context, String assetPath, String outPath)
{
File outDir = new File(outPath);
if(!outDir.exists() || !outDir.isDirectory())
{
outDir.mkdirs();
}
String tempPath = outPath + File.separator + ".temp";
try {
copyFromAssets(context, assetPath, tempPath);
} catch (Exception e) {
e.printStackTrace();
return false;
}
boolean ret = (AndUn7z.un7zip(tempPath, outPath) == 1);
new File(tempPath).delete();
return ret;
}
/**
* Copy asset to temp
* @param context
* @param assetPath
* @param tempPath
* @throws Exception
*/
private static void copyFromAssets(Context context, String assetPath, String tempPath)
throws Exception
{
InputStream inputStream = context.getAssets().open(assetPath);
FileOutputStream fileOutputStream = new FileOutputStream(tempPath);
int length = -1;
byte[] buffer = new byte[0x400000];
while ((length = inputStream.read(buffer)) != -1) {
fileOutputStream.write(buffer, 0, length);
}
fileOutputStream.flush();
fileOutputStream.close();
inputStream.close();
}
//JNI interface
private static native int un7zip(String filePath, String outPath);
static {
System.loadLibrary("un7z");
}
}
答案 0 :(得分:1)
下载7z SDK for Java并按以下方式重复使用其"<"
类:
LzmaAlone
答案 1 :(得分:0)
使用7z筹集资金并知道您要7z之后,在xz中使用Java API会容易得多:
XZInputStream in = new XZInputStream(your_input_stream_xz_compressed);
FileOutputStream out = new FileOutputStream(your_output_file_decompressed);
byte[] buffer = new byte[1024];
int length;
while ((length = in.read(buffer)) != -1) // Copy DB byte for bite
out.write(buffer, 0, length);
out.flush();
out.close();
in.close();