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

因8081端口被占用,如何构建指向8087端口Metro Bundler的Android Debug版本

How to Redirect Detox Android Debug Build to Metro Bundler on Port 8087

Got it, let's fix that port conflict issue from your antivirus blocking 8081. Here's a step-by-step guide to get your Detox Android Debug build connected to Metro running on 8087:

1. Set Metro to Use Port 8087

First, update your Metro config to listen on the new port. Open or create metro.config.js in your project root and add the server port setting:

module.exports = {
  server: {
    port: 8087,
  },
  // Keep the rest of your existing Metro config here
};

2. Tell Detox About the New Metro Port

Next, update your Detox configuration so it knows to connect to Metro on 8087. Open detox.config.js (or your package.json if Detox config lives there) and adjust the Android configuration:

module.exports = {
  configurations: {
    android: {
      // Your existing Android config (binaryPath, testBinaryPath, etc.)
      metroPort: 8087, // Add this line to specify the port
    },
  },
};

3. Configure Android App to Connect to 8087

Your Android app needs to know to reach Metro on the new port during debug. The easiest way is to update the string resource:

  • Navigate to android/app/src/main/res/values/strings.xml

  • Add or modify the debug_http_host line:

    <string name="debug_http_host" translatable="false">localhost:8087</string>
    

    If you prefer modifying the Java code instead, open android/app/src/main/java/com/[your-app-package]/MainApplication.java and check the getUseDeveloperSupport method. Ensure the ReactInstanceManager is initialized with the correct port (though the string resource method is simpler and recommended).

4. Start Metro on Port 8087

Before running your Detox build, launch Metro with the specified port:

npx react-native start --port 8087

5. Build and Run Detox Tests

Now you can build your Android Debug build and run tests—Detox will connect to Metro on 8087 instead of 8081:

detox build -c android.debug
detox test -c android.debug

That should resolve the port conflict and get your Detox build working smoothly.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 07:41:47