How to set publishedUrl, embeddedResponses and embedded manifest correctly?

#1

Hi,

I want to host my application with my own server. Also, I want to put my bundle and manifest that generated by expo export into app that the application can load them during my server is down. Here is what I have done:

Step 1.
Fisrt, I follow the tutorial Hosting An App on Your Servers to export my bundle and assets that generated by expo export --publish-url http://10.1.1.50:8000. After executing the command, I will got a dist folder that looks like:

dist
├ assets
    ╰ [all images and ttf here]
├ bundles
    ├ android-32898736a2d4fa1cf3aa6baf8b58ea30.js
    ╰ ios-cd9489075273dd38190795a6cdcc3a0f.js
├ android-index.json
╰ ios-index.json 

So, I started a very simple HTTP server with IP address: 10.1.1.50 and port 8000 to serve these files.

Step 2.
Then, I open the android project with Android Studio. I replaced the return value of function publishedUrl() in android/app/src/main/java/host.exp.exponent/MainActivity:

public class MainActivity extends DetachActivity {

  @Override
  public String publishedUrl() {
    return "exp://10.1.1.50:8000/android-index.json";
    //return "exp://exp.host/@renweiluo/<my project name>";
  }

Step 3.
In order to make my application do work offline, I modified AppConstants.java

static {
    List<Constants.EmbeddedResponse> embeddedResponses = new ArrayList<>();

        // ADD EMBEDDED RESPONSES HERE
        // START EMBEDDED RESPONSES
        embeddedResponses.add(new Constants.EmbeddedResponse("http://10.1.1.50:8000", "assets://shell-app-manifest.json", "application/json"));
        embeddedResponses.add(new Constants.EmbeddedResponse("http://10.1.1.50:8000/bundles/android-32898736a2d4fa1cf3aa6baf8b58ea30.js", "assets://shell-app.bundle", "application/javascript"));
        // END EMBEDDED RESPONSES
    EMBEDDED_RESPONSES = embeddedResponses;
}

Step 4.
Replace shell-app-manifest.json and shell-app.bundle

dist/bundles/android-32898736a2d4fa1cf3aa6baf8b58ea30.js -> android/app/src/main/assets/shell-app.bundle
dist/android-index.json -> android/app/src/main/assets/shell-app.bundleshell-app-manifest.json

After all are done, I build the application into .apk and install the app into my android device. The application work fine when my HTTP server is online. But, if I shut down the HTTP server, the application keep showing Error:

Uncaught Error: java.net.ConnectException: Failed to connect to /10.1.1.50:8000

hh:mm:ss Fatal Error

Did I do anything wrong? Any help is very grateful

Thank you