无法获得类型org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler类型的对象的未知属性'androidx'

问题描述 投票:2回答:2

我正在YouTube视频下面的帮助下构建位置跟踪器应用。“ https://www.youtube.com/watch?v=17HqLBkuX-E”在build.gradle模块中,我替换了CardView和recyclerview行,而不是视频中的行,因为它们用红色下划线表示“根据androix进行更改”。这些是我用于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'
}
android gradle android-recyclerview androidx cardview
2个回答
0
投票

从应用程序gradle文件中删除行androidx.cardview.widget.CardView(在依赖关系中)


0
投票

实现'androidx.recyclerview:recyclerview:1.0.0'实现'androidx.cardview:cardview:1.0.0'

您尚未添加实现前缀。您可以如上所述使用。

© www.soinside.com 2019 - 2024. All rights reserved.