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:
download it with adb tool
adb pull /data/app/com.my.lib.test-2/base.apk
unzip base.api & I get the classes.dex from it
check the content of classes.dex by run command
dexdump classes.dex
, output is:
Does it mean codehaus/jackson/JsonFactory
is only accessed but not included?