开发者

Can Android use standard built JAR files?

Im pretty sure the answer is no, but im using the new IntelliJ EAP version and have a project i worked on a while back which was just written against JDK 1.6 for an applet based application.

However now i could see how it could be useful in an android app that im interested in creating.

Do i now have to re-write all the code/tests again targeting the android sdk or can i just drop in my existing JAR file and only use android for the UI layer.

Its just android seems to make testing WAY harder than it needs to be, and i have alot of existing tests written and working, if it wasnt so hard to just write a quick unit test (st开发者_如何学Pythonandard Junit @Test style) i wouldnt mind porting, however i just dont get the whole instrumentation thing, as i dont need a UI at the moment...

Anyway so back to the point, can i use my existing JDK built code in an android app?


No!

Android uses the "Dalvik" VM from project harmony which uses a different set of bytecodes which are incompatable with the standard Java JVM bytecodes.

This was done both to optimise the VM for opreration on mobile platforms, and, probably more importantly to try and avoid Copyright and patent disputes with Sun and now Oracle.

More info here

However there is a tool called "dx" which can perform the conversion in the dev environment.


Okay, let me clear up your confusion.

Jars are converted to dex Dalvik bytecode during the compiling process thus you can use 3rd party jar libs.

However, in your case because its applet which has a different application lifecycle yes you might have to re-do it to get it to work in android.

As far as testing instrumentation is used on all java mobile development even JavaMe. It basically means that the Junit tests are run in the emulator or device but in android's case you are using android mock objects to test android specific things.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜