2016-01-23 156 views
51

我目前正试图在Android模拟器上运行ES6 react-native-webpack-server运行 。不同之处在于我升级了我的package.jsonbuild.grade以使用反应0.18.0,并且在启动时出现此错误。据我所知AppRegistry正确导入。即使我要将代码注释掉,这个错误仍然会出现。这在iOS上可以正常工作。React-Native:模块AppRegistry不是已注册的可调用模块

我在做什么错?

编辑:在尝试其他支持0.18.0的样板后,我仍然遇到同样的问题。

enter image description here

+0

我与0.19和0.20有同样的问题,我尝试了一切,但没有运气:'(任何更新@Dustin? – Shprink

+0

@Shprink我也遇到这个问题0.20。也收到这个问题'分配的来源之一在原型链上有一个枚举键。' –

回答

22

我刚刚升级到反应本土今天0.18.1强硬有一些与0.19.0-rc预发布版本等的依赖问题。

回到你的问题,我所做的就是

  1. cd android
  2. sudo ./gradlew clean

然后再返回到工作目录并运行 react-native run-android

您应该重新启动您的NPM太升级之后。

希望这适合你。

+3

我试图运行gradlew命令,但它一直告诉我它无法找到Android SDK,即使我有'ANDROID_HOME “在我的道路上。我还用'sdk.dir ='添加了'local.properties'文件。有任何想法吗? – steezeburger

+9

当给出建议做类似'sudo ./gradlew clean'的建议时,很高兴提及它是一个**巨大的**操作,显然会重新下载并重新安装整个gradle分发。 –

+0

它虽然工作,所以+1。 –

1

我不知道为什么,但是当我将Index.android.js中包含的index.js文件中的AppRegistry.registerComponent直接移到index.android.js中时,它似乎可以工作。

9

我对IOS同样的问题和原因,我什么,我index.io.js是不正确的(因为我复制粘贴的一个例子不看它的内容),它与一个模块结束出口报关

exports.title = ... 
exports.description = ... 
module.exports = MyRootComponent; 

而不是预期的

AppRegistry.registerComponent('MyAppName',() => MyRootComponent); 

你可以有与我猜index.android.js的Android同样的问题。

1

如果您正在使用其中的一些例子,可能就无法

这里是我的版本为滚动视图

/** 
* Sample React Native App 
* https://github.com/facebook/react-native 
*/ 

import React, { 
    AppRegistry, 
    Component, 
    StyleSheet, 
    Text, 
    View, 
    ScrollView, 
    TouchableOpacity, 
    Image 
} from 'react-native'; 

class AwesomeProject extends Component { 
    render() { 
    return (
     <View> 
      <ScrollView 
      ref={(scrollView) => { _scrollView = scrollView; }} 
      automaticallyAdjustContentInsets={false} 
      onScroll={() => { console.log('onScroll!'); }} 
      scrollEventThrottle={200} 
      style={styles.scrollView}> 
      {THUMBS.map(createThumbRow)} 
      </ScrollView> 
      <TouchableOpacity 
      style={styles.button} 
      onPress={() => { _scrollView.scrollTo({y: 0}); }}> 
      <Text>Scroll to top</Text> 
      </TouchableOpacity> 
     </View> 
    ); 
    } 
} 

var Thumb = React.createClass({ 
    shouldComponentUpdate: function(nextProps, nextState) { 
    return false; 
    }, 
    render: function() { 
    return (
     <View style={styles.button}> 
     <Image style={styles.img} source={{uri:this.props.uri}} /> 
     </View> 
    ); 
    } 
}); 

var THUMBS = [ 
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1, 
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1, 
'http://loremflickr.com/320/240?random='+Math.round(Math.random()*10000) + 1 
]; 

THUMBS = THUMBS.concat(THUMBS); // double length of THUMBS 
var createThumbRow = (uri, i) => <Thumb key={i} uri={uri} />; 

var styles = StyleSheet.create({ 
    scrollView: { 
    backgroundColor: '#6A85B1', 
    height: 600, 
    }, 
    horizontalScrollView: { 
    height: 120, 
    }, 
    containerPage: { 
    height: 50, 
    width: 50, 
    backgroundColor: '#527FE4', 
    padding: 5, 
    }, 
    text: { 
    fontSize: 20, 
    color: '#888888', 
    left: 80, 
    top: 20, 
    height: 40, 
    }, 
    button: { 
    margin: 7, 
    padding: 5, 
    alignItems: 'center', 
    backgroundColor: '#eaeaea', 
    borderRadius: 3, 
    }, 
    buttonContents: { 
    flexDirection: 'row', 
    width: 64, 
    height: 64, 
    }, 
    img: { 
    width: 321, 
    height: 200, 
    } 
}); 

AppRegistry.registerComponent('AwesomeProject',() => AwesomeProject); 
1

我卸载它Genymotion。然后运行react-native run-android来构建应用程序。它的工作。在运行sudo ./gradlew clean之前,请先尝试一下,它会为您节省很多时间。

0

希望这可以节省一个人头痛。升级我的react-native版本后出现此错误。令人困惑的是,它只出现在事物的机器人一侧。

我的文件结构包括一个index.ios.js和一个index.android.js。两者都包含代码:

AppRegistry.registerComponent('App',() => App);

我有什么做的是,在android/app/src/main/java/com/{projectName}/MainApplication.java,改变index到:

@Override protected String getJSMainModuleName() { return "index.android"; // was "index" }

然后在app/build/build.gradle,从index.jsentryFile改变index.android.js

project.ext.react = [ entryFile: "index.android.js" // was index.js" ]