测试APK不从主APK解析/加载类~无法加载类'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2'

时间:2023-01-18 10:23:15

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.

我在使用android maven插件执行测试时遇到了麻烦。我已经按照“libraryprojects”的示例进行了最后的细节,但是,我的设置有一点不同——我添加了android support jar作为外部依赖项。

My setup looks as follows:

我的设置如下:

  • APK lib project (greendroid to be specific)

    APK lib项目(具体说是greendroid)

    <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

    APK项目

    <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 .... )

    APK测试项目(这是问题....)

    <dependency>
          <groupId>com.google.android</groupId>
          <artifactId>support-v4</artifactId>
          <version>r6</version>
                      <scope>provided</scope>
    </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.**</groupId>
            <artifactId>**</artifactId>
            <version>1.0.0-SNAPSHOT</version>
            <type>apk</type>
            <scope>provided</scope>
        </dependency>
    
        <dependency>
            <groupId>com.**</groupId>
            <artifactId>**</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.

问题是delvik在运行测试时无法找到或链接支持jar。

My question is, how do I tell delvik to resolve required files within the test APK against the main application APK ? Theoretically, setting the scope of the required dependency (android-support jar) to provided within the test APK should work, but it does not.

我的问题是,如何告诉delvik针对主应用程序APK在测试APK中解析所需的文件?理论上,在测试APK中设置所需依赖项的范围(android-support jar)应该是可行的,但它不行。

Below are some scenarios that I experimented with:

下面是一些我尝试过的场景:

  • 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.

    通过将android支持jar打包为APK测试项目的一部分,delvik抱怨它无法解析已编译的代码。这是因为主APK的dex输出与测试APK的dex输出不同。

    W/dalvikvm(328): Class resolved by unexpected DEX:      
    Lcom/**/android/**/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.

    由于没有将android支持打包为APK测试项目的一部分,delvik无法定位编译后的代码。这发生在提供范围或完全排除依赖项时。

    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.

我能想到的唯一一件事是,以某种方式手动告诉APK测试项目,使用delvik链接机制从主APK项目中解决android-support依赖。

Any ideas would be much appreciated, -Michael

任何想法都将非常感谢,迈克尔

1 个解决方案

#1


0  

I am not sure, but I suspect this might be an explanation:

我不确定,但我怀疑这可能是一种解释:

Instrumentation tests scanning apk...not an issue

仪器测试扫描apk……不是一个问题

#1


0  

I am not sure, but I suspect this might be an explanation:

我不确定,但我怀疑这可能是一种解释:

Instrumentation tests scanning apk...not an issue

仪器测试扫描apk……不是一个问题