I am trying make a restful post from my android application. I have imported the jersey-core1.13, jersey-server1.13 and jersey client1.13 jar files to my project. And when I am creating the client like this :
Client client = Client.create();
I am getting run time error :E/AndroidRuntime(540): java.lang.NoClassDefFoundError: com.sun.jersey.api.client.Client
What is the problem? Can anyone help?
This error comes normally if the build paths for jar files are not configured.
The best method to avoid this problem is keep all your jar files in a folder called libs (create the folder and copy all jars file). If you are using ADT 17+ (Not sure but at least it works in ADT 20)then it automatically configures the build path.
Note: Remove all external jar files from build path (ADT will automatically detect and configure them from libs folder )
Hope this helps you.
For pictorial description of method I described please refer to
http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17
Related
I'm trying to make a build of a sample project (core-basic), without maven, just by picking the jars located in repository/dependencies/1.4.9/robospice and copying them to Android project libs folder.
The jars that I am copying are specifically these:
commons-io-1.3.2
commons-lang3-3.1
robospice-1.4.9
robospice-cache-1.4.9
However, Eclipse shows this error:
robospice-sample-core/libs/commons-lang3-3.1.jar' in project 'robospice-sample-core' cannot be read or is not a valid ZIP file
Moreover, I cannot access into the contents of the jars, WinRar says that they are corrupted or invalid.
So, what am I doing wrong? Can I really use those jar just by copying them to libs folder or do I have to do something more? Why does eclipse say that they can not be read?
(Thanks in advance. In spite of I know that maven setup for Robospice is strongly advisable, I'd like to know why this happens)
Downloading jar by means of right click on its file name --> Save link returns corrupted jar files. Clicking on "Raw" in the file details, return the correct file.
You must have made a mistake while downloading the files. They can be opened pretty easily with zipinfo on my mac. Download them again from the repo branch or pick the artifacts from maven central.
I am working on an android library, and wish to export a JAR file that I can distribute for others to use in their apps. I don't want to distribute the source code as it contains details on posting to my web server.
I have tried using the JAR file that is created in the bin directory and copying the jar file to my project and referencing it within my project and ticking the export button.
When I try and run my project referencing the library that I've copied, my app throws an exception with NoClassDefFoundError. I've done some Googling and everything I have found suggests you have to provide the source code and let the user import into their IDE and then reference that project into their app which I don't want to do. It must be possible as other companies provide JAR files for libraries that can be included.
Thanks for your help.
I don't want to distribute the source code as it contains details on posting to my web server.
Bear in mind that anyone who wants to can get that data out of the JAR.
It must be possible as other companies provide JAR files for libraries that can be included.
AFAIK, this recipe still works:
Create an Android library project, with your source code, resources, and such, and get it working
Compile the Java source (e.g., via Ant) and turn it into a JAR file
Create a copy of your original Android library project to serve as a distribution Android library project
Place the compiled JAR from step #2 and put it in libs/ of the distribution library project from step #3.
Delete everything in src/ of the distribution library project (but leave the now-empty src/ directory there)
Distribute the distribution library project (e.g., ZIP it up)
This effectively gives you what you see with the Play Services SDK -- a library project with no source code, but instead a JAR in libs/, along with the resources and such.
I will be reconfiming this recipe tomorrow and will try to remember to update this answer if I find that it needs adjusting for the current crop of tools.
And the new Gradle-based build system supports the AAR package for distributing libraries and such, though I have not played with this yet.
UPDATE
This recipe works, so long as the library project does not itself have dependencies upon another JAR or library project. In those cases, things seem to get messed up in the build process -- everything can compile, but class references from the dependencies cannot be resolved at runtime.
Did you try putting your jar file in libs folder?And if you are exporting a jar library for android be sure it has no /res folder. As you know you can't reference to your res folder from a jar therefore you have to use library project to reference your res folder (drawable,xml,ect...)On the other hand you cant make your code safe (the part you say about posting to your web service) by using it as jar since it is so easy to retrieve by reverse engineering. you better use some encoding (like base64 or any algorithm that bouncycastle provides)
This seems to be a common issue when exporting jars with Eclipse. Now, my context.
I'm attempting to write Java plugins to use in Unity applications. When I did a simple plugin with no external libraries (except the classes.jar so I can call a UnityPlayerActivity), it worked pretty well. "Now, let's use some utils libraries". So I wrote a plugin which uses Jackson libraries to parse and process JSON data, so I can serialize it to a Java object, or just pass RAW data, then build a Unity (C#) object.
I add the libraries directly from the file system to the 'libs' folder (copying the .jars, not linking them), add to build path, check every one in the Order and Export, clean and build, and export to JAR file (not runnable, but simple JAR file). Then, I add my new .jar to Unity Assets/Plugins/Android folder, then build my .apk. As soon as the game starts, I get the classic NoClassDefFoundError because of a constructer using a Jackson class. Checking the .jar contents, I find that Jackson libraries are, indeed, exported and within the 'libs' folder, but still it won't "find" it. The error will be thrown by the main thread, thus the application will crash.
I'm using ADT with API 17, so the libs folder must be named 'libs' (even Eclipse does create this folder when creating a new Android project), JRE 1.6 and Jackson libraries ver. 2.2.0. Already followed a lot of questions here, but none of their suggestions has worked for me.
Any pointers here? Has the Android API version anything to do here? Is there something I'm not doing?
Thanks in advance.
I'm quite new to Java, but as far as I can tell when you use an external JAR file it is dynamically linked. In other words, it stays independent - it is not merged into your library.
This was obvious in my case: The external library I used was Google Analytics. Its JAR file, libGoogleAnalyticsV2.jar, is 126 KB. After I added it to my libs directory and built my library I got an output JAR file of only 2 KB...
My solution was to copy the external library JAR file to Assets/Plugins/Android, together with the JAR file I created.
I am using Salesforce SOAP API to do a simple login and logout program. I follow the sample code at http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_login.htm.
This code works fine on desktop.
Then, I port it to Android application with the generated jar file (it is sforce-client.jar) based on my WSDL file and the wsc.jar.
However, when I run it, I got the following error,
Could not find class 'com.sforce.soap.enterprise.EnterpriseConnection'
referenced from method salesforceAccess.SalesforceAccess.login
Do you have any idea what cause it and how to solve it?
Thank you so much for the help.
Ada
Did you add the jar file to the 'libs' directory and check the "Order and Export" checkbox under the properties?
If you followed the default instructions for building your jar from the WSDL, then you need to add both this generated jar, and the wsc.jar that you used to generate the jar to your android libs folder. From the error it sounds like you're missing the wsc.jar that you used to generate your jar from.
Alternatively you can set -Dstandalone-jar=true as an option when you generate your jar, and then everything will be in that one generated jar.
Finally, I solved the problem!
The steps are,
1. Build the correct wsc-xxx.jar file from github.com/forcedotcom/wsc (Thank you, Superfell!)
2. Generate the jar file from wsdl using the above wsc-xxx.jar. NOTE: using jdk1.6 to generate the target 1.6 jar. (or whatever match the Android SDK level!!)
3. Import the jars into the Android project.
I was stuck because I was using jdk1.7 to generate the jar file. However, like what this thread (Android emulator crash: "Dx bad class file magic" / ClassNotFoundException on startup?) said, the Android SDK level is 1.6 (I tried to change to 1.7, the project won't be able to compiled). Therefore, the generated jar file from wsdl won't be able to be packaged in!
The eclipse and ADT doesn't give me any warning or error to tell me. I have to build the Android project from command line (see http://randomsamples.info/blog/phil/android-adt-2101-javalangnoclassdeffounderror-rdimen) and noticed the warning,
[dx] trouble processing:
[dx] bad class file magic (cafebabe) or version (0033.0000)
[dx] ...while parsing com/sforce/soap/enterprise/EnterpriseConnection.cla
ss
[dx] ...while processing com/sforce/soap/enterprise/EnterpriseConnection. class
What a process!!
The situation I have is that I have an Android Project (regular) which uses Amazon AWS android libr jars (inside libs folder).
I recently cloned Autobahn (https://github.com/tavendo/AutobahnAndroid) and I'm using this library project on my own.
The problem is that Amazon library uses jackson and it's contained in aws jar core jars. Since Autobahn also has that dependenciy I'm getting the following exception when generating the apk:
java.lang.IllegalArgumentException: already added: Lorg/codehaus/jackson/Base64Variant;
Since I can't modify the amazon library, is there any way I can tell Autobahn project to do not "export" jackson libs dependencies into my own project?
The JAR at https://autobahn.s3.amazonaws.com/android/autobahn-0.5.0.jar is pure library only with Autobahn classes and no reference to Jackson.
The archive https://autobahn.s3.amazonaws.com/android/autobahn-0.5.0.zip contains - as a convenience - both the Autobahn and Jackson JARs.
When you are using Autobahn source from GitHub, that will contain project files (plus examples and so on), which then sets up the dependency on Jackson.
You can build your own JAR from the source by going to the Autobahn directory within the repo and do a ant jar. Then, only put that JAR into your project. That should work.
The problem is that Amazon library uses jackson and it's contained in aws jar core jars
:: grumble, grumble ::
is there any way I can tell Autobahn project to do not "export" jackson libs dependencies into my own project?
Not that I am aware of. But you could make your fork for Autobahn depend upon the AWS JAR instead and get rid of its own copy of Jackson. That presumes that Amazon's embedded Jackson is complete and compatible with Autobahn, though.
I had a very similar problem with Unable to execute dex: Multiple dex files define Lorg/codehaus/jackson/Base64Variant using Google Drive api's and Google Spreadsheet api's. This may help.
Tried all the usual Eclipse fix methods, clean, rebuilding, start/stopping Eclipse, new workspace, etc.
If you are using Eclipse, this is how I solved it without having to manage the .jar's.
1) In Eclipse, right click your project properties
2) Click on Java Compiler
3) Click on Building
4) Click on Configure Workspace Settings
5) Click on Enable project specific settings
6) Click on Output Folder
7) Click 'Rebuild class files modified by others'
Hope this helps.