Epublib 崩溃,找不到 Epubreader class

Epublib crash with Epubreader no class found

我有以下错误:

07-03 19:45:47.341 18148-18148/? W/dalvikvm: Exception Ljava/lang/NoClassDefFoundError; thrown while initializing Lnl/siegmann/epublib/epub/EpubReader;
07-03 19:45:47.341 18148-18148/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bernard.epub3, PID: 18148
java.lang.NoClassDefFoundError: org.slf4j.LoggerFactory
at nl.siegmann.epublib.epub.EpubReader.(EpubReader.java:33)
at com.bernard.epub3.Epub3.onCreate(Epub3.java:55)
at android.app.Activity.performCreate(Activity.java:5458)

我设法整合了 .jar: 它们在 libs 文件夹中,我的 build.gradle 外观包括以下参考资料

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
    applicationId "com.bernard.epub3"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files ('libs/epublib-core-latest.jar')
compile files ('libs/slf4j-android-1.5.8-sources.jar')
compile 'com.android.support:appcompat-v7:23.4.0'
}

我的主要 java 看起来像这样:

package com.bernard.epub3;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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;

public class Epub3 extends AppCompatActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_epub3);
    AssetManager assetManager = getAssets();
    try {
        // find InputStream for book
        InputStream epubInputStream = assetManager
                .open("brit.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);

    }

}

}

在此先感谢您的帮助!

我使用 slf4j-android-1.6.1-RC1.jar

解决了我的问题