android - 如何在我的 Android 应用程序中使用 epublib jar

标签 android eclipse epub epublib

我在 android 中实现了一个应用程序,它使用 epublib 来查看 .epub 文件。

http://www.siegmann.nl/epublib/android

根据此链接,我已完成以下步骤。

Slf4j-android.
You can download this at http://www.slf4j.org/android/

开始使用

Download epublib-core-latest.jar from https://github.com/downloads/psiegman/epublib/epublib-core-latest.jar
Download slf4j-android
Add both to your android project

带有源代码的完整电子书阅读器。

我正在使用 Eclipse SDK 版本:3.7.2。

我在运行时收到此错误:java.lang.NoClassDefFoundError: nl.siegmann.epublib.epub.EpubReader。

我使用了下面提到的代码

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.TOCReference;
import nl.siegmann.epublib.epub.EpubReader;
import android.app.Activity;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;

/**
 * Log the info of 'assets/books/testbook.epub'.
 *
 * @author paul.siegmann
 *
 */
public class LogTestBookInfo extends Activity {
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    AssetManager assetManager = getAssets();
    try {
      // find InputStream for book
      InputStream epubInputStream = assetManager
          .open("books/testbook.epub");

      // Load Book from inputStream
      Book book = (new EpubReader()).readEpub(epubInputStream);

      // Log the book's authors
      Log.i("epublib", "author(s): " + book.getMetadata().getAuthors());

      // Log the book's title
      Log.i("epublib", "title: " + book.getTitle());

      // Log the book's coverimage property
      Bitmap coverImage = BitmapFactory.decodeStream(book.getCoverImage()
          .getInputStream());
      Log.i("epublib", "Coverimage is " + coverImage.getWidth() + " by "
          + coverImage.getHeight() + " pixels");

      // Log the tale of contents
      logTableOfContents(book.getTableOfContents().getTocReferences(), 0);
    } catch (IOException e) {
      Log.e("epublib", e.getMessage());
    }
  }

  /**
   * Recursively Log the Table of Contents
   *
   * @param tocReferences
   * @param depth
   */
  private void logTableOfContents(List<TOCReference> tocReferences, int depth) {
    if (tocReferences == null) {
      return;
    }
    for (TOCReference tocReference : tocReferences) {
      StringBuilder tocString = new StringBuilder();
      for (int i = 0; i < depth; i++) {
        tocString.append("\t");
      }
      tocString.append(tocReference.getTitle());
      Log.i("epublib", tocString.toString());

      logTableOfContents(tocReference.getChildren(), depth + 1);
    }
  }
}

请给我一些解决方案。

最佳答案

如果您对外部 jar 存在问题,请创建一个名为 libs 的文件夹

关于android - 如何在我的 Android 应用程序中使用 epublib jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10450346/

相关文章:

java - 跨运行保存 Javadoc

java - 为什么这在 Maven 下编译正常,但在 Eclipse 中给我错误?

html - 修复了 EPUB 布局,其中每个页面都有不同的大小

android - 从 assets 文件夹加载大于 1M 的文件

android - 通过 Android YouTube 播放器 SDK 播放时,YouTube 视频数量不会增加

安卓 Activity 版

安卓.view.InflateException : Binary XML file line #45: Error inflating class fragment

java - 无法从 Eclipse 3.6.2 导出 EAR 文件

encryption - 如何对 ePub 文件进行 DRM?