androidepublib

Epublib crash with Epubreader no class found


I have the following error:

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)

I managed to integrate the .jar: they are in the libs folder and my build.gradle looks includes the following reference

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'
}

and my main java looks like this:

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);

    }

}

}

Thanks in advance for the help!


Solution

  • I solved my problem by using slf4j-android-1.6.1-RC1.jar