package.json
和build.grade
以使用react 0.18.0
,并且在启动时遇到了此错误。据我所知,AppRegistry
已正确导入。即使我注释掉代码,此错误仍会出现。这在iOS上没有问题。
我错在哪里?
编辑:尝试其他支持0.18.0的样板文件后,我仍然遇到相同的问题。
package.json
和build.grade
以使用react 0.18.0
,并且在启动时遇到了此错误。据我所知,AppRegistry
已正确导入。即使我注释掉代码,此错误仍会出现。这在iOS上没有问题。
我错在哪里?
编辑:尝试其他支持0.18.0的样板文件后,我仍然遇到相同的问题。
重新启动打包器 对我有用。 只需终止React Native打包器并再次运行即可。
请使用以下包:
"react-native-reanimated": "^2.2.4",
我不知道为什么,但当我将AppRegistry.registerComponent从index.js文件移动到直接包含在index.android.js中时,它似乎可以工作。
/**
* 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);
npm start -- --reset-cache
可能端口已被使用。当我第一次运行react-native run-android然后运行npm start时,我遇到了类似的问题。我像这样解决它:首先,获取在端口8081上运行的进程的ID:
sudo lsof -i :8081
我曾多次遇到同样的问题。以下解决方案解决了我的问题。我根据复杂程度列出了它们。
Restart the computer and see whether the problem is out
If it still exists, try to kill the process on running port usually 8080
netstat -ano | findstr 8080
taskkill /F /PID <PID>
If it still exists, go to 'android' directory as follow and go further
cd android
./gradlew clean
并启动节点
npm start
然后运行npx react-native run android
或expo stat
,并按下'a'
希望您对上述问题满意。
我遇到的问题通过以下命令得到解决(操作系统:Windows 10)。
cd android
gradlew clean
cd..
npx react-native run-android
我曾遇到过同样的问题,那是因为我在没有导入的情况下调用了样式表。
react-native run-android
来构建应用程序。这样做是有效的。在运行sudo ./gradlew clean
之前,请先尝试这个方法,这将为您节省大量时间。我的问题通过增加inotify max_user_watches得到了解决:
sudo sysctl fs.inotify.max_user_watches=1280000
One of the sources for assign has an enumerable key on the prototype chain.
- Josh Ferrara