2016-01-23 160 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" ]