【问题标题】:Firebase Android SDK causing Gradle error (With no error cause)Firebase Android SDK 导致 Gradle 错误(没有错误原因)
【发布时间】:2015-08-01 06:42:17
【问题描述】:

我正在尝试在我的 Android Studio 项目中使用 Firebase,但它给了我一个空的 Gradle 错误。

我尝试过将 Firebase SDK 与 Gradle 一起使用,并将 jar 放在我的 libs 文件夹中,并且都给出了相同的空白 Gradle 错误。

我在这里关注了 Android 快速入门:https://www.firebase.com/docs/android/quickstart.html

我放入了 packagingOptions,但没有用。如果没有实际的错误消息,很难调试!我还没有为 Firebase 编写任何代码,我只是想让它与 Firebase Android SDK 一起运行而不会出现 Gradle 错误

我的项目在不包含 Firebase 时有效。

有什么想法吗?

谢谢!

【问题讨论】:

  • 嘿尼克。我每天至少遵循一次相同的步骤来获得一个正常工作的 Android 应用程序。因此,您执行的方式与我执行它们的方式(或我们从什么开始)很可能存在差异。我在下面发布了一个完整的 build.gradle。但除此之外,只有您提供更多信息,我才能提供帮助。您使用什么版本的 Android Studio?逐步描述你的工作。向您展示 build.gradle。显示你得到的错误。 Android Studio 的 Gradle 控制台中有什么东西吗?等
  • 嗨弗兰克。我正在使用 Android Studio 1.2 我所做的是将 Firebase 编译依赖项和 PackagingOptions 放在我项目的 app:build.gradle 文件中,然后同步 gradle 并且没有错误。当我构建或尝试运行应用程序时,我收到一个 Gradle 错误,原因是空白。我在下面评论了我的 app:build.gradle 文件的链接。对我来说看起来不错,我不知道出了什么问题。

标签: android android-studio firebase


【解决方案1】:

在你的 build.gradle (Module:app) 中有这个内容

    android {

    //so default auto generated blocks will be here ...

        packagingOptions {
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE-FIREBASE.txt'
            exclude 'META-INF/NOTICE'
        }

    } // end of android node 

     dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile 'com.android.support:appcompat-v7:22.0.0'
            compile 'com.android.support:support-v4:22.0.0'
            compile 'com.firebase:firebase-client-android:2.3.1'
        }

【讨论】:

    【解决方案2】:

    感谢您的帮助,看起来这是一个 dex 限制错误。添加 Firebase SDK 一定让我超出了限制,要解决这个问题,我必须在我的 app:build.gradle 文件的 defaultConfig 部分添加 multiDexEnabled true 并在依赖项中编译 'com.android.support:multidex:1.0.0' p>

    【讨论】:

      【解决方案3】:

      您可能需要启用 multidex。

      android {
          compileSdkVersion 21
          buildToolsVersion "21.1.0"
      
          defaultConfig {
              ...
              minSdkVersion 14
              targetSdkVersion 21
              ...
      
              // Enabling multidex support.
              multiDexEnabled true
          }
          ...
      }
      
      dependencies {
        compile 'com.android.support:multidex:1.0.0'
      }
      

      【讨论】:

        【解决方案4】:

        我的一个项目中完整的app/build.gradle

        apply plugin: 'com.android.application'
        
        android {
            compileSdkVersion 22
            buildToolsVersion "22.0.1"
        
            defaultConfig {
                applicationId "com.firebaseuser.nanochat"
                minSdkVersion 21
                targetSdkVersion 22
                versionCode 1
                versionName "1.0"
            }
            buildTypes {
                release {
                    minifyEnabled false
                    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
                }
            }
            packagingOptions {
                exclude 'META-INF/LICENSE'
                exclude 'META-INF/LICENSE-FIREBASE.txt'
                exclude 'META-INF/NOTICE'
            }
        }
        
        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            compile 'com.android.support:appcompat-v7:22.1.1'
            compile 'com.firebase:firebase-client-android:2.3.1+'
        }
        

        【讨论】:

        • 对不起,这里不让我贴代码,它说文本太长了 990 个字符:/
        • 您的问题下方有一个 edit 链接,以便您使用其他信息对其进行更新。
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-01-02
        • 2012-06-19
        • 1970-01-01
        • 2018-01-08
        • 2015-11-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多