Android Gradle cannot find Gson character class

So, I added gson-2.2.4.jar to the libs directory (I use Android studio). My project could not find the gson stuff, so I added it as a library dependency to my module in Project Structure. When I try to start a project, the assembly does not work with the following errors:

Error:(12, 23) Gradle: package com.google.gson does not exist Error:(37, 3) Gradle: cannot find symbol class Gson Error:(37, 19) Gradle: cannot find symbol class Gson 

Why can't I make this work? I read elsewhere that gradle should process everything automatically if it fits in the lib directory.

+50
android android-studio android-gradle gradle
Jul 28 '13 at 22:43
source share
10 answers

Adding it as a dependency in the project structure settings is not enough. This parameter is for the IDE only. To really build, Gradle also needs to know about it. You should add the .jar file to your build.gradle file, for example ...

 dependencies { compile files('libs/gson-2.2.4.jar') } 
+41
Jul 28 '13 at 22:55
source share
β€” -

I ran into the same problem. I just added one line, as shown below in my build.gradle dependencies (without adding a jar in the project structure), and it worked for me.

 dependencies { compile 'com.google.code.gson:gson:2.2.+' compile 'com.android.support:support-v4:13.0.+' compile 'com.android.support:appcompat-v7:18.0.+' } 

Along with the above, I found a few things that are necessary for this to work.

  • Make sure you have android:targetSdkVersion="18" in the AndroidManifest.xml file.

     <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" /> 
  • Make sure that build.gradle has targetSdkVersion 18 .

     defaultConfig { minSdkVersion 10 targetSdkVersion 18 } 
  • Make sure you are connected to the Internet; so banks will be downloaded from the maven online centralized repository.

+94
Aug 10 '13 at
source share

To add a point,

As with Gradle 1.7, jcenter () is a superset of mavenCentral () ... so there is no need for the add and repositories directive.

Mailboxes will be downloaded from the jcenter online centralized repository. therefore, only the following statement is added.

 dependencies { compile 'com.google.code.gson:gson:2.2.+' } 
+19
Jul 06 '15 at 2:37
source share

I ran into the same problem.

To solve this problem, make sure you specify maven central for the Android plugin.

 repositories { mavenCentral() } 

And it should be added twice if you define a build script

 buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.5+' } } repositories { mavenCentral() } apply plugin: 'android' dependencies { compile 'com.google.code.gson:gson:2.2.4' compile 'com.android.support:support-v4:13.0.0' compile project(':libraries:volley') } 
+14
Sep 03 '13 at 16:02
source share

In my case, I just added this line:

 dependencies { compile 'com.google.code.gson:gson:2.7' } 

in my application build.gradle file.

Currently 2.7 is the latest current version available according to: https://mvnrepository.com/artifact/com.google.code.gson/gson

Please check this repository to make sure you are using the latest available version.

+6
Oct 03 '16 at 11:02
source share

Try this GSON. Add this to build.gradle (Module: application)

implementation 'com.google.code.gson:gson:2.2.4'

+3
Mar 27 '18 at 12:26
source share

Add this to build.gradle (Module: application)

  dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support:design:27.1.1' implementation 'com.google.code.gson:gson:2.8.0' } 
+3
May 01 '18 at 4:28
source share

Create a libs folder name and add or edit build.gradle (works for any jar lib in the folder)

 dependencies { compile fileTree(dir: 'libs', include: '*.jar') } 
+1
Dec 09 '13 at 17:56
source share

I solved the problem by making targetSdkVersion the same for all library modules with an application-level module.

0
Apr 09 '18 at 5:45
source share

Just to update the link (I searched):

 implementation 'com.google.code.gson:gson:2.8.5' 

You can see the latest version on your github project:

enter link description here

0
Apr 10 '19 at 12:08 on
source share



All Articles