我从 git 存储库中 check out 了 coolreader 3 http://sourceforge.net/projects/crengine/ . 我尝试在 eclipse 中构建它,但在运行时它崩溃并出现以下错误:
The application Cool Reader (process.org.coolreader) has stopped unexpectedly. Please try again.
这是来自 logcat 的红色部分:
08-27 02:54:24.553: ERROR/AndroidRuntime(223): Uncaught handler: thread BackgroundThread44c32540 exiting due to uncaught exception 08-27 02:54:24.583: ERROR/AndroidRuntime(223): java.lang.UnsatisfiedLinkError: Library cr3engine-45-15 not found 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at java.lang.Runtime.loadLibrary(Runtime.java:489) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at java.lang.System.loadLibrary(System.java:557) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at org.coolreader.crengine.Engine.installLibrary(Engine.java:837) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at org.coolreader.crengine.Engine.init(Engine.java:745) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at org.coolreader.crengine.Engine.access$10(Engine.java:742) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at org.coolreader.crengine.Engine$4.run(Engine.java:565) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at android.os.Handler.handleCallback(Handler.java:587) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at android.os.Handler.dispatchMessage(Handler.java:92) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at android.os.Looper.loop(Looper.java:123) 08-27 02:54:24.583: ERROR/AndroidRuntime(223): at org.coolreader.crengine.BackgroundThread.run(BackgroundThread.java:120)
and this is the function org.coolreader.crengine.Engine.installLibrary:
private void installLibrary() {
try {
if (force_install_library)
throw new Exception("forcing install");
// try loading library w/o manual installation
log.i("trying to load library " + LIBRARY_NAME
+ " w/o installation");
System.loadLibrary(LIBRARY_NAME);
// try invoke native method
//log.i("trying execute native method ");
//setHyphenationMethod(HYPH_NONE, new byte[] {});
log.i(LIBRARY_NAME + " loaded successfully");
} catch (Exception ee) {
log.i(SO_NAME + " not found using standard paths, will install manually");
File sopath = mActivity.getDir("libs", Context.MODE_PRIVATE);
File soname = new File(sopath, SO_NAME);
try {
sopath.mkdirs();
File zip = new File(mActivity.getPackageCodePath());
ZipFile zipfile = new ZipFile(zip);
ZipEntry zipentry = zipfile.getEntry("lib/armeabi/" + SO_NAME);
if (!soname.exists() || zipentry.getSize() != soname.length()) {
InputStream is = zipfile.getInputStream(zipentry);
OutputStream os = new FileOutputStream(soname);
Log.i("cr3",
"Installing JNI library "
+ soname.getAbsolutePath());
final int BUF_SIZE = 0x10000;
byte[] buf = new byte[BUF_SIZE];
int n;
while ((n = is.read(buf)) > 0)
os.write(buf, 0, n);
is.close();
os.close();
} else {
log.i("JNI library " + soname.getAbsolutePath()
+ " is up to date");
}
System.load(soname.getAbsolutePath());
//setHyphenationMethod(HYPH_NONE, new byte[] {});
} catch (Exception e) {
log.e("cannot install " + LIBRARY_NAME + " library", e);
}
}
}
engine.java中第837行:
System.loadLibrary(LIBRARY_NAME);
engine.java 中的 LIBRARY_NAME 设置为:
static final private String LIBRARY_NAME = "cr3engine-45-15";
自从我从存储库下载代码后,它应该无需任何修改即可工作。我不明白为什么它不起作用。
最佳答案
这些不是标准名称,因为它们缺少 lib 前缀。
System.loadLibrary("lept");
System.loadLibrary("tess");
这会导致搜索 liblept.so 而不是您拥有的文件。要么给你的库一个标准名称,要么指定一个实际的文件名,包括它最终安装在设备上的路径
System.load(("lept")
//rather than
System.loadLibrary().
如果它是unsatisfiedlink 错误 那么在没有看到您的代码的情况下,仅假设您的代码正在尝试加载共享库 liblept.so 并且该库在该路径中不可用。此外,您正在使用的代码要么在任何 lib 或内部包目录中都有该 liblept.so 文件,要么您必须使用 Android-NDK 生成(构建)该共享库尝试遵循 tutorial1 , tutorial2 强>
关于android 不满意链接错误 : Library not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7212432/