我正在尝试在我的项目中使用 firebase sdk,但无法同步 gradle。我已将 jdk 从 1.7 更新到 1.8,并将 google 存储库、android sdk 和工具更新到最新版本,但甚至我收到错误消息,因为无法加载类“com.google.gson.JsonObject”。
项目 Gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
classpath 'com.google.gms:google-services:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
} allprojects {
repositories {
jcenter()
}
}
模块等级:
apply plugin: 'com.android.application'
安卓{ 编译SDK版本23 buildTools版本“23.0.1”
defaultConfig {
applicationId "nidhinkumar.firebaseexample"
minSdkVersion 15
targetSdkVersion 23
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:23.1.1'
compile 'com.firebase:firebase-client-android:2.4.0'
compile 'com.google.firebase:firebase-storage:9.2.1'
compile 'pub.devrel:easypermissions:0.1.9'
compile 'com.google.firebase:firebase-core:9.2.1'
compile 'com.google.firebase:firebase-auth:9.2.1'
}
apply plugin: 'com.google.gms.google-services'
错误:
Error:Unable to load class 'com.google.gson.JsonObject'.
Possible causes for this unexpected error include:<ul><li>Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href="syncProject">Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href="stopGradleDaemons">Stop Gradle build processes (requires restart)</a></li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
最佳答案
您发布的错误消息中提到了解决方案:
Possible causes for this unexpected error include:
In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.
- Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.) Re-download dependencies and sync project (requires network)
- The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem. Stop Gradle build processes (requires restart)
重新启动 IDE 后,还要执行文件 -> 使缓存无效/重新启动
,因为它表示您的缓存已损坏。
评论中对话的更新
应满足先决条件。正如您提到的,您使用的是 AS 1.0.1,它低于 firebase 的要求 - AS 1.5 及更高版本。升级您的 Android Studio,您应该就可以了。
关于java - 无法在 Android 中同步 Firebase 的 gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38655021/