muklah
muklah

Reputation: 865

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx

I'm working on the android app it's too big projects with many class but today I'm trying to create a new class then I just got this code:

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

    public class Main2Activity extends AppCompatActivity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main2);
        }
    }

you can see this line:

import androidx.appcompat.app.AppCompatActivity;

the appcompat is in red color

while the old classes all have this line instead:

import android.support.v7.app.AppCompatActivity;

and the xml code like this:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity">

</androidx.constraintlayout.widget.ConstraintLayout>

you can see the androidx too I tried to delete the class and create it again and tried to create new fragment instead class but all created with x

before some days I update the library from 27 to 28 I don't know if this cause to this problem now I can't sync project I just got these errors:

Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve androidx.constraintlayout:constraintlayout:1.1.2. Open File Show Details

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve androidx.constraintlayout:constraintlayout:1.1.2. Open-File Show Details

and this is the app gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "giga.net.world.GN"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        aaptOptions {
            cruncherEnabled = false
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.constraintlayout:constraintlayout:1.1.2'
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
    implementation 'com.android.support:design:28.0.0-alpha1'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
    implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.jakewharton:butterknife:8.8.1'
    implementation 'com.roughike:bottom-bar:2.0.2'
    implementation 'com.android.support:palette-v7:28.0.0-alpha1'
    implementation 'com.android.support:support-v4:28.0.0-alpha1'
    testImplementation 'junit:junit:4.12'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'com.android.support:support-core-utils:28.0.0-alpha1'
    implementation 'net.alexandroid.utils:mylog:1.1'
    implementation 'com.google.android.exoplayer:exoplayer:r1.5.16'
    implementation project(':playercontrolview')
}

and the project gradle:

buildscript {
    repositories {
        jcenter()
        mavenCentral()
        google()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0-alpha02'
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
        classpath 'com.novoda:bintray-release:0.5.0'
//        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        google()
        maven {
            url "https://maven.google.com"
        }
    }
}

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

and there is also a library project with the main projects and it's gradle is:

apply plugin: 'com.android.library'
apply plugin: 'com.novoda.bintray-release'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.3"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0.1"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:27.1.1'
}

publish {
    userOrg = 'ogapants'
    groupId = 'com.github.ogapants.playercontrolview'
    artifactId = 'playercontrolview'
    publishVersion = '1.0.1'
    desc = 'This library provides easily customizable MediaController for Android'
    website = 'https://github.com/ogapants/PlayerControlView'
    licences = ['Apache-2.0']
}

when I delete the newly created class or fragment and sync the project again the errors are gone and everything return normal what's happened to project?

Upvotes: 3

Views: 2599

Answers (1)

Amir Mohsenian
Amir Mohsenian

Reputation: 94

You have 2 dependencies for constraintLayout. remove one of them. use implementation 'androidx.constraintlayout:constraintlayout:1.1.2' or implementation 'com.android.support.constraint:constraint-layout:1.0.2'

Upvotes: 1

Related Questions