android - 什么是错误包 androidx 和 Android JUnit 4?

标签 android package

enter image description here

我写了一个示例代码并收到了这些错误。

error: cannot find symbol class Android J Unit 4.

error: package android x test ext j unit runners does not exist

我安装了最新版本的 android studio 并在运行每个代码后收到这些错误。

错误是什么意思?

代码:

package com.example.hello;

public class JavaBasics {
    public static void main(String args[]){
        System.out.println("Hello World");
    }
}

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.example.hello"
        minSdkVersion 14
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.2.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

最佳答案

我解决了.. 我必须使用

@RunWith(AndroidJUnit4.class)

在 . java和

androidTestImplementation 'androidx.test.ext:junit:1.1.1'

在应用程序中(build.grade)

关于android - 什么是错误包 androidx 和 Android JUnit 4?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57785389/

相关文章:

javascript - React Native 0.61.0 中的 MainApplication.java

Java NoClassDefFounderror 尝试运行时出错

android - 如何使用 JSON 将记录插入 SQL 数据库

java - 围绕 java 类传递数据

android - 用于将联系人添加到 whatsapp 的 HTML 链接

wix - 如何使用开源软件创建自己的 MSI 包?

python - 在 Python2.7 上安装 tkMessageBox

java - Android单列Gridview

android - 如何在 ActionBarSherlock 中更改大屏幕上的布局

android - 检测安装的应用程序