4

Quick summary: I am trying to do integration testing using gradlew connectedAndroidTest on Android Studio 1.2.2 but I get the following error:

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.

I execute my instrumentation tests using:

gradlew connectedAndroidTest

This uses AndroidManifest.xml located at .../src/androidTest/ and builds and runs the android tests. 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, i.e. 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.

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.

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'
}
amirhbp
  • 185
  • 1
  • 1
  • 7

1 Answers1

0

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.

AndroidEx
  • 15,524
  • 9
  • 54
  • 50
  • Hi @Android777, neither of the values are in the `res` folder of the main resources. `google_maps_key` is in `debug/res/values/google_maps_api.xml` and `release/res/values/google_maps_api.xml`. The `google_play_services_version` is specified under `R.java`, so I guess it's auto generated. – amirhbp Jul 14 '15 at 07:53
  • @amirhbp yes, my bad, of course you're right. Here's another idea: take a gradle copy task from [this question](http://stackoverflow.com/questions/17213236/how-to-run-copy-task-with-android-studio-into-assets-folder) and change origin to your generated main resources and destination to the generated test resources. Use `${buildDir}` to start your relative paths in the generated folder. – AndroidEx Jul 14 '15 at 12:16
  • this might be very trivial but how do I find out where the generated resources are. – amirhbp Jul 14 '15 at 16:16
  • @amirhbp I cannot test it right now but I would try something like "${buildDir}/intermediates/res/debug/values/" or "${buildDir}/intermediates/res/main/debug/values/", check the structure/contents of your local `/build` folder. Tell me how this turns out. – AndroidEx Jul 14 '15 at 16:22
  • so I after hours of researching, I managed to get gradle to copy the generated sources over to the test folder. The problem is, this folder gets deleted at task `processDebugAndroidTestResources`. This also happens to be the task that throws the error. So basically, `processDebugAndroidTestResources` deletes the test generated sources directory and then attempts to read the AndroidManifest.xml – amirhbp Jul 14 '15 at 21:41
  • @amirhbp hmm, one more crazy test: set your copy task `.dependsOn(processDebugAndroidTestResources)` so that it's launched after it. – AndroidEx Jul 14 '15 at 21:43
  • I'm fairly new to gradle but would it be possible to reference the google play version and the google maps key from build.gradle? If so, how can I go about it. ta – amirhbp Jul 14 '15 at 21:50