【发布时间】:2016-09-07 12:14:52
【问题描述】:
所以我需要将 jexcelApi 用于我的 Android 项目。包含它之后,我没有收到编译器错误,但是我的设备上的运行时异常 NoClassDefFoundError 对于我从该 jar 中使用的每个类。反编译显示需要的类在jar里面。
我做了以下步骤:
- 下载了jar
- 已将其复制到 {Root_Folder}/libs
-
compile fileTree(include: ['*.jar'], dir: 'libs')在我的 gradle 构建脚本中 - 称为清洁项目
- 构建项目
完整的 logcat 条目:
05-11 23:28:05.234 26289-26289/? E/Assignment: Spreadsheet Error
java.lang.NoClassDefFoundError: jxl.write.WritableFont
at com.example.bene.assignment.spreadsheet.SpreadsheetController.<init>(SpreadsheetController.java:43)
at com.example.bene.assignment.spreadsheet.SpreadsheetController.create(SpreadsheetController.java:34)
at com.example.bene.assignment.MainActivity.onCreate(MainActivity.java:62)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)bs')
关于以下代码:
// create Formats
WritableFont times10pt = new WritableFont(WritableFont.TIMES, 10);
// Define the cell format
mTimes = new WritableCellFormat(times10pt);
// Lets automatically wrap the cells
mTimes.setWrap(true);
// create create a bold font with unterlines
WritableFont times10ptBoldUnderline = new WritableFont(WritableFont.TIMES, 10, WritableFont.BOLD, false, UnderlineStyle.SINGLE);
mTimesBoldUnderline = new WritableCellFormat(times10ptBoldUnderline);
// Lets automatically wrap the cells
mTimesBoldUnderline.setWrap(true);
我真的不知道,如何进行,请帮助我!提前谢谢你。
更新
所以我刚刚发现,一些包具有传递依赖项,必须包含这些依赖项才能编译它们。 所以我找到了以下链接:
- Maven repository
- Sourceforge(由于 stackoverflow 限制,无法发布)
第一个说我需要compile 'log4j:log4j:1.2.14',第二个说我需要
compile 'org.slf4j:slf4j-api:1.7.2'
compile 'org.slf4j:slf4j-log4j12:1.7.2'
按照 Maven 链接,我通过
得到相同的结果compile('net.sourceforge.jexcelapi:jxl:2.6.12') {
transitive= true
}
这使我对该任务的依赖关系树如下所示: Dependency Tree
仍然遇到同样的异常...
【问题讨论】:
标签: java android android-studio jar android-gradle-plugin