简体   繁体   English

使用集成测试时,Gradle无法从AndroidManifest.xml中正确获取元数据

[英]Gradle doesn't pick up meta-data correctly from AndroidManifest.xml when using integration testing

Quick summary: I am trying to do integration testing using gradlew connectedAndroidTest on Android Studio 1.2.2 but I get the following error: 快速摘要:我正在尝试使用Android Studio 1.2.2上的gradlew connectedAndroidTest进行集成测试,但是我收到以下错误:

Position 28:28-65 : No resource found that matches the given name (at 'value' with value '@integer/google_play_services_version').
Position 31:28-51 : No resource found that matches the given name (at 'value' with value '@string/google_maps_key').

Full story: I have two different AndroidManifest.xml, one for release and one for integration/instrumentation testing. 全文:我有两个不同的AndroidManifest.xml,一个用于发布,一个用于集成/检测测试。

I execute my instrumentation tests using: 我使用以下方法执行仪器测试:

gradlew connectedAndroidTest

This uses AndroidManifest.xml located at .../src/androidTest/ and builds and runs the android tests. 这使用位于... / src / androidTest /的AndroidManifest.xml并构建并运行android测试。 It looks like this: 它看起来像这样:

<uses-sdk android:targetSdkVersion="22" android:minSdkVersion="15"/>

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application>
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="@string/google_maps_key" />

    <uses-library android:name="android.test.runner"/>
</application>

<instrumentation android:name="android.test.InstrumentationTestRunner"
    android:label="Tests for com.company.app"
    android:functionalTest="false"
    android:handleProfiling="false"
    android:targetPackage="com.company.app"/>

</manifest>

When I run the app by itself (not the integration testing bit) it works properly, ie it picks up the google play version and the google maps key. 当我单独运行应用程序(而不是集成测试位)时,它可以正常运行,即它可以获取谷歌播放版本和谷歌地图密钥。 However, I get the above error when I do integration testing using the above AndroidManifest.xml. 但是,当我使用上面的AndroidManifest.xml进行集成测试时,我得到了上述错误。

It has got something to do with gradle using the above given AndroidManifest.xml to generate another one, but in doing so it doesn't pick up the value of "@integer/google_play_services_version" but rather just uses it as a literal. 它与gradle有关,使用上面给出的AndroidManifest.xml来生成另一个,但是这样做它不会获取“@ integer / google_play_services_version”的值,而只是将它用作文字。

Any help would be much appreciated. 任何帮助将非常感激。 Thanks 谢谢

EDIT 编辑

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.minttea.halalit"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.loopj.android:android-async-http:1.4.6'
    compile 'com.google.android.gms:play-services:6.+'

    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:2.0.8-beta'
    testCompile 'org.json:json:20141113'
    androidTestCompile 'junit:junit:4.12'
}

I guess it's because it's trying to find these resources in the test resources. 我想这是因为它试图在测试资源中找到这些资源。 As a quick solution, try creating res folder under androidTest/ and duplicating the requested resources there. 作为一个快速解决方案,尝试在androidTest/下创建res文件夹,并在那里复制所请求的资源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 应用程序AndroidManifest.xml中的必需元数据标记不存在。 - A required meta-data tag in your app's AndroidManifest.xml does not exist. 华为设备:您应用的AndroidManifest.xml中的元数据标签的值不正确 - Huawei devices: The meta-data tag in your app's AndroidManifest.xml does not have the right value IllegalStateException:您应用的 AndroidManifest.xml 中的元数据标记没有正确的值 - IllegalStateException : The meta-data tag in your app's AndroidManifest.xml does not have the right value 没有`<meta-data android:name="flutterEmbedding" android:value="2" /> ` 在 "..\src\main\AndroidManifest.xml" - No `<meta-data android:name="flutterEmbedding" android:value="2"/>` in "..\src\main\AndroidManifest.xml" AndroidManifest.xml中的元数据标记没有正确的值 - The meta-data tag in AndroidManifest.xml does not have the right value 任务“:app:processDebugManifest”执行失败:重复<meta-data /> AndroidManifest.xml 中的元素 - Execution failed for task ':app:processDebugManifest': Dupicate <meta-data/> element in AndroidManifest.xml 将 google_analytics_adid_collection_enabled 元数据标记添加到 Cordova AndroidManifest.xml - Adding google_analytics_adid_collection_enabled meta-data tag to Cordova AndroidManifest.xml 应用的AndroidManifest.xml中的元数据标记没有正确的值 - The meta-data tag in your app's AndroidManifest.xml does not have the right value 每当我在元数据部分添加某个库并修改 androidmanifest.xml 时,flutter 应用程序都会崩溃 - Whenever I add a certain library and modify androidmanifest.xml on meta-data section, flutter app keeps crashing 您应用的 AndroidManifest.xml 中的元数据标记没有正确的值。 - 谷歌地图 - The meta-data tag in your app's AndroidManifest.xml does not have the right value. - Google Maps
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM