我在使用android maven插件执行仪器测试时遇到问题。然而,我已经遵循了"图书馆项目"的例子,直到最后一个细节,我的设置有一点不同~我添加了android支持jar作为外部依赖。
我的设置如下:
-
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项目
<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测试项目(这里的问题…)
<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>
问题是delvik在运行仪器测试时无法找到或链接支持jar。
我的问题是,我如何告诉delvik针对主应用程序APK解决测试APK中所需的文件?理论上,将所需依赖项(android support jar)的范围设置为在测试APK中提供应该有效,但它不起作用。
以下是我试验过的一些场景:
-
通过将android支持jar打包为APK测试项目的一部分,delvik抱怨无法解析编译的代码。这是因为主APK的dex输出与测试APK的index输出不同。
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)
-
由于没有将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
我唯一能想到的就是以某种方式手动告诉APK测试项目,使用delvik链接机制解决主APK项目对android支持的依赖。
任何想法都将不胜感激,-Michael
我不确定,但我怀疑这可能是一种解释:
仪器测试扫描apk。。。不是问题