简体   繁体   English

错过了Android JRE系统库(java.awt。*)

[英]Android JRE System library (java.awt.*) is missed

I'm trying to run pdfbox.jar library on Android and seems like I do everything right. 我正在尝试在Android上运行pdfbox.jar库,看起来我做的一切都正确。 I use Eclipse pluging to deploy the project. 我使用Eclipse pluging来部署项目。 The code is very simple just call for pdfbox.jar library. 代码非常简单,只需调用pdfbox.jar库即可。

All required jars are located in classpath in correct order and should be exported while dalvik recompiles the byte-code. 所有必需的jar都以正确的顺序位于类路径中,并且应该在dalvik重新编译字节代码时导出。

but all my attempts to get it work is failed, when I deploy the project I got the following error 但我尝试使其工作失败,当我部署项目时,我收到以下错误

05-10 13:53:42.590: I/dalvikvm(14009): Failed resolving Lorg/apache/pdfbox/pdmodel/PDDocument; interface 911 'Ljava/awt/print/Pageable;'
05-10 13:53:42.590: W/dalvikvm(14009): Link of class 'Lorg/apache/pdfbox/pdmodel/PDDocument;' failed
05-10 13:53:42.590: E/dalvikvm(14009): Could not find class 'org.apache.pdfbox.pdmodel.PDDocument', referenced from method com.ibm.ext.pdf.PDFExtractor.extractText

05-10 13:53:54.881: E/AndroidRuntime(14009): FATAL EXCEPTION: main
05-10 13:53:54.881: E/AndroidRuntime(14009): java.lang.NoClassDefFoundError: org.apache.pdfbox.pdmodel.PDDocument
05-10 13:53:54.881: E/AndroidRuntime(14009):    at com.ibm.ext.pdf.PDFExtractor.extractText(PDFExtractor.java:52)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at com.ibm.ext.pdf.PDFBoxActivity.onCreate(PDFBoxActivity.java:14)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.app.Activity.performCreate(Activity.java:4465)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.app.ActivityThread.access$600(ActivityThread.java:123)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.os.Looper.loop(Looper.java:137)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at android.app.ActivityThread.main(ActivityThread.java:4424)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at java.lang.reflect.Method.invokeNative(Native Method)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at java.lang.reflect.Method.invoke(Method.java:511)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-10 13:53:54.881: E/AndroidRuntime(14009):    at dalvik.system.NativeStart.main(Native Method)

org/apache/pdfbox/pdmodel/PDDocument implements java/awt/print/Pageable

it seems that dalvit doesn't know to export java.awt.* classes for some reason or there is still something that I missed in the classpath. 似乎dalvit不知道出于某种原因导出java.awt。*类,或者在类路径中仍然遗漏了一些东西。

I'd like to know whether there is any solution or this is valid case and I can't use jars which are depend on jre libraries that dalvik doesn't know to use. 我想知道是否有任何解决方案或这是有效的情况,我不能使用依赖于dalvik不知道使用的jre库的jar。

Android does not include most of the java.awt.* classes, and so third-party Java libraries that depend upon such classes would need to be rewritten to work on Android, or simply not used. Android不包含大多数java.awt.*类,因此依赖于这些类的第三方Java库需要重写才能在Android上运行,或者根本不使用。

I can't use jars which are depend on jre libraries that dalvik doesn't know to use. 我不能使用依赖于dalvik不知道使用的jre库的jar。

More accurately, you cannot use JARs which depend on classes that the Android SDK does not include. 更准确地说,您不能使用依赖于Android SDK不包含的类的JAR。

The problem is that Android has minimal support for AWT. 问题是Android对AWT的支持很少。

This is one of those areas where it is clear that Android is NOT a Java platform. 这是Android不是Java平台的领域之一。 Android has its own stack for doing graphics and GUIs. Android有自己的堆栈用于执行图形和GUI。

I'd like to know whether there is any solution ... 我想知道是否有任何解决方案......

This SO question - Using awt with android - has an answer mentions a commercial product that allows you to run Swing code on Android. 这个问题 - 使用awt与android - 有一个答案提到了一个商业产品,允许你在Android上运行Swing代码。 I don't know for sure, but I imagine that this product supports AWT as well. 我不确定,但我想这个产品也支持AWT。

The problem is due to the lack of AWT support in android, as others have indicated. 问题是由于其他人已表明,Android中缺乏AWT支持。 A work-around for you could be to use the android port of PDFBox: 解决方法可能是使用PDFBox的android端口:

https://github.com/Birdbrain2/PdfBox-Android https://github.com/Birdbrain2/PdfBox-Android

tldr; tldr; replace your gradle dependency on PDFBox with this: org.apache:pdfbox-android: latest version here , and consider adding MultiDex support to your app if you get a DexIndexOverflowException exception. 使用以下方法替换您对PDFBox的gradle依赖:org.apache:pdfbox-android: 最新版本 ,如果您收到DexIndexOverflowException异常,请考虑向您的应用添加MultiDex支持。

The only part of AWT supported by Android is the fonts package. Android支持的AWT的唯一部分是字体包。

Porting AWT graphics code to Android 将AWT图形代码移植到Android

This one works perfectly! 这一个完美! ;-) ;-)

Birdbrain2/PdfBox-Android Birdbrain2 / PDFBOX-的Android

Had the same problem, and it solved it. 有同样的问题,它解决了它。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM