繁体   English   中英

Android 应用程序未连接到 Firebase

[英]Android app does not connect to Firebase

我正在使用 Firebase GMS 服务开发 android 应用程序。
我尝试按照他们的教程进行操作,按照他们的说法制作项目,下载了 json 文件。

但是当我尝试将我的应用程序连接到 Firebase 时。 他们向我展示了错误

无法解析 Android 应用模块的 Gradle 配置。 解决 gardle 构建问题和/或重新同步。

在此处输入图像描述

但是我认为我的成绩单很完美(我会写在页面底部)

在此处输入图像描述

这是我的成绩构建控制台

Executing tasks: [:app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources]

Configuration on demand is an incubating feature.
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for debug as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
WARNING: WARNING: Dependency org.json:json:20090211 is ignored for release as it may be conflicting with the internal version provided by Android.
         In case of problem, please repackage it with jarjar to change the class packages
Incremental java compilation is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2400Library UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72400Library UP-TO-DATE
:app:prepareComAndroidSupportMediarouterV72400Library UP-TO-DATE
:app:prepareComAndroidSupportPaletteV72400Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42400Library UP-TO-DATE
:app:prepareComAndroidSupportSupportVectorDrawable2400Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServices980Library
:app:prepareComGoogleAndroidGmsPlayServicesAds980Library
:app:prepareComGoogleAndroidGmsPlayServicesAdsLite980Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics980Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl980Library
:app:prepareComGoogleAndroidGmsPlayServicesAppindexing980Library
:app:prepareComGoogleAndroidGmsPlayServicesAppinvite980Library
:app:prepareComGoogleAndroidGmsPlayServicesAuth980Library
:app:prepareComGoogleAndroidGmsPlayServicesAuthBase980Library
:app:prepareComGoogleAndroidGmsPlayServicesAwareness980Library
:app:prepareComGoogleAndroidGmsPlayServicesBase980Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement980Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesCast980Library
:app:prepareComGoogleAndroidGmsPlayServicesCastFramework980Library
:app:prepareComGoogleAndroidGmsPlayServicesClearcut980Library
:app:prepareComGoogleAndroidGmsPlayServicesDrive980Library
:app:prepareComGoogleAndroidGmsPlayServicesFitness980Library
:app:prepareComGoogleAndroidGmsPlayServicesGames980Library
:app:prepareComGoogleAndroidGmsPlayServicesGass980Library
:app:prepareComGoogleAndroidGmsPlayServicesGcm980Library
:app:prepareComGoogleAndroidGmsPlayServicesIdentity980Library
:app:prepareComGoogleAndroidGmsPlayServicesIid980Library
:app:prepareComGoogleAndroidGmsPlayServicesInstantapps980Library
:app:prepareComGoogleAndroidGmsPlayServicesLocation980Library
:app:prepareComGoogleAndroidGmsPlayServicesMaps980Library
:app:prepareComGoogleAndroidGmsPlayServicesNearby980Library
:app:prepareComGoogleAndroidGmsPlayServicesPanorama980Library
:app:prepareComGoogleAndroidGmsPlayServicesPlaces980Library
:app:prepareComGoogleAndroidGmsPlayServicesPlus980Library
:app:prepareComGoogleAndroidGmsPlayServicesSafetynet980Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanager980Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerApi980Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks980Library UP-TO-DATE
:app:prepareComGoogleAndroidGmsPlayServicesVision980Library
:app:prepareComGoogleAndroidGmsPlayServicesWallet980Library
:app:prepareComGoogleAndroidGmsPlayServicesWearable980Library
:app:prepareComGoogleFirebaseFirebaseAnalytics980Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseAnalyticsImpl980Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseAuth980Library
:app:prepareComGoogleFirebaseFirebaseAuthCommon980Library
:app:prepareComGoogleFirebaseFirebaseAuthModule980Library
:app:prepareComGoogleFirebaseFirebaseCommon980Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseConfig980Library
:app:prepareComGoogleFirebaseFirebaseCore980Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseCrash980Library
:app:prepareComGoogleFirebaseFirebaseDatabase980Library
:app:prepareComGoogleFirebaseFirebaseDatabaseConnection980Library
:app:prepareComGoogleFirebaseFirebaseIid980Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseMessaging980Library UP-TO-DATE
:app:prepareComGoogleFirebaseFirebaseStorage980Library
:app:prepareComGoogleFirebaseFirebaseStorageCommon980Library
:app:prepareComTsengvnTypekit100Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
Parsing json file: C:\Users\AJH322\AndroidStudioProjects\hanyang\app\src\debug\google-services.json
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl UP-TO-DATE
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript UP-TO-DATE
:app:generateDebugAndroidTestBuildConfig UP-TO-DATE
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources UP-TO-DATE
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources

BUILD SUCCESSFUL

Total time: 3 mins 14.678 secs

这是我的 gradle 脚本(模块)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.example.ajh322.hanyang"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.tsengvn:Typekit:1.0.0'
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
    compile 'com.github.nkzawa:socket.io-client:0.3.0'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

项目 gradle 应用插件:'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "24.0.0"
    defaultConfig {
        applicationId "com.example.ajh322.hanyang"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.android.gms:play-services:9.8.0'
    compile 'com.tsengvn:Typekit:1.0.0'
    compile 'com.squareup.okhttp3:okhttp:3.4.2'
    compile 'com.github.nkzawa:socket.io-client:0.3.0'
    testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'

有人知道如何使用我的应用程序连接到 Firebase 吗?
请拯救我的生命...谢谢



+ 正如人们所说,我更新了我的 sdk 工具
仍然无法正常工作。
在此处输入图像描述

我有完全相同的问题。 我构建成功,但在通过助手点击“连接到 Firebase”按钮时收到了相同的消息。

结果是我有一个警告,我必须修复它才能让它工作。

“按需配置是一个孵化功能。警告:配置'编译'已过时,已被'实现'和'api'取代。它将在2018年底删除。更多信息参见: http://d .android.com/r/tools/update-dependency-configurations.html "

我只需要用'api'替换我的'compile',然后它就可以工作了。 即使您的构建成功,我也建议您查看修复警告,如果您有任何警告。

我尝试了很多方法,但最简单的方法是将com.google.gms:google-services从 3.1.1 更新为 3.2.0

我怀疑您项目中的 gzip 可能是罪魁祸首。 在您的项目文件夹中搜索并删除它们,让 gradle 为您重新同步它。

可能的替代解决方案: https : //github.com/socketio/engine.io-client-java/issues/13 https://github.com/ACRA/acra/issues/159

确保您的 app/build.gradle 没有过时的依赖项和声明。 我的问题是使用

dataBinding {
    enabled = true
}

而不是

buildFeatures{
        dataBinding = true
    }

转到应用程序 build.gradle 文件。 将“编译”替换为“api”。 然后,同步您的项目。 警告应该消失。 这对我来说很好。

好吧,您需要解决所有 gradle 构建问题。 转到 gradle 控制台(通常位于 IDE 的右下角)并检查它们的错误/警告。 一旦您的构建成功且没有错误,与 firebase 的连接应该可以工作。

我最近更新到 Android studio 4.0 并遇到了这个错误。 我仍然使用过时的方式来添加数据绑定。 将其更改为使用数据绑定的更新方式解决了我的问题。 下面是代码:

buildFeatures{
        dataBinding = true
        // for view binding :
        // viewBinding = true
    }

在 build.gradle 文件中,将 'compile' 替换为 'implementation' 并同步项目。

我在 build.gradle 文件中有一些其他错误。 注释掉以下行后,它开始工作:

dexOptions
            {
                //incremental false
            }

就我而言,它显示了此警告:

API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()

因此,我无法连接到 Firebase。

由 gms 服务 4.3.0 引起。 所以我不得不将其更改为:

com.google.gms:google-services:4.2.0

我通过运行发现了这一点:

gradlew 同步 -Pandroid.debug.obsoleteApi=true

在终端。 在 Android Studio 中转到查看 -> 工具窗口 -> 终端。 Gms 服务可能会在未来的版本中解决这个问题。

第一种方法:- 只需删除jcenter() 因为此存储库即将关闭,因此这将在与 firebase 连接时产生问题

repositories {
        google()
        mavenCentral()
//        jcenter() // Warning: this repository is going to shut down soon
    }

第二种方法:- 临时删除

id 'androidx.navigation.safeargs.kotlin' 

在 build.gradle(module) 和

classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.3.5" 

来自 build.gradle(项目)

如果您正在使用,请注意:

android.enableR8 = 真

暂时删除它。 那是我的错误。

如果您正在使用 gradle.properties 中的databinding ,请删除此行

android.databinding.enableV2=true

在build.gradle(Module.app)中,如果使用视图绑定,暂时注释掉,然后同步!

/*
viewBinding {
   enabled = true
}
*/

然后连接到firebase。 我使用 AS 4.0。

我有同样的问题! 当我使用 Android Studio Firebase 助手并单击“连接到 Firebase”按钮时,我遇到了同样的问题。 解决方法很简单:忘记助手(很明显,它有一些bug),只需按照说明手动将Firebase项目集成到您的Android Studio项目中(在Firebase控制台中创建项目,下载json文件并将其放入'app' 文件夹内等)不要忘记确保所有 Firebase 依赖项的版本相同(例如 11.8.0)。 它对我有用。

对我来说,解决方案是,将所有“编译'com.google ....”替换为“实现'com.google ...”

在 Gradle 文件中:

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

这对我有帮助。

好吧,您需要从 build.gradle 中删除错误和警告。

可以在以下位置轻松找到:构建选项卡(底部)-> 同步选项卡-> 在这里您可以找到问题

任何有这个问题的人,我都是这样解决的:Android Studio - 3.4.2

修复“构建”窗口中的所有警告。 将编译更改为“implementation”和“testImplementation”、“androidTestImplementation”等

删除这一行 app build.gradle: apply plugin: 'io.fabric'

就我而言,在我的清单中删除节点

 <application
        android:name=".controller.AppController"
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:usesCleartextTraffic="true"
        android:roundIcon="@mipmap/ic_launcher"
        android:supportsRtl="true"
        tools:node="replace"
        android:theme="@style/AppTheme">

删除这一行

 tools:node="replace"

并用这个替换

tools:replace="allowBackup"

如果您正在使用 gradle.properties 中的数据绑定,请删除此行

android.databinding.enableV2=true

已经在应用程序 gradle 文件中启用了数据绑定

我有同样的问题。 我通过将 sha-1 代码更新到 firebase 控制台并从 firebase 重新导入 google-json 文件来解决它。 我发现的主要问题是在更新 android studio 后,sha-1 或 md5 代码发生了变化。

在 build.gradle 文件中,将 'compile' 替换为 'implementation' 并同步项目。 以后谢谢我。

要在 Android Studio 北极狐中为新创建的 android 项目修复此问题,请更改所有测试依赖项的“testImplementation”、“androidTestImplementation”。

Couldn't parse the android application module Gradle config then there must be some problem in your grade build, In my case, I imported an old project which wasn't using android X, so I migrate to android X, and in the process,您还必须在gradle.properties文件中添加这些代码行,

android.enableJetifier=true
android.useAndroidX=true
  • 我已更改为 android x,但未将这些设置为 true,为什么我收到错误,您可以从此处了解有关迁移到 android X 的更多信息,

https://developer.android.com/jetpack/androidx/migrate

我通过删除解决了这个问题:

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

我希望这有效!

我遇到了同样的问题,但至少我设法解决了它和最好的方法:

请更改应用模块的 Gradle 配置:

在 Android 中:compileSdk 31 ---更改您的 SDK 版本,就像在我的项目中一样,我使用 31

在 compileOptions{} 之后添加:

compileSdkVersion 31 ---将此代码添加到您的 buildToolsVersion '30.0.3' ---将此代码添加到您的

在依赖项中添加: implementation 'androidx.appcompat:appcompat:1.4.2' ---更改您的依赖项

现在同步您的项目 Firebase 控制台将打开……

视频链接: https://youtu.be/trQtxMbMLFk

许多人已经提供了解决方案。 但有趣的是,问题的位置在我的情况下是不同的。 settings.gradle文件中注释掉jcenter()为我解决了这个问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM