Unable to load class 'com.google.gson.JsonObject'

假装没事ソ 提交于 2019-12-06 04:14:47

问题


I am trying to include firebase SDK in my Android Studio Project. But it giving me an error. I am using latest JDK version (1.7.0_71) and it is asking for upgrading higher version to (1.7.0_67).

I need help for basic firebase setup SDK on android. I tried to setup it by the reference of following link: https://firebase.google.com/docs/android/setup#add_the_sdk.

I am getting following error: Please check attached screenshot


回答1:


I had the same problem trying to GCM to an old android project. The solution for me was to also add

classpath 'com.android.tools.build:gradle:2.1.2'

to the top-level build file dependencies, just before classpath 'com.google.gms:google-services:3.0.0'. For the old android project, this dependency only existed in the module-level build file.




回答2:


Make sure you are using Android Studio 1.5 or above. Just saw a guy who had the same issue and he was using android studio 1.0.1

Updating the Android Studio will fix it for you. Also check other pre-requisites.

Prerequisites from official documentation are as follows:

  • A device running Android 2.3 (Gingerbread) or newer, and Google Play services 9.2.1 or newer
  • The Google Play services SDK from the Android SDK Manager
  • Android Studio 1.5 or higher
  • An Android Studio project and its package name



回答3:


First of all complete all the steps mentioned in a link you had followed for Firebase

And note that it requires active internet connection so please check internet connection and add both project and app level dependencies as per suggested in link of Firebase you had used in question

Also it is best to use JDK version 1.8 and above because oracle officialy ended support for those versions. If you are working with Firebase Api which is quiet new so i would highly recommend as it is also recommended by most professionals including developers at Google.Or if you want to go with JDK 1.7 then update it to latest Jdk 7u80 or 7u79 at least because it has least issues comparing to older versions.

The best solution is use JDK version 1.8 and follow all the steps in link https://firebase.google.com/docs/android/setup#add_the_sdk




回答4:


Ensure that you have the google-services.json file, with the client id: <effective package name>, in the app directory. This you download from the Firebase console when you add an app.



来源:https://stackoverflow.com/questions/38053925/unable-to-load-class-com-google-gson-jsonobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!