7

I have been working on a Android Web Services program that uses a number of classes from Sun's javax libraries. The eclipse IDE is barking "Attempt to include a core class (java.* or javax.* ) in something other than a core library." My application is an Android application and I am not creating a core library. I am using several .jars; javax.xml.ws, javax.xml.bind, javax.xml.soap, javax.xml.rpc, and javax.jws. I believe I cannot use these java bytecode .jars directly. I will have to use the dx tool to convert them to delvik bytecode or .dex files. I have done some additional research and have found that use of any javax.* classes in an android application are forbidden. Can someone explain why? Are their practical programming work arounds?

Thanks, Steve

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
Steve Mansfield
  • 147
  • 1
  • 3
  • 10

3 Answers3

7

That's because those jars use core core libraries. Android does not support the complete J2SE, but rather a subset of it: http://developer.android.com/reference/packages.html

Thus, you cannot use Java core libraries because they don't belong to the Android SDK.

Cristian
  • 198,401
  • 62
  • 356
  • 264
  • Hello Christian, That's what I have read and I see a couple of the javax.xml.* classes in the Android reference that are in my javax.xml.rpc class. Classes are classes. There is nothing special about these classes other than they have the same name. Can you explain why the Android will not allow the use of these classes. I know my question is somewhat basic but I am new to Android....Thanks. – Steve Mansfield Jun 28 '10 at 19:46
  • 1
    Well... classes are classes, but actually they are more than simple classes. For instance, a class can contain this: `import java.beans.*;`, and android won't be able to execute it. – Cristian Jun 28 '10 at 19:48
  • Thanks Christian, appreciate the help. – Steve Mansfield Jun 28 '10 at 20:01
  • Christian, Yes, you are 100% right. I did not quite understand your answer at first but after digging into the Android VM for a couple of weeks I found that there are several libraries that Android will not support. If you try to link any jar with android.*, java.*, javax.*, junit.* and org.* you may get a compiler build error and those classes will not load. These are core libraries provided by Android. They provide a small subset of classes and are not guaranteed to be 100% compatible with similar java libraries...Thanks. – Steve Mansfield Jul 28 '10 at 12:11
2

You need to use an alternate library to handle SOAP in Android - the Sun provided libraries do not work.

One popular alternative is KSOAP2.

Yann Ramin
  • 32,895
  • 3
  • 59
  • 82
  • Hello Theatrus, Yes, I started with kSOAP2 and got several WS Android applications running. kSOAP2 is capable of talking to almost any WS. However, it has two flaws. First, it has none of the newer WS security support so you cannot easily connect to secure WS's. Second, it is only useful for the simplest of WSDL's. Most WS WSDL's are complex and building a kSOAP2 client by hand is impractical for all but the simplest WS. Not impossible but not easy compaired to the support provided by wsimport. I was trying to use wsimport to build an Android client but it may not work. – Steve Mansfield Jun 28 '10 at 20:09
1

Start with an enhanced version of kSOAP called ksoap2-android:

http://code.google.com/p/ksoap2-android/

Then add a tool that generates kSOAP stubs based on a WSDL called wsdl2ksoap:

http://code.google.com/p/wsdl2ksoap/

Not quite as advanced as wsimport, but this gets you pretty darn close.

Filippo Mazza
  • 4,339
  • 4
  • 22
  • 25
Jonathan Schneider
  • 26,852
  • 13
  • 75
  • 99