我正在嘗試爲我的Android應用程序編寫測試測試。當我運行我的測試,和它擊中我的代碼試圖使用com.google.android.gms.vision.face.FaceDetector庫中的部分,測試框架拋出下列錯誤:由於com.google.android.gms.version元數據造成的Android儀器測試錯誤
A required meta-data tag in your app's AndroidManifest.xml does not exist. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
然而,我的AndroidManifest.xml已經不包含精確的元數據標籤,就在這裏:
<application
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="NeuralEye-FaceID-2"
android:theme="@style/Theme.AppCompat"
android:largeHeap="true">
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.vision.DEPENDENCIES"
android:value="face" />
我缺少什麼?我的儀表測試看起來是這樣的:
@RunWith(AndroidJUnit4.class)
public class FeatureExtractionTest {
public FeatureExtraction mFeatureExtraction;
public ConcurrentSkipListSet<String> skipList = new ConcurrentSkipListSet();
@Before
public void createFeatureExtraction() {
mFeatureExtraction = new FeatureExtraction();
}
@Test
public void testGetFeatures() throws Exception {
File file = new File("new.txt");
Context ctx = InstrumentationRegistry.getContext();
mFeatureExtraction.getFeatures(file, skipList, ctx);
}
}
編輯:添加的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "tuan.search"
minSdkVersion 21
targetSdkVersion 23
versionCode 1
versionName "0.5 "
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile files('libs/opencsv-3.7.jar')
compile 'com.android.support:support-v4:23.4.0'
compile 'com.google.android.gms:play-services:9.0.1'
compile 'com.android.support:design:23.4.0'
compile 'org.projectlombok:lombok:1.16.8'
compile 'com.android.support:multidex:1.0.0'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.android.support.test:runner:0.4'
androidTestCompile 'com.android.support.test:rules:0.4'
androidTestCompile 'com.android.support:support-annotations:23.4.0'
androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
}
任何幫助表示讚賞。我已經找到了一大堆SO答案,所有人都說將元數據標籤添加到清單(this one, for example),但是我已經添加了它,並且測試仍然不會通過FaceDetector庫。
請勿添加'google_play_services_version'。它會通過谷歌播放服務AAR自動添加。 –
@JaredBurrows你能澄清一下嗎?我試圖完全刪除標記,並試圖只刪除「android:value」屬性,並在兩個實例中,當測試運行時仍然收到相同的錯誤。 –
顯示build.gradle。 –