我在使用 Android Studio 的库时遇到问题。我在项目的 libs 文件夹中添加了 .jar,然后单击 RMB 将其添加为库。在 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.+'
}
应用插件:'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')
}