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

2020-07-18 07:06发布

问题:

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.