you*_*arx 10 linux android react-native
我正在构建一个 React-Native android 应用程序。我想将 App.js 文件移动到 src 文件夹中以获得更清晰的文件结构,因此我将此行添加到 expo 对象内的 app.json 文件中:
{
"expo": {
"entryPoint": "./src/App.js",
Run Code Online (Sandbox Code Playgroud)
当我运行该应用程序时,我得到了相同的旧默认 expo 应用程序。我在文件中拥有什么并不重要。当我更改任何内容时,它会引发此错误:
Unable to resolve "../../App" from "node_modules/expo/AppEntry.js"
Run Code Online (Sandbox Code Playgroud)
我还尝试按照此处的建议将此行添加到文件中:
export default Expo.registerRootComponent(App);
Run Code Online (Sandbox Code Playgroud)
我正在使用 Linux 和 android studio 模拟器。
And*_*rew 22
每当我尝试此操作时,对我registerRootComponent有用的方法就是按以下方式导入和使用它:
这是一个非常简单的 App.js
import React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import { registerRootComponent } from 'expo'; // import it explicitly
class App extends React.Component {
render () {
return (
<View style={styles.container}>
<Text>Hello</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white'
}
});
export default registerRootComponent(App); // this is how I register the App component
Run Code Online (Sandbox Code Playgroud)
这是我的 app.json
{
"expo": {
"entryPoint": "./src/App.js", <---- notice my entry point
"name": "ExpoTester",
"slug": "ExpoTester",
"privacy": "public",
"sdkVersion": "32.0.0",
"platforms": [
"ios",
"android"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 package.json
{
"name": "NewApp",
"version": "0.0.0",
"description": "No description",
"author": null,
"private": true,
"main": "node_modules/expo/AppEntry.js",
"dependencies": {
"expo": "^32.0.0",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的文件结构:
??? app.json
??? assets
? ??? icon.png
? ??? splash.png
??? package-lock.json
??? package.json
??? src
??? App.js <- notice the App.js is no longer in the root directory it is now in src
Run Code Online (Sandbox Code Playgroud)
此外,当对应用程序的结构进行任何重大更改时,我喜欢关闭捆绑程序,然后使用它重新启动它expo start -c以确保清除缓存。
| 归档时间: |
|
| 查看次数: |
6396 次 |
| 最近记录: |