New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] module 0 is not a registered callable module. #7832

Closed
chufengma opened this Issue May 30, 2016 · 27 comments

Comments

Projects
None yet
@chufengma
Copy link

chufengma commented May 30, 2016

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

@charpeni

This comment has been minimized.

Copy link
Collaborator

charpeni commented May 30, 2016

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

@chufengma

This comment has been minimized.

Copy link
Author

chufengma commented May 31, 2016

@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) ?

@glcrazier

This comment has been minimized.

Copy link

glcrazier commented May 31, 2016

This normally happens when your react-native version of the application and dev server are not matched.

@chufengma

This comment has been minimized.

Copy link
Author

chufengma commented May 31, 2016

@glcrazier When I Integrating with Existing Apps, My Android Project use gradle :

compile 'com.facebook.react:react-native:+' // From node_modules

use the latest react-native version. (0.20.1 In Maven)

So, latest react-native version in maven is old ?

@glcrazier

This comment has been minimized.

Copy link

glcrazier commented Jun 1, 2016

@chufengma from package.json, the react-native version dev server uses is 0.26.1. if u use 0.20.1 in your application, it won't work. I suggest you to specify the version clearly in your gradle file

@LunaGao

This comment has been minimized.

Copy link

LunaGao commented Jun 1, 2016

I got the same error.

build.gradle

 dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.facebook.react:react-native:+'
    compile 'com.jakewharton:butterknife:8.0.1'
    apt 'com.jakewharton:butterknife-compiler:8.0.1'
}

package.json

{
  "name": "reacttest",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node node_modules/react-native/local-cli/cli.js start"
  },
  "author": "luna gao",
  "license": "ISC",
  "dependencies": {
    "react": "^15.1.0",
    "react-native": "^0.27.0-rc2"
  }
}

make the "react-native" from "^0.27.0-rc2" to "^0.26.1" is ok?

@nevir

This comment has been minimized.

Copy link
Contributor

nevir commented Jun 9, 2016

I'm experiencing this on 0.27.1 as well (packager is being run from the local node_modules; same copy of react-native).

Strangely, the first time I boot the app in the android emulator, it works fine. The instant I reload, or attempt to attach the chrome debugger, I start seeing a myriad of module # is not a registered callable module errors.

@suxiaoyv

This comment has been minimized.

Copy link

suxiaoyv commented Jun 14, 2016

+1

@bschandramohan

This comment has been minimized.

Copy link

bschandramohan commented Jun 14, 2016

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

This comment has been minimized.

Copy link
Contributor

nevir commented Jun 14, 2016

@bschandramohan

This comment has been minimized.

Copy link

bschandramohan commented Jun 14, 2016

@nevir Thanks. Interestingly if I just give "com.facebook.react:react-native:+" on a react-native init project, then it downloads 0.27.2.
If I include that in my existing android project, then it loads 0.20.1.
https://bintray.com/bintray/jcenter/com.facebook.react:react-native/view as well as http://mvnrepository.com/artifact/com.facebook.react/react-native seem to have 0.20.1 as the latest, so NOT sure how a new init project is able to download the latest version of react-native.
Any idea why?

@nevir

This comment has been minimized.

Copy link
Contributor

nevir commented Jun 14, 2016

@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 :-/

@nevir

This comment has been minimized.

Copy link
Contributor

nevir commented Jun 14, 2016

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)

@aqrun

This comment has been minimized.

Copy link

aqrun commented Jun 15, 2016

Thank you all I got this error fixed today
problem is the path of com.facebook.react:react-native:+
you don't need rebuild rn from source

maven {
            // All of React Native (JS, Android binaries) is installed from npm
            url "$projectDir/../node_modules/react-native/android"
}

this config point to npm downloaded newest build version
open the file $projectDir/../node_modules/react-native/android/0.27.2/react-native-0.27.2.pom
got this:

<dependency>
      <groupId>com.android.support</groupId>
      <artifactId>appcompat-v7</artifactId>
      <version>23.0.1</version>
      <scope>compile</scope>
</dependency>

you'd better spcify the config version to

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile "com.facebook.react:react-native:0.27.2"
}
@bschandramohan

This comment has been minimized.

Copy link

bschandramohan commented Jun 16, 2016

@alex306314 the method you suggest works if the same project has both android and react-native code. Your npm install downloads the latest React Native library.

However if you have your android project in a separate repo (which doesn't use npm install), and only have compile "com.facebook.react:react-native:0.27.2" in gradle file, it will NOT be able to download that.

For those scenarios, @nevir suggested building from React Native source.

@bschandramohan

This comment has been minimized.

Copy link

bschandramohan commented Jun 27, 2016

The other solution/workaround that works for android project (separate from your react native) one is to provide the maven reference to your react native project's node modules in the build.gradle file.

For e.g.,

allprojects {
    repositories {
        jcenter()
        maven {
            url <Point to maven repo>
        }
        maven {
            url "$projectDir/../<React Native Project>/node_modules/react-native/android"
        }
    }
}
@nevir

This comment has been minimized.

Copy link
Contributor

nevir commented Jun 27, 2016

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)

@christopherdro

This comment has been minimized.

Copy link
Contributor

christopherdro commented Jul 6, 2016

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

@nevir

This comment has been minimized.

Copy link
Contributor

nevir commented Jul 7, 2016

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
#7832 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AAChnYqTG6yBCRySJ_laolAxv0511yftks5qTD13gaJpZM4Ipqxa
.

@adamshone

This comment has been minimized.

Copy link

adamshone commented Jul 8, 2016

Thanks @nevir, I had the same problem - we were running off a fork of react-native from Github rather than npm and didn't have the generated artifacts, so I guess it was silently falling back to an incompatible version. It was working on another developer machine because he had the generated folder lying around from before we forked it.

Would have taken me forever to find the cause :/

@Kureev

This comment has been minimized.

Copy link
Contributor

Kureev commented Jul 8, 2016

@christopherdro should we compose a PR to the docs explaining this?

@christopherdro

This comment has been minimized.

Copy link
Contributor

christopherdro commented Jul 8, 2016

@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

@devhyunjae

This comment has been minimized.

Copy link

devhyunjae commented Jul 12, 2016

@christopherdro @nevir I am in the same situation. Forked 0.29-stable, and as you mentioned, node_modules/react-native/android does not exist. So i have Run ./gradlew :ReactAndroid:installArchives inside the android dir(does this mean PROJECT_ROOT/android or PROJECT_ROOT/node_modules/react-native/android?), and this throws error like below,

* Exception is:
org.gradle.execution.taskpath.ProjectFinderByTaskPath$ProjectLookupException: Project 'ReactAndroid' not found in root project 'latest'.
        at org.gradle.execution.taskpath.ProjectFinderByTaskPath.findProject(ProjectFinderByTaskPath.java:47)
        at org.gradle.execution.taskpath.TaskPathResolver.resolvePath(TaskPathResolver.java:49)
        at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:79)
        at org.gradle.execution.TaskSelector.getSelection(TaskSelector.java:75)
        at org.gradle.execution.commandline.CommandLineTaskParser.parseTasks(CommandLineTaskParser.java:42)
        at org.gradle.execution.TaskNameResolvingBuildConfigurationAction.configure(TaskNameResolvingBuildConfigurationAction.java:44)
        at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
        at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
        at org.gradle.execution.ExcludedTaskFilteringBuildConfigurationAction.configure(ExcludedTaskFilteringBuildConfigurationAction.java:47

)
        at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
        at org.gradle.execution.DefaultBuildExecuter.access$100(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:48)
        at org.gradle.execution.DefaultTasksBuildExecutionAction.configure(DefaultTasksBuildExecutionAction.java:44)
        at org.gradle.execution.DefaultBuildExecuter.configure(DefaultBuildExecuter.java:42)
        at org.gradle.execution.DefaultBuildExecuter.select(DefaultBuildExecuter.java:35)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)

@DeDuckProject

This comment has been minimized.

Copy link

DeDuckProject commented Jul 15, 2016

@alex306314 I've tried doing that.

my package.json is:

{ "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "dependencies": { "react": "15.2.0", "react-native": "^0.28.0" }, "devDependencies": {}, "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "start": "node node_modules/react-native/local-cli/cli.js start" } }

My gradle has:

compile "com.facebook.react:react-native:+" // From node_modules

As well as the Maven:
url "$rootDir/node_modules/react-native/android"

node_modules has the correct react-native version - 0.28.0
But .idea/libraries has react_native_0_20_1.xml created - which, as I understand means that gradle has downloaded 0.20.1.

If I change gradle to
compile "com.facebook.react:react-native:0.28.0" // From node_modules

I get a cannot resolve. My npm install is on the same repo as the android project.
Can I have android use the correct react-native version without going through all the build from source procedure?

@thiagoterleski

This comment has been minimized.

Copy link

thiagoterleski commented Aug 19, 2016

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.

@LiangliangSha

This comment has been minimized.

Copy link

LiangliangSha commented Aug 26, 2016

My solution to this is change the react-native version of the packager to 0.20.0,the content of the package.json is like below:

{
"name": "helloworld",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"author": "",
"license": "ISC",
"dependencies": {
"react-native": "^0.20.0"
}
}

@lacker

This comment has been minimized.

Copy link
Contributor

lacker commented Nov 30, 2016

It sounds like the original issue has led to some workarounds which are reasonable for now, so I am going to close this issue. It also seems like there are some people commenting with related-but-not-the-same issues - if those continue to be a problem then I encourage folks to open a new issue with repro information.

@lacker lacker closed this Nov 30, 2016

@facebook facebook locked as resolved and limited conversation to collaborators Jul 19, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.