5

I have two projects:

  • one is my android library project (com.my.lib),
  • one is a test project to test the library project (com.my.lib.test).

In the test project, there is a test class which tests the corresponding class in library project which imports & uses org.codehaus.jackson.JsonFactory class.

In test project, I have added dependency in maven build :

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.13</version>
</dependency>

and

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-core-asl</artifactId>
    <version>1.9.13</version>
</dependency>

The AndroidManifest.xml of test project is like this:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.my.lib.test"
          android:versionCode="1"
          android:versionName="1.2" >
  <instrumentation
      android:name="android.test.InstrumentationTestRunner"
      android:targetPackage="com.my.lib" />

  <uses-sdk
      android:minSdkVersion="14"
      android:targetSdkVersion="21" />

  <application>
    <uses-library android:name="android.test.runner" />
  </application>

</manifest>

when I run instrumentation test, my tests are executed, but when executing that particular test class, I always get the following runtime error:

java.lang.ClassNotFoundException: Didn't find class "org.codehaus.jackson.JsonFactory" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/com.my.lib.test-2/base.apk", zip file "/data/app/com.my.lib-1/base.apk"],nativeLibraryDirectories=[/data/app/com.my.lib.test-2/lib/arm, /data/app/com.my.lib-1/lib/arm, /vendor/lib, /system/lib]]
07-06 18:06:08.041 24082 24998 E AndroidRuntime:    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
07-06 18:06:08.041 24082 24998 E AndroidRuntime:    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)

So, the above log complains that it couldn't find org.codehaus.jackson.JsonFactory class on those paths.

BUT, when I unzip my test project's APK file (MyLibTest.apk), and check the content of classes.dex by using Android SDK provided dexdump tool, I see the org/codehaus/jackson/JsonFactory is there!

here is the command and output:

dexdump classes.dex | grep 'org.codehaus.jackson.JsonFactory'

      type          : 'Lorg/codehaus/jackson/JsonFactory;'
      type          : 'Lorg/codehaus/jackson/JsonFactory;'

Why I get ClassNotFoundException though I can find this class in classes.dex of test project's APK file?

=== UPDATE ===

Since the error log shows it tries to find from path "/data/app/com.my.lib.test-2/base.apk"

So, I also tried to download that base.apk, and check what is there by:

  1. download it with adb tool

    adb pull /data/app/com.my.lib.test-2/base.apk

  2. unzip base.api & I get the classes.dex from it

  3. check the content of classes.dex by run command dexdump classes.dex , output is:

enter image description here

Does it mean codehaus/jackson/JsonFactory is only accessed but not included?

Community
  • 1
  • 1
Leem.fin
  • 40,781
  • 83
  • 202
  • 354
  • Can you confirm you're not facing the problem described here? http://android.foxykeep.com/dev/how-to-fix-the-classdefnotfounderror-with-adt-17 – ck1 Jul 16 '16 at 20:06
  • Please tell which version of java target and android build tools do you use? PS: it means that your classes byte code has link to `jackson` classes byte code but the last was not compiled for some reason. I had this problem when I tried to include library written in Java 1.7 to project that was compiled by 1.6. – Sieva Kimajeŭ Jul 17 '16 at 05:32
  • Have you found a solution? I am facing the same problem. – Hong Aug 05 '21 at 03:49

0 Answers0