[英]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.