【问题标题】:Using custom attributes with Android Instrumentation Tests在 Android Instrumentation 测试中使用自定义属性
【发布时间】:2011-10-27 20:55:53
【问题描述】:

我有一个包含两个子项目(应用程序和仪器测试)的 android 项目。在我向我的应用程序添加一些自定义属性(res/values/attrs.xml)之前,一切都使用 maven-android-plugin 构建得很好。 要使用自定义属性,我必须在我的引用 xml 文件 (res/xml/someFile.xml) 中定义一个新的命名空间: <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fosslab="http://schemas.android.com/apk/res/org.fosslab.android.hazard"> 应用程序本身构建良好,但仪器测试项目在 AndroidManifest.xml 中声明了另一个包名称,这就是无法构建仪器测试项目的原因。

错误是:hazard-it/res/xml/settings_filter.xml:4: error: No resource identifier found for attribute 'stepSize' in package 'org.fosslab.android.hazard'

在构建检测项目之前,将 res/*(来自应用项目)中的所有文件复制到检测项目。

错误似乎很明显,因为对于仪器测试,命名空间声明应该是 org.fosslab.android.hazard.tests。

有谁知道如何为仪器测试自动进行此类更改。或者我可以离开命名空间并在我的仪器测试项目中更改其他内容吗?

编辑: 通过从仪器项目中删除整个 res 文件夹并停止将资源从应用程序复制到仪器来解决问题。 标记为 pom.xml 中提供的应用 apklib 和应用 jar 并且一切似乎都在工作。

【问题讨论】:

    标签: android testing maven instrumentation


    【解决方案1】:

    您的解决方案确实允许编译项目,但它没有将其包含到 dex 文件中。

    我能够通过使用这样的命名空间来解决这个问题:

    xmlns:something="http://schemas.android.com/apk/lib/the.package.name"
    

    注意/lib/ 而不是/res/

    【讨论】:

      猜你喜欢
      • 2011-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多