Search code examples
androidgradleandroid-recyclerviewandroidxcardview

Could not get unknown property 'androidx' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler


I'm trying to build a location tracker app with the help of below YouTube Video. "https://www.youtube.com/watch?v=17HqLBkuX-E" In build.gradle module I have replaced the CardView and recyclerview lines instead for the lines in the video as they were underlined with red saying 'change according to androix'. So these are the codes I have used for cardview and recyclerview

androidx.cardview.widget.CardView
implementation 'androidx.recyclerview:recyclerview:1.0.0'

And I have changed the layout file with

<androidx.recyclerview.widget.RecyclerView
.
.
.
</androidx.recyclerview.widget.RecyclerView>

I'm getting above titled error when I try to sync it. Here is my layout file

<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
    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=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.recyclerview.widget.RecyclerView>

Here is my build.gradle(Project:)

// 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.5.1'
        classpath 'com.google.gms:google-services:4.2.0'

        // 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://maven.fabric.io/public"
        }

    }
}

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

Here is my buld.gradle(Module:app)

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig {
        applicationId "com.locationtracker2019"
        minSdkVersion 19
        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'])

    androidx.cardview.widget.CardView
    implementation 'androidx.recyclerview:recyclerview:1.0.0'

    implementation "com.google.firebase:firebase-database:10.2.0"
    implementation "com.google.firebase:firebase-auth:10.2.0"
    implementation "com.firebaseui:firebase-ui-auth:1.2.0"
    implementation "com.firebaseui:firebase-ui-database:1.2.0"


    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

Solution

  • implementation 'androidx.recyclerview:recyclerview:1.0.0'
    implementation 'androidx.cardview:cardview:1.0.0'

    You have not added implementation prefix with it. You can use as mentioned above.