将epublib添加到Android Studio并运行它

我在使用
Android Studio的库中遇到了问题.

我在项目的libs文件夹中添加了.jar,然后单击RMB将其添加为libary.

在build.gradle中,我添加了依赖项:

compile files('libs/epublib-core-latest.jar')

这是有效的,但是当我运行应用程序时,我收到此错误:

Could not find class 'nl.siegmann.epublib.epub.EpubReader', referenced from method com.MJV.Reader.MainActivity.onCreate

这是可能导致它的代码:

import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.epub.EpubReader;


public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    System.out.println("hoi");
    AssetManager assetManager = getAssets();
    try {
        InputStream epubInputStream = assetManager
                .open("books/testbook.epub");
        Book book = (new EpubReader()).readEpub(epubInputStream);
        System.out.println("Hier komt het...");
        System.out.println(book.getTitle());
    } catch (IOException e) {
        e.printStackTrace();
    }
} ...

我认为当应用程序发送到我的手机时不包括库,但我可能是错的.任何帮助,将不胜感激!

编辑:
build.gradle文件:

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:0.5.+'
}

}
    apply plugin:’android’

repositories {
mavenCentral()

}

android {
    compileSdkVersion 17
    buildToolsVersion“17.0.0”

defaultConfig {
    minSdkVersion 7
    targetSdkVersion 16
}

}

dependencies {

// You must install or update the Support Repository through the SDK manager to use this dependency.
// The Support Repository (separate from the corresponding library) can be found in the Extras category.
// compile 'com.android.support:appcompat-v7:18.0.0'
compile files('libs/epublib-core-latest.jar')

}

最佳答案 您还必须在项目中包含
slf4j的二进制文件

 slf4j-android-1.5.8.jar是epublib的依赖项.

将它与epublib一起粘贴到libs文件夹中后,请确保在graddle脚本中也提到它.

从Android Studio中获取这一行非常方便,因为它编译了libs文件夹中的所有* .jar文件:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
点赞