Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2'

Showing 1-7 of 7 messages
Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2' blizzard 8/23/12 1:56 AM
Hello everyone,

I'm having trouble executing instrumentation tests using the android maven plugin. I have followed the "libraryprojects" example to the last detail, however, there is one slight difference in my setup ~ i'm adding the android support jar as an external dependency.

My setup looks as follows:

APK lib project (greendroid to be specific)

<dependency>
  <groupId>com.google.android</groupId>
  <artifactId>support-v4</artifactId>
  <version>r6</version>
</dependency>        

<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>android</artifactId>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <scope>test</scope>
</dependency>
APK project

<dependency>
    <groupId>com.google.android</groupId>
    <artifactId>android</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>greendroid</groupId>
    <artifactId>GreenDroidFragment</artifactId>
    <version>1.0.0-SNAPSHOT</version>  
    <type>apklib</type>                
</dependency>
APK test project (and here's the problem .... )

<dependency>
      <groupId>com.google.android</groupId>
      <artifactId>support-v4</artifactId>
      <version>r6</version>
</dependency>                  
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android-test</artifactId>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.jayway.android.robotium</groupId>
        <artifactId>robotium-solo</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>com.entersectmobile</groupId>
        <artifactId>NMACFragment</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>apk</type>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.entersectmobile</groupId>
        <artifactId>NMACFragment</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>jar</type>
        <scope>provided</scope>
    </dependency>  
The problem is that delvik is unable to find or link support jar upon running instrumentation tests.

By packaging the android support jar as part of the APK test project, delvik complains that it's unable to resolve the compiled code. This is because the dex output of the main APK is different from the dex output of the test APK.

W/dalvikvm(328): Class resolved by unexpected DEX:      
Lcom/entersectmobile/android/nedbank/GenerateOtpFragment;(0x44edffb0):0x121de0 ref  
[Landroid/support/v4/app/Fragment;] Landroid/support/v4/app/Fragment;(0x44edffb0)
By not packaging the android support as part of the APK test project, delvik is unable to locate the compiled code. This happens when making the scope provided or excluding the dependency completely.

W/ClassPathPackageInfoSource(632): Cannot load class. Make sure it is in your apk.
Class name: 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2'.
Message: android.support.v4.os.ParcelableCompatCreatorHoneycombMR2
The only thing I can think of is to somehow manually tell the APK test project to resolve the android-support dependency from the main APK project using a delvik linking mechanism.

Any ideas would be much appreciated,
Thanks
-Michael

Re: Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2' blizzard 8/28/12 12:43 AM
I've had a major breakthrough on this.

My conclusion thus far is that android instrumentation tests do not support 
FragmentActivity or other activity wrappers at this point in time.

-Michael
Re: Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2' Sesso Deluca 8/28/12 2:31 AM
I'm trying to understand mavens purpose
Re: Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2' blizzard 8/29/12 1:35 AM
The purpose of Maven ?

Configuration controle ... release management ... reporting .... the list goes on and on.
However, the problem I experience above occurs on both maven and ant builds.
Re: Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2' Patrick Boos 10/25/12 5:12 PM
Experiencing same problem. If I run the tests through eclipse they run fine on 2.3.
But installing the apks by hand through adb and then running:
adb shell am instrument -w ${TEST_PACKAGE_NAME}/android.test.InstrumentationTestRunner

Gives me the given error. So questions is. What is different between how eclipse runs those tests?
Re: Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2' Patrick Boos 10/25/12 7:06 PM
I think I found the problem. It has to do with RUNNING ALL TESTS. Run each test case one by one and the problem does not occur. No idea why. Maybe a bug in running all tests?

For example. I have my SampleActivityTest extends SingleLaunchActivityTestCase<...>.
This will have the problem:
adb shell am instrument -w jp.cyberagent.testgrid.android.sample.test/android.test.InstrumentationTestRunner

Adding "-e package jp.cyberagent.testgrid.android.sample.test" has the same problem.

whereas this will run it okay:
adb shell am instrument -w -e class jp.cyberagent.testgrid.android.sample.test.SampleActivityTest jp.cyberagent.testgrid.android.sample.test/android.test.InstrumentationTestRunner

Now the question is: WHY?
Re: Android maven plugin: Adding android support jar to test project ~ Cannot load class 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2' Patrick Boos 10/25/12 7:12 PM
To clarify. Eclipse has the same problem. I on accident tested the single test only where it worked.