React-native-code-push: Dev server 500 error: Unable to resolve module `./assets://index.android`

Created on 6 May 2019  路  13Comments  路  Source: microsoft/react-native-code-push

Steps to Reproduce

  1. Blank react app
  2. Install react-native-navigation
  3. Install react-native-code-push
  4. Followed RNN v2 guide from here https://github.com/Microsoft/react-native-code-push/blob/master/docs/setup-android.md#wix-react-native-navigation-applications

iOS side is working, can't get the android side to work.

Expected Behavior

Load bundle from localhost Dev Server when running debug build

Actual Behavior

What actually happens?
Screenshot_6_5_19__11_50_pm

Reproducible Demo

MainApplication.java

package com.example;

import android.app.Application;

import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
import com.facebook.react.ReactInstanceManager;

import com.reactnativenavigation.NavigationApplication;
import com.reactnativenavigation.react.NavigationReactNativeHost;
import com.reactnativenavigation.react.ReactGateway;

import com.microsoft.codepush.react.CodePush;

import java.util.Arrays;
import java.util.List;
import android.util.Log;

public class MainApplication extends NavigationApplication {

    @Override
    protected ReactGateway createReactGateway() {
        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
            @javax.annotation.Nullable
            @Override
            protected String getJSMainModuleName() {
                return CodePush.getJSBundleFile();
            }
        };
        return new ReactGateway(this, isDebug(), host);
    }

    @Override
    public boolean isDebug() {
        return BuildConfig.DEBUG;
    }

    protected List<ReactPackage> getPackages() {
        // Add additional packages you require here
        // No need to add RnnPackage and MainReactPackage
        return Arrays.<ReactPackage>asList(
            // eg. new VectorIconsPackage()
            new CodePush("REDACTED", getApplicationContext(), isDebug())
        );
    }

    @Override
    public List<ReactPackage> createAdditionalReactPackages() {
        return getPackages();
    }
}

return CodePush.getJSBundleFile(); is returning
: assets://index.android.bundle

Environment

  • react-native-code-push version: 5.6.0
  • react-native version: 0.59.5
  • iOS/Android/Windows version: Android
  • Does this reproduce on a debug build or release build? debug, will crash app on release build
  • Does this reproduce on a simulator, or only on a physical device? both
  • react-native-navigation: 2.18.4

Most helpful comment

@rendomnet

public class MainApplication extends NavigationApplication {

    protected ReactGateway createReactGateway() {
        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
            @javax.annotation.Nullable
            @Override
            protected String getJSBundleFile() {
                return CodePush.getJSBundleFile();
            }
             @Override
             protected String getJSMainModuleName() {
                return "index";
            }

        };
        return new ReactGateway(this, isDebug(), host);
    }

    @Override
    public boolean isDebug() {
        return BuildConfig.DEBUG;
    }

    protected List<ReactPackage> getPackages() {

        return Arrays.<ReactPackage>asList(
                new RNGestureHandlerPackage(),
                new MainReactPackage(),
                new FastImageViewPackage(),  
                new CodePush("KEY", getApplicationContext(), BuildConfig.DEBUG)

        );
    }

    @Override
    public List<ReactPackage> createAdditionalReactPackages() {
        return getPackages();
    }


}

All 13 comments

It was a gradle issue

@eaco-andrew how to fix the problem ?

@eaco-andrew , Do you have any suggestions?

@xuananpham93 ,I finally solve this problem by adding getJSBundleFile in ReactNativeHost:

public class MainApplication extends NavigationApplication {

    private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {

        @Override
        protected String getJSBundleFile() {
        return CodePush.getJSBundleFile();
        }

        @Override
        public boolean getUseDeveloperSupport() {
            return BuildConfig.DEBUG;
        }

        @Override
        protected List<ReactPackage> getPackages() {
            return Arrays.<ReactPackage>asList(
                    new MainReactPackage(),
                    new RNDeviceInfo(),
                    new SvgPackage(),
                    new RNFirebasePackage(),

                    new CodePush("KEY", getApplicationContext(), BuildConfig.DEBUG)
            );
        }

        @Override
        protected String getJSMainModuleName() {
            return "index";
        }
    };

    @Override
    public ReactNativeHost getReactNativeHost() {
        return mReactNativeHost;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        SoLoader.init(this, /* native exopackage */ false);
    }
}

@maleking, thanks for your response. I added this to my code but not work

@xuananpham93 i edited previous comment hope it works

@maleking , are you sure you are using react-native-navigation? Maybe you not

@xuananpham93, yes absolutely 馃槃
( "react-native": "0.59.8","react-native-code-push": "^5.6.0","react-native-navigation": "^2.18.5")

@maleking maybe you have react-native-navigation installed but as far as I can see in your code you are not using it. MainApplication should extend NavigationApplication.

@buskerone yes your are right , my code that i commented was wrong but in my app it is correct and works

@maleking Can you show your MainApplication.java. I have same issue with RNN2
UPDATE: I have addded @Override
protected String getJSMainModuleName() {
return "index";
}
And now I passed this error but gets https://github.com/microsoft/react-native-code-push/issues/1272

@rendomnet

public class MainApplication extends NavigationApplication {

    protected ReactGateway createReactGateway() {
        ReactNativeHost host = new NavigationReactNativeHost(this, isDebug(), createAdditionalReactPackages()) {
            @javax.annotation.Nullable
            @Override
            protected String getJSBundleFile() {
                return CodePush.getJSBundleFile();
            }
             @Override
             protected String getJSMainModuleName() {
                return "index";
            }

        };
        return new ReactGateway(this, isDebug(), host);
    }

    @Override
    public boolean isDebug() {
        return BuildConfig.DEBUG;
    }

    protected List<ReactPackage> getPackages() {

        return Arrays.<ReactPackage>asList(
                new RNGestureHandlerPackage(),
                new MainReactPackage(),
                new FastImageViewPackage(),  
                new CodePush("KEY", getApplicationContext(), BuildConfig.DEBUG)

        );
    }

    @Override
    public List<ReactPackage> createAdditionalReactPackages() {
        return getPackages();
    }


}

Android, I try open access about write and read file, then test it in dev again. this error didn't happen.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Adr1ann picture Adr1ann  路  3Comments

vira-khdr picture vira-khdr  路  3Comments

Fuhrmann picture Fuhrmann  路  3Comments

kevando picture kevando  路  4Comments

SudoPlz picture SudoPlz  路  4Comments