3

I know about this questions:

Failed to resolve: com.android.support:cardview-v7:26.0.0 android

Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]

Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project

And I've read this documentations:

Migrate to Android Plugin for Gradle 3.0.0

Migrating to Android 8.0

So I'm posting this question believing its not a duplicate.

I've installed Android Studio 3.4.1. I didn't have any previous version before and I started a new project.

Every setting in Gradle file have been set by Android Studio itself and I've checked them all.

I have already tried

These are the file contents:

build.gradle (Module:app)

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'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

}

Top level build.gradle

    // 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 {
        google()
        jcenter()
        maven {url 'https://maven.google.com/'}
        maven { url "https://jitpack.io" }
        maven { url 'https://dl.bintray.com/guardian/android' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

gradle-wrapper.properties

 #Mon Jun 10 17:40:01 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

I use google() in repositories as here clearly says:

  // If you're using a version of Gradle lower than 4.1, you must instead use:
     // maven {
     //     url 'https://maven.google.com'
     // }

My gradle version is 4.1 so I don't need above code.

But I still get this error as the others have been asking about:

  • Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.constraintlayout:constraintlayout:1.1.3.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.versionedparcelable:versionedparcelable:1.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.lifecycle:lifecycle-runtime:2.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.legacy:legacy-support-core-ui:1.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.vectordrawable:vectordrawable-animated:1.0.0.

  • ERROR: Unable to resolve dependency for ':app@releaseUnitTest/compileClasspath': Could not resolve androidx.fragment:fragment:1.0.0.

I have also unchecked the offline check box from gradle and using default

I have also unchecked the offline check box from gradle and using default

Why should I get this error when I'm creating a new project in AS 3.4.1 and it has been set all the necessary settings?

user1
  • 99
  • 5

3 Answers3

2

You are trying to mix AppCompat and Jetpack dependencies, and you cannot do that.

I think you 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).

user1
  • 99
  • 5
Booger
  • 18,579
  • 7
  • 55
  • 72
  • what should I do? remove @Booger – user1 Jun 10 '19 at 12:58
  • 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). – Booger Jun 10 '19 at 13:56
1

Replace

implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'

with

implementation 'com.android.support:appcompat-v7:26.0.0'
implementation 'com.android.support:design:26.0.0'

EDIT:- You should invalidate your cache and restart. Follow this steps file -> invalidate caches/Restart Then select invalidate and restart

Prachi Singh
  • 564
  • 3
  • 8
  • I did removed it but still got these errors @PrachiSingh – user1 Jun 10 '19 at 13:05
  • @user1 First uncheck 'Offline Work' in `settings`->`gradle`->`Offline Work`. Then You should invalidate your cache and restart. Follow this steps `file` -> `invalidate caches/Restart` Then select `invalidate and restart` – Prachi Singh Jun 10 '19 at 14:29
  • I have already disabled that see my question I have edited my question @PrachiSingh – user1 Jun 10 '19 at 14:36
1

Define repositories for both Appcompat and jetpack

allprojects {
    repositories {
        google()
        jcenter()        
        maven {url 'https://maven.google.com/'}
        maven { url "https://jitpack.io" }
        maven { url 'https://dl.bintray.com/guardian/android' }
    }
}

After that sync project with gradle.. let me know its working or not.

Hemant Parmar
  • 3,924
  • 7
  • 25
  • 49