Android ADT 21 NoClassDefFoundError - android

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!!

Related

how to resolve a conflict between two Jar files that reside in separate Libraries within my project?

I wrote a project using Google Maps which imports classes from android.jar
and maps.jar, both of which sit in Android Private Libraries within by project's Build Path.
After receiving several
"fix error in project before running it"
messages from Android Launch and not finding any errors in the code, I saw a warning in Window>>Problems that my project was lacking JRE System files, so I added JRE System Library (jre.8.0_31) to my project's Build Path.
I tried to run my project and got a Console error message
Conversion to Dalvik format failed with error 1
Dx trouble processing "javax/xml/parsers/SAXParser.class":
which according to
/questions/2680827/“Conversion to Dalvik format failed with error 1" on external JAR
may result from a conflict between identical packages in different jar files. I checked and in my case there is a conflict between packages in android.jar (in my Android Private Libraries) and rt.jar (in the JRE System Library).
I don't know what to do:
My project imports classes from android.jar so I can't get rid of that.
rt.jar is part of JRE System Library which is probably needed.
I have tried to extract packages from android.jar to include them by themselves in my Build Path, but couldn't find how to do this.
I have been stuck on this for days.Does anyone have any pointers, please?

Exporting .jar to use in Unity with 3rd-party libs included: NoClassDefFoundError

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.

android Jersey api client create NoClassDefFoundError

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

'Conversion to Dalvik format failed with error 1' and 'java.lang.IllegalArgumentException: already added: '

I'm having this problem since I installed the new SDKs. I've read about this happening when I try to link the same class to the build twice.
But here is the peculiar thing about it:
I have an Android library project that includes a class folder on the build path.
I have this library project included in one of my regular Android projects.
I have to include the class folder in this regular project as well to make it build.
This when the error occurs.
But when I do either of the following:
Remove the class folder from the library project: The library project won't build, so the regular project won't either.
Remove the class folder from the regular project: The library project builds, but the regular project won't because it misses the class files (?!).
I seem to be stuck in some unsolvable paradigm here.
Maybe there are build rules to circumvent this?
Any help would be greatly appreciated!
Apparently the way Android library projects are linked has changed.
Before, the library's source folder would be linked to the build path.
With the new solution the library is apparently built to a jar file in its own 'bin' folder.
This is then linked as an external jar to the build path of the project using the library.
To make the conflict dissappear, do two things:
Remove the source folder link in Project properties->Java Build Path->Source
Clean the project. Perhaps clear your projects 'bin' folder manually.
Now it should work again! :)

How to include JAR in APK without Eclipse?

I maintain an Android app and am not using Eclipse. I am not using Eclipse. I am using ant and build.xml and build.properties.
I have places my .jar file into the libs/ directory. My code compiles just dandy. But when I run it on the emulator, the output APK does not include the .jar, so I get a runtime stacktrace:
ERROR/AndroidRuntime(470): java.lang.NoClassDefFoundError: com.google.ads.AdView
my build.properties looks like this:
jar.libs.dir=libs
And the libs/ directory contains my .jar file.
What needs to be in build.xml so that the external .jar file is included in the APK?
Edit: In theory this answer should work, but it doesn't for me. Is it out of date? What gives? How to add external jar libraries to an android project from the command line
I just came over a similar problem and noticed that libraries should not be placed in "myprojectdir\lib". When I moved them to "myprojectdir\libs" everything started to work.
It turns out that I needed to upgrade the version of ant I was using to 1.8. During the compile process, I had been getting this error message:
Warning: Reference out.dex.jar.input.ref has not been set at runtime,
but was found duringbuild file parsing, attempting to resolve. Future
versions of Ant may support referencing ids defined in non-executed
targets.
I googled it, and found that I needed to upgrade Ant, and now I don't get this warning, and my application does not force close.
What needs to be in build.xml so that the external .jar file is included in the APK?
Just putting it in libs/ is sufficient.
my build.properties looks like this:
That line should not be necessary. It does not appear in my build.properties files that build successfully with JAR files.
If you use dexdump -f classes.dex from your project's bin/ directory, you will be able to determine whether com.google.ads.AdView made it in there. If it did not, then something is strange with your build scripts. If it did, then perhaps there is a dependent JAR that you are missing (though I would expect a VerifyError in that case).
You use 3rd party library, but you seem didn't run DX on it. Make sure that not only your code processed by DX tool (I assume Ant does it), but also all 3rd party libraries you use. You can look in 7Bee script I use to convert web applications to Android davlik format, so it can work for you too. You can find more about the script on Atjeews page.
Solution:
right click on the project in project tree and select Project
properties
select Java Build Path
select TAB Order
and Export
check GoogleAdMobAdsSdk-4.0.4.jar (or your
version SDK)
press OK
clean project by menu Project
-> Clean
rebuild project (Project – Build Automatically)

Categories

Resources