无法解析符号 AndroidJUnit4 [英] Cannot resolve symbol AndroidJUnit4

查看:32
本文介绍了无法解析符号 AndroidJUnit4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的应用添加 loginfacebook.但是当我添加了一个需要这样做的存储库时.它导致了错误.AndroidJUnit4 现在无法解析.

I'm trying to add loginfacebook for my app. But when I added a repository that is need in doing this. It caused an error. The AndroidJUnit4 cannot resolve now.

ExampleInstrumentedTest.java

package com.example.user.enyatravelbataan;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.*;

/**
 * Instrumentation test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.example.user.enyatravelbataan", 
appContext.getPackageName());
}
}

这是我的构建:gradle(app)

and this is my build:gradle(app)

apply plugin: 'com.android.application'

 android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
useLibrary 'org.apache.http.legacy'


repositories {
    mavenCentral()
}

defaultConfig {
    applicationId "com.example.user.enyatravelbataan"
    minSdkVersion 16
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile(name: 'wikitudesdk', ext: 'aar')
// compile 'org.apache.httpcomponents:httpclient:4.5'
// compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile files('libs/MD5Simply.jar')
compile files('libs/GenAsync.1.2.jar')
compile 'com.facebook.android:facebook-android-sdk:[4,5)'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services:9.8.0'
compile 'com.google.android.gms:play-services-location:9.8.0'
compile 'com.google.android.gms:play-services-appindexing:9.8.0'
compile 'com.android.support:cardview-v7:24.2.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.android.support:design:24.2.1'
compile 'com.android.volley:volley:1.0.0'
compile 'com.android.support:support-v4:24.2.1'

testCompile 'junit:junit:4.12'
}

repositories {
flatDir {
    dirs 'libs'
}
}
apply plugin: 'com.google.gms.google-services'

推荐答案

尝试

androidTestImplementation 'com.android.support:support-annotations:23.1.0'
androidTestImplementation 'com.android.support.test:runner:0.4.1'
androidTestImplementation 'com.android.support.test:rules:0.4.1'

在依赖项部分添加以下内容

Add following above dependencies section

configurations.all {
   resolutionStrategy.force 'com.android.support:support-annotations:23.1.0'
}

这篇关于无法解析符号 AndroidJUnit4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆