You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio 3.1添加本地Gson依赖失败,求助解决方案

Hey there, let's get that local Gson dependency working in your Android Studio 3.1 project. I’ve tackled similar setup issues before, so here’s a step-by-step fix tailored to your setup:

1. Fix your settings.gradle first

Since you’ve extracted Gson into TestGsonExtras\subProject\gson, you need to tell Gradle to recognize this sub-project. Update your settings.gradle file to include the Gson module:

include ':app', ':subProject:gson'

This tells Gradle that there’s a valid Gradle project in that subdirectory (make sure the extracted Gson folder has its own build.gradle file—this comes with the official Gson source download).

Next, open your app module’s build.gradle (the one inside the app folder) and add the local project dependency in the dependencies block:

dependencies {
    // Keep your existing dependencies here (like appcompat, etc.)
    implementation project(':subProject:gson')
}
3. Troubleshoot common sync issues

If you still run into problems, check these quick fixes:

  • Missing build.gradle in Gson folder: For some reason, if the extracted Gson folder doesn’t have its own build.gradle, create one inside the gson directory with this basic Java library config:
    apply plugin: 'java-library'
    
    repositories {
        jcenter()
    }
    
    dependencies {
        implementation 'com.google.code.findbugs:jsr305:3.0.2'
    }
    
    sourceCompatibility = JavaVersion.VERSION_1_7
    targetCompatibility = JavaVersion.VERSION_1_7
    
  • Sync Gradle manually: Click the "Sync Project with Gradle Files" button (the elephant icon) in the top-right corner of Android Studio and wait for the process to finish. Check the Build tab for specific error messages if sync fails.
  • Alternative: Use a local JAR instead: If dealing with sub-projects feels cumbersome, you can compile the Gson source into a JAR (or use a pre-built one) and drop it into your app/libs folder. Then update your app’s build.gradle dependencies:
    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        // Your other dependencies
    }
    

Once you’ve made these changes, sync your project again, and you should be able to use Gson and its Extra classes without issues.

内容的提问来源于stack exchange,提问作者fredimx40

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:49:33