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

求助:Flutter应用执行flutter pub get后在VS Code中运行报错java.rmi.ConnectException: Connection refused to host: 127.0.0.1

Fixing java.rmi.ConnectException: Connection refused after flutter pub get in VS Code

Hey there, let's tackle this java.rmi.ConnectException you're hitting after running flutter pub get. This error usually pops up when the Gradle daemon can't establish a connection to its RMI server, which often ties to local network/port issues or Gradle cache corruption after updating dependencies.

Common Fixes to Try

1. Kill and Restart Stale Java/Gradle Processes

Gradle might be stuck with a stale daemon process holding onto a port. Run these commands in your terminal to clear them out:

# Windows users
taskkill /F /IM java.exe
# macOS/Linux users
pkill -f java

After this, close and reopen VS Code, then try running your app again.

2. Disable Gradle Daemon (Temporary Workaround)

You can bypass the RMI issue by forcing Gradle to run in non-daemon mode. Head to your project's android folder, create or edit the gradle.properties file, and add this line:

org.gradle.daemon=false

Save the file, then run these commands in your project root:

flutter clean
flutter pub get

Now try launching your app again.

3. Check Firewall/Antivirus Blocking

Sometimes firewalls or antivirus tools block the dynamic ports that Gradle's RMI server uses. Temporarily disable your firewall/antivirus and test if the error goes away. If it does, add exceptions for:

  • java.exe (your JDK's Java executable)
  • adb.exe (Android Debug Bridge)
  • Your Flutter project's root folder

4. Reset Flutter and Gradle Caches

Corrupted cache files are a common culprit. Run these commands in sequence:

# Clean Flutter project cache
flutter clean
# Repair pub cache
flutter pub cache repair
# Move to Android folder and clean Gradle
cd android
./gradlew clean
./gradlew build --refresh-dependencies
# Go back to project root
cd ..
# Reinstall dependencies
flutter pub get

5. Verify Java Environment Setup

Make sure your JAVA_HOME environment variable points to a valid JDK installation (preferably the one bundled with Android Studio). Check it with:

# Windows
echo %JAVA_HOME%
# macOS/Linux
echo $JAVA_HOME

If it's incorrect, update JAVA_HOME to point to Android Studio's bundled JBR (e.g., C:\Program Files\Android\Android Studio\jbr on Windows, /Applications/Android Studio.app/Contents/jbr on macOS).

Quick Note on Your App Code

While it's not related to the current RMI error, there's a syntax issue in your _HomeState class that will cause runtime crashes once you fix the connection problem:

  • Duplicate @override annotations
  • dispose() method incorrectly nested inside initState()

Here's the corrected version of that section:

class _HomeState extends State<Home> {
  VideoPlayerController _controller;

  @override
  void initState() {
    super.initState();
    // Pointing the video controller to our local asset.
    _controller = VideoPlayerController.asset("assets/02.mp4")
      ..initialize().then((_) {
        // Once the video has been loaded we play the video and set looping to true.
        _controller.play();
        _controller.setLooping(true);
        // Ensure the first frame is shown after the video is initialized.
        setState(() {});
      });
  }

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  // Rest of your build method...
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 21:19:09