Firebase Android SDK 导致 Gradle 错误(没有错误原因)
Firebase Android SDK causing Gradle error (With no error cause)
我正在尝试在我的 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 的情况下工作。
有什么想法吗?
谢谢!
将此内容放入您的 build.gradle(模块:应用程序)
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'
}
来自我的一个项目的完整 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+'
}
感谢大家的帮助,看来是 dex 限制错误。添加 Firebase SDK 一定让我超出了限制,为了解决这个问题,我必须在我的 app:build.gradle
文件的 defaultConfig 部分添加 multiDexEnabled true 以及编译 'com.android.support:multidex:1.0.0'
在依赖项中
您可能需要启用 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'
}
我正在尝试在我的 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 的情况下工作。
有什么想法吗?
谢谢!
将此内容放入您的 build.gradle(模块:应用程序)
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'
}
来自我的一个项目的完整 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+'
}
感谢大家的帮助,看来是 dex 限制错误。添加 Firebase SDK 一定让我超出了限制,为了解决这个问题,我必须在我的 app:build.gradle
文件的 defaultConfig 部分添加 multiDexEnabled true 以及编译 'com.android.support:multidex:1.0.0'
在依赖项中
您可能需要启用 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'
}