Android Gradle cannot find symbol class Gson

前端 未结 10 1352
温柔的废话
温柔的废话 2020-12-08 19:07

So i added gson-2.2.4.jar to the libs dir (I\'m using android studio). My project couldn\'t find the gson stuff so I added it as a library dependency to my module in the \"P

相关标签:
10条回答
  • 2020-12-08 19:14

    Add this on build.gradle (Module: app)

        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'
        }
    
    0 讨论(0)
  • 2020-12-08 19:14

    I have resolved the issue, by making targetSdkVersion same for all library module with the app-level module.

    0 讨论(0)
  • 2020-12-08 19:24

    Just to update the reference (I was searching for):

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

    You can see the last version on its github repository

    0 讨论(0)
  • 2020-12-08 19:25

    Adding it as a dependency in the Project Structure settings is not enough. That setting is only for the IDE. To actually build, Gradle also needs to be aware of it. You must add the .jar file to your build.gradle file like so...

    dependencies {
        compile files('libs/gson-2.2.4.jar')
    }
    
    0 讨论(0)
  • 2020-12-08 19:27

    Try this GSON . Add this on build.gradle (Module :app)

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

    0 讨论(0)
  • 2020-12-08 19:29

    Just to add a point,

    As of Gradle 1.7, jcenter() is a superset of mavenCentral()...so no need of adding and repositories directive.

    Jars will be downloaded from online central jcenter repository. so adding just the following statement is working.

    dependencies {
    compile 'com.google.code.gson:gson:2.2.+'
    }
    
    0 讨论(0)
提交回复
热议问题