4

Ich versuche, Loginfacebook für meine App hinzuzufügen. Aber wenn ich ein Repository hinzugefügt habe, ist das nötig. Es hat einen Fehler verursacht. Die AndroidJUnit4 kann jetzt nicht aufgelöst werden.Kann Symbol nicht auflösen 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()); 
} 
} 


apply plugin: 'com.android.application' 

und das ist mein Build: gradle (app)

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' 

Antwort

4

Versuchen

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' 

Add über folgende Abhängigkeiten Abschnitt

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

Ich habe es versucht, aber es zeigt einen Fehler: Warnung: Konflikt mit Abhängigkeit 'com.android.support:support-annotations'. Gelöste Versionen für App (25.0.0) und Test-App (23.1.1) unterscheiden sich. Details finden Sie unter http://g.co/androidstudio/app-test-app-conflict. –

+0

Aktualisierte Antwort. http://stackoverflow.com/questions/33317555/conflict-with-dependency-com-android-supportsupport-annotations-resolved-ver – Pehlaj

+0

es funktioniert jetzt. Vielen Dank :) –

0

Zusätzlich zu der obigen Antwort bitte sicher, dass Sie diese Schritte streng folgen:

ich meinen Kopf gegen die Wand hämmerte und/oder ein beliebiges Objekt ich sehe meine SQLite-Funktionseinheit vor mir zu machen, um geprüft. Egal, was ich tue, wie streng folgen Sie den Vorschlägen, die meine vielen weisen Menschen im ganzen Internet nicht funktionierten.

Ich musste dann zu Vorschule gehen und neu beginnen, um meinen dummen Fehler zu realisieren. Ich habe gelernt, dass AndroidJUnit4 nur mit Instrumentation Test verwendet werden kann und JUnit für lokale Tests verwendet werden muss. Der Ordner muss src/androidTest/java sein. Ich hatte meine Test-Klasse direkt unter androidTest Ordner, daher musste ich diesen ekligen Fehler sehen. Aber in dem Moment, als ich es unter src/androidTest/java alles ging ging sehr klar wie "kann ich deutlich sehen, jetzt ist der Regen weg".

Take a look at this article, die sagt ...

Run Instrumented Unit Tests To run your instrumented tests, follow these steps:

Be sure your project is synchronized with Gradle by clicking Sync Project in the toolbar. Run your test in one of the following ways: To run a single test, open the Project window, and then right-click a test and click Run . To test all methods in a class, right-click a class or method in the test file and click Run . To run all tests in a directory, right-click on the directory and select Run tests . The Android Plugin for Gradle compiles the instrumented test code located in the default directory (src/androidTest/java/), builds a test APK and production APK, installs both APKs on the connected device or emulator, and runs the tests. Android Studio then displays the results of the instrumented test execution in the Run window.

Deshalb Leute, für Instrumentierung Test muss der Ordner sein (vergessen Sie nicht, den Fall)

src/androidTest/java

und für lokale Tests Der Ordner muss

sein 10

src/test/java

Sie dann Ihr Paket Ordner (n) haben können Ihre App-Paket

Hope, das hilft für die Gemeinschaft entsprechen!

Verwandte Themen