我写了一个示例代码并收到了这些错误。
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/