android - 无法获取 org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler 类型的对象的未知属性 'androidx'

标签 android gradle android-recyclerview androidx cardview

我正在尝试在下面的 YouTube 视频的帮助下构建一个位置跟踪器应用。 “https://www.youtube.com/watch?v=17HqLBkuX-E” 在 build.gradle 模块中,我替换了 CardView 和 recyclerview 行,而不是视频中的行,因为它们用红色下划线表示“根据 android 进行更改”。这些是我用于cardview和recyclerview的代码

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

我已经更改了布局文件

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

当我尝试同步它时,出现上述标题错误。 这是我的布局文件

<?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>

这是我的 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
}

这是我的 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'
}

最佳答案

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

您尚未添加实现前缀。 您可以按照上面提到的方式使用。

关于android - 无法获取 org.gradle.api.internal.artifacts.dsl.dependency.DefaultDependencyHandler 类型的对象的未知属性 'androidx',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59475842/

相关文章:

android - 在 ViewPager 中应用时在 Recycler 中滑动

android - 如何清除 "in-app billing service"缓存

java - 如何在 View 中添加字符串属性以供 View 服务器转储

android - 在 Android Studio 中导入 Gradle Android 项目时出错

intellij-idea - 在 Gradle 中设置 IntelliJ 编译器参数

gradle - 从Gradle任务跟踪(和删除)输出文件

android - 在 Kotlin 中为 recyclerView 的 child 的 child 设置监听器

android - 如何自定义回收站 View 的网格布局管理器?

android - sdkmanager vs "android update sdk"安装依赖项

android - 调用 popupwindow 的 showAtLocation 会使应用程序崩溃