我在使用 android maven 插件执行仪器测试时遇到问题。 然而,我已经按照“libraryprojects”示例进行了最后的细节, 我的设置略有不同〜我将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 的 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)
由于未将 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-support 依赖关系。
任何想法将不胜感激, -迈克尔
最佳答案
我不确定,但我怀疑这可能是一种解释:
关于java - 测试 APK 无法从主 APK 解析/加载类 ~ 无法加载类 'android.support.v4.os.ParcelableCompatCreatorHoneycombMR2',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12087948/