New issue 361 by perez...@gmail.com: Unable to load JacksonFactory class in
version 1.6.0-beta
http://code.google.com/p/google-api-java-client/issues/detail?id=361
Version of google-api-java-client (e.g. 1.5.0-beta)?
1.6.0-Beta
Java environment (e.g. Java 6, Android 2.3, App Engine)?
Java 6, Android 2.2
Describe the problem.
In the YouTube Sample code, when creating the final jsonFactory = new
JacksonFactory(), I get a runtime exception on the Android emulator saying
class not found, JacksonFactory. I included every possible library I could
within the dependencies including jackson-asl-core-1.9.1. Project built and
ran fine when running in regular Java environment, but I get class not
found when running on Android environment.
How would you expect it to be fixed?
Temporary work-around was to use google-api-java-client 1.5.1-beta and
the .jar's in the dependencies folder worked just fine, but they don't work
in 1.6.0-beta. I also tried using a previous version of
jackson-asl-core-1.6.7 with google java client 1.6.0-beta, no good. Maybe
there's something wrong with the set up in one of the libraries that is
causing this class to not get loaded.
Comment #1 on issue 361 by yan...@google.com: Unable to load JacksonFactory
class in version 1.6.0-beta
http://code.google.com/p/google-api-java-client/issues/detail?id=361
JacksonFactory should be unchanged between 1.5 and 1.6. Unfortunately I
suspect it is a problem with your set up. I would need more information in
order to reproduce it, including your setup. For example, one possible bug
I've seen in the past is that old versions of the Maven Eclipse plugin
added the dependencies to the compile classpath but not the runtime
classpath.
Note that the YouTube sample is actually a command-line sample, not an
Android sample.
This is exactly the same problem as I am having in my project. I am not
using Ant or Maven to build my Android project, just relying on Eclipse for
the time being.
The exception I was getting initially is as follows:
java.lang.NoClassDefFoundError:
com.google.api.client.json.jackson.JacksonFactory
This class is in google-http-client-1.6.0-beta.jar, which was added to
the "Referenced Libraries" section by Eclipse automatically when I added
google-api-client-1.6.0-beta.jar. I suspected that Eclipse treats it as a
compile-time dependency only (it even included a comment saying "(from
Class-Path of google-api-client-1.6.0-beta.jar)" next to the .jar file in
the Referenced Libraries section), so I added
google-http-client-1.6.0-beta.jar explicitly to the class path to make it a
runtime dependency. This resulted in another runtime exception:
java.lang.NoClassDefFoundError: org.codehaus.jackson.JsonFactory
This time I added jackson-core-asl-1.9.1.jar to the class path explicitly
(it was already there as a compile-time dependency), but then I got another
exception:
java.lang.NoClassDefFoundError: com.google.common.base.Preconditions
So I also added guava-r09.jar to the class path, but then I got the
dreaded "Conversion to Dalvik format failed with error 1", with the
following stack trace:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added:
Lcom/google/common/base/FinalizableReference;
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:123)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.dex.file.DexFile.add(DexFile.java:163)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.command.dexer.Main.processClass(Main.java:486)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.command.dexer.Main.processFileBytes(Main.java:455)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.command.dexer.Main.access$400(Main.java:67)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:394)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:245)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:131)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:109)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.command.dexer.Main.processOne(Main.java:418)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.command.dexer.Main.processAllFiles(Main.java:329)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.dx.command.dexer.Main.run(Main.java:206)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
java.lang.reflect.Method.invoke(Method.java:597)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.ide.eclipse.adt.internal.build.DexWrapper.run(DexWrapper.java:179)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.ide.eclipse.adt.internal.build.BuildHelper.executeDx(BuildHelper.java:729)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.ide.eclipse.adt.internal.build.builders.PostCompilerBuilder.build(PostCompilerBuilder.java:602)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:321)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:396)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.resources.Project$1.run(Project.java:618)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2344)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.resources.Project.internalBuild(Project.java:597)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.resources.Project.build(Project.java:124)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.ide.eclipse.adt.internal.project.ProjectHelper.build(ProjectHelper.java:869)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
com.android.ide.eclipse.adt.internal.launch.LaunchConfigDelegate.launch(LaunchConfigDelegate.java:146)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:854)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.debug.internal.core.LaunchConfiguration.launch(LaunchConfiguration.java:703)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.debug.internal.ui.DebugUIPlugin.buildAndLaunch(DebugUIPlugin.java:928)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.debug.internal.ui.DebugUIPlugin$8.run(DebugUIPlugin.java:1132)
[2011-12-04 01:20:27 - Discovr Music for Android] Dx at
org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Apparently, it is trying to add guava-r09.jar *twice* to the .dex file. At
this point I'm kinda stuck. Any ideas?
java.lang.NoClassDefFoundError: org.codehaus.jackson.JsonFactory
java.lang.NoClassDefFoundError: com.google.common.base.Preconditions
[
Same problem here. All jars have been added to my lib folder (app engine
project) and have been included as referenced libraries. Looking in the
Jar for Jackson, you can see the jSonFactory inside, but for some reason
there is a bad reference it seems inside the jar.
Can compile build but when testing Android VM returns:
Could not find class 'org.codehaus.jackson.JsonFactory', referenced from
method com.google.api.client.json.jackson.JacksonFactory.<init>
VFY: unable to resolve new-instance 1782
(Lorg/codehaus/jackson/JsonFactory;) in
Lcom/google/api/client/json/jackson/JacksonFactory;
VFY: rejecting opcode 0x22 at 0x0003
VFY: rejected Lcom/google/api/client/json/jackson/JacksonFactory;.<init>
()V
Verifier rejected class Lcom/google/api/client/json/jackson/JacksonFactory;
Shutting down VM
threadid=3: thread exiting with uncaught exception (group=0x4001db80)
I am getting the same error as mentioned in comment(3).
#6: if you are also getting the "Conversion to Dalvik format failed with
error 1" message, I managed to resolve that. Actually, the stack trace was
right, it was really trying to add
com.google.common.base.FinalizableReference twice, but not because of
guava-r09.jar. It turned out that my project also had Droid-Fu as a
dependency, and the JAR file of Droid-Fu contains Guava already, so one
copy of Guava came from google-http-client as a transitive dependency,
while the other copy of Guava was shipped with Droid-Fu. I resolved things
by re-packaging Droid-Fu and excluding Guava from it.