2016年5月20日 星期五

使用jdk中android不支持的api,造成 java.exe finished with non-zero exit value 1

發生Android java.exe finished with non-zero exit value 1的問題, 很多人提到很有可能是ram的問題, 或是clean project, rebuild project, 或是重開系統, 可解決, 但我在處理 poi 轉到 android 時發生此一問題, 並且有一大串訊息如下:


在dos視窗project的根目錄下 執行 gradlew assembleDebug --info
可見以下訊息:


java.exe
Ill-advised or mistaken usage of a core class (java.* or javax.*)
when not building a core library.

This is often due to inadvertently including a core library file
in your application's project, when using an IDE (such as
Eclipse). If you are sure you're not intentionally defining a
core class, then this is the most likely explanation of what's
going on.

However, you might actually be trying to define a class in a core
namespace, the source of which you may have taken, for example,
from a non-Android virtual machine project. This will most
assuredly not work. At a minimum, it jeopardizes the
compatibility of your app with future versions of the platform.
It is also often of questionable legality.

If you really intend to build a core library -- which is only
appropriate as part of creating a full virtual machine
distribution, as opposed to compiling an application -- then use
the "--core-library" option to suppress this error message.

If you go ahead and use "--core-library" but are in fact
building an application, then be forewarned that your application
will still fail to build or run, at some point. Please be
prepared for angry customers who find, for example, that your
application ceases to function once they upgrade their operating
system. You will be to blame for this problem.

If you are legitimately using some code that happens to be in a
core package, then the easiest safe alternative you have is to
repackage that code. That is, move the classes in question into
your own package namespace. This means that they will never be in
conflict with core system classes. JarJar is a tool that may help
you in this endeavor. If you find that you cannot do this, then
that is an indication that the path you are on will ultimately
lead to pain, suffering, grief, and lamentation.



查找了一下原因, 原文如下:
Dalvik JVM does not support the entire API of Oracle JDK. I think javax.* packages aren't available to Android. For example there's no AWT or Swing or Graphics2D of Java on Android.

From the error, it looks like you app is using this Class:http://docs.oracle.com/javase/7/docs/api/javax/xml/namespace/QName.html

This shouldn't happen If you set up your IDE to use Android SDK instead of JDK.

大意是因為Android並不支持全部JDK的api, 例如 AWT, Swing, 還有部分javax開頭的api 等, 所以以上的訊息就是因為poi用到了這些不支持android的api,

加上"--core-library"的參數, 可避免出現以上訊息


  © Blogger templates Psi by Ourblogtemplates.com 2008

Back to TOP