Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve junit:junit:4.12
I create an new android project It shows errors on built
I tried the exiting answers
- Failed to resolve: com.android.support:appcompat-v7 24.0.1
- I tried to invalidate and restart android studio
Error are
Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve junit:junit:4.12.
Error:Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve junit:junit:4.12.
Error:Unable to resolve dependency for ':app@debugUnitTest/compileClasspath': Could not resolve junit:junit:4.12.
Error:Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve com.google.code.findbugs:jsr305:2.0.1.
Dependencies section of my gradle file
dependencies
{
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
}
I do not understand it is my first my project.
My Project gradle is
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
My app gradle is
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 28
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'
}
}
}
android
{
configurations.all
{
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
dependencies
{
implementation 'androidx.appcompat:appcompat:1.0.2'
testImplementation 'junit:junit:4.12'
}
Solution 1:
Add below repository in your build.gradle file,
repositories {
jcenter()
maven {
url 'https://maven.google.com'
}
}
you forgot to add this to your dependencies
androidTestCompile 'com.google.code.findbugs:jsr305:3.0.0'
The problem is caused by espresso library , if you can't remove it add this to your app gradle
android
{
configurations.all
{
resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
}
}
Solution 2:
I was trying to mix AppCompat and Jetpack dependencies, and you cannot do that.
I think I might not have the right repository setup for the Jetpack libraries (why it can't find any Jetpack libraries).
Don't use: implementation 'androidx.appcompat:appcompat:1.0.2' . (this is Jetpack) -- use AppCompat versions of this (besides - Jetpack is NOT consistent with Appcompat versions earlier then 28.x). Bottom line, get rid of anything that says (androidx).
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
}