I am trying to import certain classes like
javax.namespace.QName
and
org.apache.axis2.*
but I am unable to use these classes in my program. I actually got this code after converting a wsdl file into java using wsdl2java. Can anyone help me which libraries I need to use in order to get support for these classes. Also I shall be greatly thankful to you if someone can guide me about how can I add external libraries in eclipse in my Android project.
Looking forward to some useful responses.
Thanks
You should read some stuff about dalvik http://en.wikipedia.org/wiki/Dalvik_(software)
Dalvik VM is not JVM, it run different bytecode, so you have to prepare jars by tools/add sources to you project as library. But javax is a Java EE package as I know, and it has a lot of dependencies (could be even incompatible).
For eclipse:
1) create android project , go to project properties > Android > check Is Library
2) add library to project (the same way)
Related
I am trying to use webrtc in Android Studio. The file libjingle_peerconnection_so.so is put int the folder src/main/jniLibs/arneabi-v7a. But when I put in a Java file:
import org.webrtc.DataChannel;
it tells me that can not resolve "Cannot resolve symbol webrtc". Any help appreciated.
First, its armeabi-v7a, not arneabi-v7a, but that alone will not solve your problem :)
You are going the hard way, so here is a little theory:
The file libjingle_peerconnection_so.so itself is not enough to use WebRTC in Java program. At least, you need the Java JNI wrapper for WebRTC core, which provides you all necessary Java classes to work with native WebRTC code. Default wrapper is usually libjingle_peerconnection.jar, which you should put in "libs" folder on the same level as your "src" folder. So, your project tree should have these files:
src/main/jniLibs/armeabi-v7a
libs/libjingle_peerconnection.jar
Also you need to tell your build system to build the .jar in your app. In Android Studio it's usually Gradle, so just add compile files('libs/libjingle_peerconnection.jar') into your dependencies.
But there is also the easy way! Good guys from pristine.io regularly build WebRTC for Android and publish some pre-built versions to Maven repository (see here). So, you can just add compile 'io.pristine:libjingle:10839#aar' to your Gradle dependencies, and go. No need to add .so files and all that. Here is their article on that (note the outdated WebRTC version, you can use 10839, for example)
I'm using the commonsguy cwac-camera library, as per the demo-layout example, documented in "Working directlly with cameraview".
All is fine referencing camera/ and camera-v9/ as Android library projects in source form (I need Android 2.3 compatibility, that's what camera-v9 is for).
When I switch to using the library via JARs:
- cwac-camera-v9-0.6.8.jar only includes CameraFragment and BuildConfig classes, so I need also cwac-camera-0.6.8.jar with the other classes.
- including both JARs causes the following self-explaining error when running the project (not at compile time) Conversion to Dalvik format failed: Unable to execute dex: Multiple dex files define Lcom/commonsware/cwac/camera/BuildConfig;
I could just use the source as library project, or use Gradle, but I want to know if this is a bug to open an issue on Github, or if I'm doing something wrong.
To replicate the error, just clone the demo-layout example add both .jar files to libs folder, and run the project.
No, this appears to be my fault. They must have changed something in the Gradle build process that I am using to create the JARs. I will try to fix this tomorrow. In the meantime, you could go into the cwac-camera-v9 JAR and try removing the classes in com.commonsware.cwac.camera, leaving only those classes incom.commonsware.cwac.camera.acl.
My apologies for this, and thanks for pointing it out!
I'm just getting started in Android development, and use Netbeans with NBAndroid and SDK 17.
I'd like to use the same Java source code in my Java and Android app.
http://developer.android.com/guide/developing/projects/projects-eclipse.html says how to do it in Eclipse (although it is sketchy on the .JAR connection thing), but I can't seem to make it work in NB.
Based on that link, My understanding is that the correct setup for the Android app is an Android Application project which references an Android Library project which in turn references a .JAR library produced by a Java Library project. I could then also have a Java Application project referring to the same Java Library project.
So, I've set up this project structure... I have an AndroidApp project which is a basic HelloAndroid Activity in a com.ex package. This project includes an AndroidLib library project in the Libraries folder. I also have a LibClass.java file which defines a simple LibClass class which has one function getText() that just returns a String to be displayed. The MainActivity in the AndroidApp calls this to get the String to output.
When I put LibClass.java directly into the AndroidLib project, everything is fine.
But what I want to do is to share the source code with Java.
So I want to move the LibClass.java into the JavaLib library, whose .JAR file is included in the AndroidLib project. However, when I tried that, I get an error in the MainActivity class, complaining it can't find LibClass. Looking at the Projects window, I can see LibClass.class inside the com.ex package in the JavaLib.jar in the Libraries folder of the AndroidLib project. And AndroidLib is visible in the Libraries folder of the AndroidApp project, but it doesn't show any packages or other contents there.
So I feel like I'm just one step away from making this work. Do I need to do something with one or other of the AndroidManifest files perhaps? Or do something with the build.xml files? Or am I on the wrong track altogether?
I'd be really grateful if someone could post a how-to for this.
I'm trying something similar; I've got Java EE projects, built using Eclipse, and I'm trying to utilize some of that code from my Android projects. This should give me a shared codebase rather than a bunch of confusing SVN externals which I've had to endure before.
Rather than creating JAR files I've found that working with the source and building for the platform works best (well, it has been working but I've got a problem with it at the moment). So, what I'm doing is:
c:\MySvnFolderStructure\MyJavaProjectFolder\src\ (and then all the source under that)
c:\MySvnFolderStructure\MyJavaProjectFolder\android\ (and all the Eclipse Android project gubbins)
c:\MySvnFolderStructure\MyJavaProjectFolder\jee\ (and all the Eclipse JEE project gubbins)
The Android and Java EE projects do not have their own src folders, they both link to the src folder in their parent folder. What this means is that each of the Java implementations is building its own byte code version from the source, and using its own external libraries (like the Apache HTTP ones, for example).
Naturally they can't share stuff like awt (as mentioned in another post), but there's plenty of stuff that does cross-over especially if it's core Java classes that are being used.
Also, it's proving a bit tricky writing JUnit tests as there needs to be some duplication of the test code at the moment because the Android ones need extra instrumentation, but I'm working on it.
Also, see this post about relative paths in Eclipse, which means the folders can be checked-out to different places on different machines (like we all do with our version control check-outs) and still be shared.
if I understand your situation correct, you are trying to use a custom java library for both your android and java applications.
For this scenario, you can build the java library first. Instead of adding the java library jar as android library, you can drop the jar directly inside the libs folder of android project and add it to android project's build path.
If you are using ANT scripts for building the java library jar , you can consider adding the source files also as part of jar. This will help you get code assistance when you develop the android part. But this part is purely optional.
The problem is that the Java platform in Android is different from the JDK platform.
In particular, the .JAR library CANNOT refer to anything that is not icluded in the Android platform. An example of things you can't refer to is java.awt.* (except you can have java.awt.fonts).
There is also a difference between JDK String and Android String -- Android does not implement the isEmpty() method.
Has anyone tried to use javax.persistence on Android by getting the source or jar and adding it to their project?
Odds are, you will not be able to add the JAR or source. The Android build tools actively block you from importing much in the java.* and javax.* packages.
If Apache Harmony has an implementation of javax.persistence, and you are willing to refactor it to a new package (e.g., via jarjar), you can give it a try.
I need to import a couple of jars that where compiled under the full implementation of java. I know that Android doesn't use all the packages that java has to offer. My question is: Is it possible to import them without creating errors? Is there a tool that can convert jars to android jars? if so, can some examples be provided. Any help is much appreciated.
Is it possible to import them without creating errors?
If the JARs refer to classes that Android does not have, no.
Is there a tool that can convert jars to android jars?
There is no such thing as "android jars".
If you have the source code to the JARs in question, between modifying that source code and modifying copies of the missing classes from Apache Harmony, you may be able to get stuff working. However, you cannot just put java.* or javax.* classes in your project -- you will have to refactor them into new packages. Also, depending on what classes are missing, this may take thousands of developer-months to accomplish (e.g., reimplementing Swing using 2D Canvas APIs).