React Native app闪退 显示 “很抱歉, ‘xxx’ 无法运行”
这种情况一般是因为第三方库的配置有问题或者js 代码写的有问题
- 首先看看js代码是否有问题
去官方下载正确的代码
import React from 'react';
import { View, Text } from 'react-native';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
class HomeScreen extends React.Component {
render() {
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
</View>
);
}
}
const AppNavigator = createStackNavigator({
Home: {
screen: HomeScreen,
},
});
export default createAppContainer(AppNavigator);
然后惊喜的发现可以正常运行
所有可以断定是因为js代码有问题导致的闪退, 我冤枉了node.js 。。。
2.查看js 代码
import React, {Component} from 'react';
import { createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack';
import 'react-native-gesture-handler';
import Index from './src/index/index';
import Search from './src/search/search';
const AppNavigator = createStackNavigator({
Index: Index,
Search: Search,
},
{
initialRouteName: 'Index',
});
const AppContainer = createAppContainer(AppNavigator);
export default class App extends React.Component {
render() {
return <AppContainer />;
}
}
发现是index.js中的下面一段代码有问题
<View style={styles.search}>
<View style={styles.searchInput} onClick={() => { document.location.href = "search.html"; }}>
<Image style={styles.searchIcon} source={{uri:"http://yanxuan.nosdn.127.net/hxm/yanxuan-wap/p/20161201/style/img/icon-normal/search2-2fb94833aa.png"}}/>
<Text style={styles.searchText}>商品搜索, 共{this.state.goodsCount}款好物</Text>
</View>
</View>
删了就可以正常了。。。好吧。我该好好学习RN 基础知识了