Given an Android project in Eclipse build from 2 projects:
Project 1 is a Java library, which compiles just fine on Android.
Project 2 are test cases for the library, essentially classes extending AndroidTestCase
and outputting results to the Android console.
Project 1 is a Java project, Project 2 is an Android project depending on Project 1.
Problem Description: If I execute the tests from Eclipse as Android JUnit Tests they run just as they should, no errors. However, if I want to execute them again by commandline:
adb shell am instrument -w bla.bla/android.test.InstrumentationTestRunner
I get a lot of
Cannot load class. Make sure it is in your apk. Class name: xyz
java.lang.ClassNotFoundException: xyz
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:234)
at android.test.ClassPathPackageInfoSource.createPackageInfo
....
Caused by: java.lang.ClassNotFoundException: xyz in loader
dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/bla.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
....
errors in logcat.
Observations:
Eclipse installs the .apk.
Later I execute the same already installed .apk, so the classes available must be the same.
Classes are dynamically requested with Class c = Class.forName("xyz")
.
So my the question is, how does Eclipse execute the installed .apk differently so that the proper classes are found at runtime?
Are you sure xyz.class is in CLASSPATH?
I had the same problem and was just this!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With