microsoft / react-native-code-push

React Native module for CodePush
http://appcenter.ms
Other
8.98k stars 1.47k forks source link

Dev server 500 error: Unable to resolve module `./assets://index.android` #1580

Closed eaco-andrew closed 5 years ago

eaco-andrew commented 5 years ago

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

eaco-andrew commented 5 years ago

It was a gradle issue

maleking commented 5 years ago

@eaco-andrew how to fix the problem ?

xuananpham93 commented 5 years ago

@eaco-andrew , Do you have any suggestions?

maleking commented 5 years ago

@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);
    }
}
xuananpham93 commented 5 years ago

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

maleking commented 5 years ago

@xuananpham93 i edited previous comment hope it works

xuananpham93 commented 5 years ago

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

maleking commented 5 years ago

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

buskerone commented 5 years ago

@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.

maleking commented 5 years ago

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

rendomnet commented 5 years ago

@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

maleking commented 5 years ago

@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();
    }

}
sunny635533 commented 5 years ago

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

jet2018 commented 1 year ago

I had the same issue but I realised I had wiped out

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

and added

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

yet we need both methods.

And the error was a result of not finding getJSMainModuleName, added it and everything came back to normal.