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

Android中使用OKHttp发起POST请求时无法解析FormBody.Builder符号

Fixing "Cannot resolve symbol 'Builder'" for FormBody in OKHttp (Android)

Hey, I’ve run into this exact issue before when working with OKHttp on Android. Let’s walk through the most likely fixes to get that FormBody.Builder error sorted out:

1. Double-check your OKHttp dependency setup

First, make sure you’ve added the correct OKHttp dependency to your module-level build.gradle file (not the project-level one). Use a recent stable version—here’s an example:

dependencies {
    // Replace with the latest stable OKHttp version
    implementation 'com.squareup.okhttp3:okhttp:4.12.0'
}

After updating the dependency, click the Sync Now button in the top-right corner of Android Studio to let Gradle pull in the library. Sometimes a missed sync is the root cause!

2. Verify your import statement

It’s easy to accidentally import the wrong class or forget to import it entirely. Make sure your code includes this exact import:

import okhttp3.FormBody;

If you don’t see this line, Android Studio should usually show a lightbulb icon to auto-import it—click that, or manually add the line at the top of your file.

3. Clean and rebuild your project

Android Studio’s cache can sometimes cause weird unresolved symbol issues. Try these steps:

  • Go to Build > Clean Project to wipe old build files
  • Then go to Build > Rebuild Project to build everything from scratch
  • If that still doesn’t work, try invalidating caches: File > Invalidate Caches... > Invalidate and Restart

4. Check for obfuscation conflicts (if using ProGuard/R8)

If your project uses code obfuscation, make sure OKHttp’s classes aren’t being stripped away. Add these rules to your proguard-rules.pro file:

-dontwarn okhttp3.**
-keep class okhttp3.** { *; }

This ensures FormBody and other OKHttp components stay intact during the build process.

5. Ensure compatibility between Android Studio and OKHttp

Outdated versions of Android Studio might have trouble with newer OKHttp releases. If you’re running an ancient AS version, consider updating to the latest stable build—this often resolves subtle compatibility bugs.


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 07:10:41