程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了为什么在添加所需的依赖项后我无法在 android studio 中导入 fire base 库大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决为什么在添加所需的依赖项后我无法在 android studio 中导入 fire base 库?

开发过程中遇到为什么在添加所需的依赖项后我无法在 android studio 中导入 fire base 库的问题如何解决?下面主要结合日常开发的经验,给出你关于为什么在添加所需的依赖项后我无法在 android studio 中导入 fire base 库的解决方法建议,希望对你解决为什么在添加所需的依赖项后我无法在 android studio 中导入 fire base 库有所启发或帮助;

我需要为我的项目添加火库。我按照所有步骤添加了消防商店。构建完成后,Gradle 构建和编译成功。但是当我尝试对其进行编码时,它不允许导入 firestore 库。以下代码是我的构建 gradle

  plugins {
        ID 'com.androID.application'
        ID 'com.Google.gms.Google-services'
    
    }
    
    androID {
        compileSdkVersion 30
        buildToolsversion "29.0.3"
    
        defaultConfig {
            applicationID "com.example.mas"
            minSdkVersion 22
            targetSdkVersion 30
            versionCode 1
            versionname "1.0"
    
            testinstrumentationRunner "androIDx.test.runner.AndroIDJUnitRunner"
        }
    
        buildTypes {
            release {
                MinifyEnabled false
                proguardfiles getDefaultProguardfile('proguard-androID-optimize.txt'),'proguard-rules.pro'
            }
        }
    
        packagingOptions{
            exclude 'meta-inf/liCENSE'
            exclude 'meta-inf/liCENSE-FIREBASE.txt'
            exclude 'meta-inf/NOTICE'
    
        }
        compiLeoptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    dependencIEs {
    
        implementation 'androIDx.appcompat:appcompat:1.3.0'
        implementation 'com.Google.androID.material:material:1.3.0'
        implementation 'androIDx.consTraintlayout:consTraintlayout:2.0.4'
    
        implementation('com.Google.firebase:firebase-installations:17.0.0')
        implementation 'com.firebase:firebase-clIEnt-androID:2.5.2'
        implementation 'com.Google.firebase:firebase-auth:21.0.1'
        testImplementation 'junit:junit:4.13.2'
        androIDTestImplementation 'androIDx.test.ext:junit:1.1.2'
        androIDTestImplementation 'androIDx.test.espresso:espresso-core:3.3.0'
        implementation 'com.Google.firebase:firebase-firestore:23.0.0'
    
    
    }

此代码是项目级别的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:4.1.3"
        classpath 'com.Google.gms:Google-services:4.3.8'




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

allprojects {
    repositorIEs {
        Google()
        jcenter()
    }
}

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

enter image description here

解决方法

你为什么说这个导入是错误的?您的屏幕截图在导入 lib 类时没有显示错误,灰线表示这些导入实际上正在工作,但在此特定类中不需要,因为它们未在代码中使用。在某些方法中放入一些与 firebase 相关的代码或声明变量,灰线变成“彩色”

当你不能导入声明的类时,这些导入行会用红色下划线

,

只需格式化您的代码并检查灰色导入是否被删除,如果它是红色,那么它将是错误的 你没有使用它们

大佬总结

以上是大佬教程为你收集整理的为什么在添加所需的依赖项后我无法在 android studio 中导入 fire base 库全部内容,希望文章能够帮你解决为什么在添加所需的依赖项后我无法在 android studio 中导入 fire base 库所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。