react-native: [Android] module 0 is not a registered callable module.

Error when Integrating with Existing Apps.

My Android project is separated from Js bundle server. android project: c/projects/android js bundle server project: c/projects/react

MainActivity

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mReactRootView = new ReactRootView(this);
        mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "DemoProject", null);

        setContentView(R.layout.activity_main);
        ((FrameLayout)findViewById(R.id.container)).addView(mReactRootView);
    }

app/build,gradle

apply plugin: 'com.android.application'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.onefengma.event.rnandroid"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile 'com.facebook.react:react-native:+' // From node_modules
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
}

My js bundle server package.js :

{
  "name": "RNDemo2",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "react": "^15.1.0",
    "react-native": "^0.27.0-rc2"
  }
}

at js bundle folder react-native start --port 5389

then i reload js at android deivces, It shows : image

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 27 (11 by maintainers)

Most upvoted comments

Anybody got the gradle build version to 27? compile “com.facebook.react:react-native:+” OR compile “com.facebook.react:react-native:0.20.+” both download 0.20.1 only. Specifying any version about 20 like 22, 25,26, 27 all throw error “Failed to resolve com.facebook.react:react-native:0.22.+” compile “com.facebook.react:react-native:0.22.+”

How do we specify gradle build to use the latest 0.27.x react native version?

@nevir I recently learned that you can manually generate the required files for the android dir if you are using a forked version. Run ./gradlew :ReactAndroid:installArchives inside the android dir.

Be aware that if you point to RN from source (e.g. "react-native": "github/react-native#abcd123"), that approach won’t work (node_modules/react-native/android will not exist, and gradle will silently fall through to jcenter)

@bschandramohan So, when Facebook publishes the module to npm, they precompile the android packages, and hide them under node_modules/react-native/android as a maven(?) repository. The default project configuration then points to that path as a package repo.

The annoying bit is that if you check out react native from git, or the build is broken (no android dir), it silently falls back to jcenter 😕

Hi, I had the same problem, I always stop and start the npm start again, but when I run react run-android it works fine. I don’t know what was the problem but works for me.

@Kureev Yea, I think that would be a great idea. I came across this which was intended to be added to the docs. https://github.com/facebook/react-native/blob/b9396cd74419dd4165fb051605076d19b1c18905/ReactAndroid/DevExperience.md

I’ll try and put a PR together

Oho, awesome! Thanks for the tip

On Wed, Jul 6, 2016, 16:42 Christopher Dro notifications@github.com wrote:

@nevir https://github.com/nevir I recently learned that you can manually generate the required files for the android dir if you are using a forked version. Run ./gradlew :ReactAndroid:installArchives inside the android dir.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/facebook/react-native/issues/7832#issuecomment-230939940, or mute the thread https://github.com/notifications/unsubscribe/AAChnYqTG6yBCRySJ_laolAxv0511yftks5qTD13gaJpZM4Ipqxa .

I’ve just moved to always building RN from source in my team’s RN projects - it’s the least error-prone way we could find to guarantee the right version is present (and reduces confusion when we have to temporarily patch something in RN, or bump RN’s version)

@charpeni My js bundle server is a freshly init project. but android project is a pure Android Project. when I start the old js bundle server which i inited before : package.json

{
  "name": "DemoProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "dependencies": {
    "react": "^0.14.8",
    "react-native": "^0.26.1"
  }
}

Android Project load successfully. So , It’s the problem of react or react-native version (and the related node_modules) ?

Looks like an integration issue, does it happens on a freshly init project ?