Android Gradle cannot find symbol class Gson

前端 未结 10 1353
温柔的废话
温柔的废话 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:32

    In my case, I just added this line:

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

    on my app build.gradle file.

    By now 2.7 is last current available version according to: https://mvnrepository.com/artifact/com.google.code.gson/gson

    Please check this repository to be sure you are using last available version.

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

    I've faced with same issue.

    To solve it be sure that you specify maven central for android plugin

    repositories {
        mavenCentral()
    }
    

    And it should be added twice if you are defining 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') 
    }
    
    0 讨论(0)
  • 2020-12-08 19:35

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

    dependencies {
        compile fileTree(dir: 'libs', include: '*.jar')
    }
    
    0 讨论(0)
  • 2020-12-08 19:39

    I faced the same issue. I just added a single line as shown below in my build.gradle dependencies (without adding any jar in 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 above, I found few more things which are required for this to work.

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

      <uses-sdk
          android:minSdkVersion="10"
          android:targetSdkVersion="18" />
      
    2. Make sure you have targetSdkVersion 18 in build.gradle file.

      defaultConfig {
          minSdkVersion 10
          targetSdkVersion 18
      }
      
    3. Make sure you are connected to internet; so that jars will be downloaded from online central maven repository.

    0 讨论(0)
提交回复
热议问题