微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – 无法解析符号AndroidJUnit4

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

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)

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'

解决方法

尝试
androidTestCompile 'com.android.support:support-annotations:23.1.0'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'

添加以下依赖项部分

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

原文地址:https://www.jb51.cc/android/129914.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐