【问题标题】:Android app does not connect to FirebaseAndroid 应用无法连接到 Firebase
【发布时间】:2016-11-13 18:10:31
【问题描述】:

我正在使用 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'

项目等级 应用插件:'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 工具
还是不行。

【问题讨论】:

    标签: android firebase


    【解决方案1】:

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

    原来我有一个警告,我必须修复它才能让它工作。

    “按需配置是一项孵化功能。 警告:配置“编译”已过时,已替换为“实施”和“API”。 它将在 2018 年底被删除。更多信息请参阅:http://d.android.com/r/tools/update-dependency-configurations.html"

    我只需要用 'api' 替换我的 'compile' 就可以了。如果您有任何警告,我建议您考虑修复警告,即使您的构建成功。

    【讨论】:

    • 谢谢!就我而言,我不得不使用“实现”而不是“编译”。
    • 这行对我有用 //jackOptions {enabled true}
    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

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

      【讨论】:

      • 我认为这些警告与 firebase 无关,再次感谢
      • @AJH 什么是gzips 我也有同样的问题,无法解决?
      • @Nicholas gzip 是什么?
      • @FelipeCastilhos 带有 .gz 扩展名的文件。
      • 对于仍然面临问题的任何人,我从项目文件中删除了 .gradle 和 .idea,然后清理、构建并运行应用程序。
      【解决方案4】:

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

      dataBinding {
          enabled = true
      }
      

      而不是

      buildFeatures{
              dataBinding = true
          }
      

      【讨论】:

        【解决方案5】:

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

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            【解决方案7】:

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

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

            【讨论】:

              【解决方案8】:

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

              【讨论】:

                【解决方案9】:

                第一种方法:- 只需 REMOVE 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(项目)

                【讨论】:

                  【解决方案10】:

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

                  dexOptions
                              {
                                  //incremental false
                              }
                  

                  【讨论】:

                    【解决方案11】:

                    在我的例子中,它显示了这个警告:

                    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 服务可能会在未来的版本中解决此问题。

                    【讨论】:

                    • 感谢 Nurseyit - 我也收到了同样的警告,并在 4.3.0 的 Project build.gradle 文件中更改了这一点:classpath 'com.google.gms:google-services:4.2.0'跨度>
                    【解决方案12】:

                    如果您正在使用请注意:

                    android.enableR8 = true

                    暂时将其删除。那是我的错误。

                    【讨论】:

                      【解决方案13】:

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

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

                      去掉这一行 app build.gradle: 应用插件:'io.fabric'

                      【讨论】:

                        【解决方案14】:

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

                        android.databinding.enableV2=true
                        

                        【讨论】:

                        • 这条线在哪里?我有 viewBinding {enabled = true} 删除这一行并没有解决这个问题
                        【解决方案15】:

                        在 build.gradle (Module.app) 如果您使用视图绑定,请暂时评论它,然后同步!

                        /*
                        viewBinding {
                           enabled = true
                        }
                        */
                        

                        然后连接到 Firebase。我使用的是 AS 4.0。

                        【讨论】:

                          【解决方案16】:

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

                          【讨论】:

                            【解决方案17】:

                            对我来说,解决方案是将所有“compile 'com.google....”替换为“implementation 'com.google...”

                            【讨论】:

                              【解决方案18】:

                              在 Gradle 文件中:

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

                              这对我有帮助。

                              【讨论】:

                              • 欢迎来到 StackOverflow。这个答案太小而且不清楚。你是说插件应该从文件中删除吗?问候。
                              • @Elletlar 你必须添加这一行。但就我而言,它并没有解决问题
                              【解决方案19】:

                              嗯,你需要从 build.gradle 中删除错误和警告。

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

                              【讨论】:

                                【解决方案20】:

                                在我的清单中删除节点

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

                                【讨论】:

                                  【解决方案21】:

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

                                  android.databinding.enableV2=true
                                  

                                  app gradle 文件中已经启用了数据绑定

                                  【讨论】:

                                  • 这条线在哪里?我有 viewBinding {enabled = true} 删除这一行并没有解决这个问题
                                  • 你必须在 gradle.properties 文件中添加这一行
                                  【解决方案22】:

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

                                  【讨论】:

                                    【解决方案23】:

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

                                    【讨论】:

                                    • 这应该是一条评论
                                    • 不,@Istiak。虽然很短,但这是一个有效的答案。
                                    【解决方案24】:

                                    为 Android Studio 北极狐中新创建的 android 项目解决此问题 更改所有测试依赖项的“testImplementation”、“androidTestImplementation”。

                                    【讨论】:

                                      【解决方案25】:

                                      无法解析 Android 应用程序模块 Gradle 配置 那么你的成绩肯定有问题, 就我而言,我导入了一个没有使用 android X 的旧项目,所以我迁移到 android X,在此过程中,您还必须在 gradle.properties 中添加这些代码行文件,

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

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

                                      【讨论】:

                                        【解决方案26】:

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

                                        【讨论】:

                                          猜你喜欢
                                          • 2013-07-08
                                          • 1970-01-01
                                          • 1970-01-01
                                          • 2021-06-18
                                          • 2020-08-26
                                          • 1970-01-01
                                          • 1970-01-01
                                          • 2020-06-24
                                          • 1970-01-01
                                          相关资源
                                          最近更新 更多