现在我正在尝试使用 eas 将我的应用程序导出为 apk,但它不起作用。
当我与 expo 捆绑时,一切正常,但当我构建时,应用程序在启动时崩溃。
我一直在删除和调试大部分代码,并且只有在使用反应导航时构建才会崩溃。我在网上查看过,我有所有必要的依赖项,我不明白我做错了什么。
Expo doctor 没有显示任何问题,文件位于正确的位置(如果情况如此,我也会在 expoGo 中看到这一点)并且应用程序构建时带有所有绿色标志。
还尝试使用 logcat 进行调试并得到此错误(见下文)。看来这是一个与“react-native-gesture-handler”相关的问题。
这是我的代码(不要介意 page1,因为在没有反应导航的情况下使用该代码进行构建时,应用程序工作得很好):
const themeColor1 = "#7CFC00";
const themeColor3 = "#394230";
const themeColor4 = "#141712";
import React from 'react';
import { View, Text} from 'react-native';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import { SafeAreaView } from 'react-native-safe-area-context';
import { NavigationContainer } from '@react-navigation/native';
import { createDrawerNavigator, DrawerItemList } from '@react-navigation/drawer';
import Page1 from './assets/screens/Page1.js';
const Drawer = createDrawerNavigator();
export default function App() {
return (
<NavigationContainer>
<Drawer.Navigator
initialRouteName="Page1"
drawerContent={(props) => (
<SafeAreaView style={{ flex: 1 }}>
<View
style={{
height: 180,
width: '100%',
justifyContent: 'center',
borderBottomColor: themeColor1,
inactiveTintColor: themeColor1,
borderBottomWidth: 0.5,
marginLeft: 0,
alignItems: 'center',
textAlign: 'center',
}}>
<Text
style={{
fontSize: 30,
marginVertical: 6,
justifyContent: 'space-evenly',
color: themeColor1,
textAlign: 'center',
}}>
App that crashes
on startup
</Text>
</View>
<DrawerItemList {...props} />
</SafeAreaView>
)}
screenOptions={{
drawerStyle: {
backgroundColor: themeColor4,
width: 250,
},
headerStyle: {
backgroundColor: themeColor4,
},
headerTintColor: themeColor1,
headerTitleStyle: {
},
drawerLabelStyle: {
color: '#111',
},
headerTitle :{
color: '#111',
},
drawerActiveBackgroundColor: themeColor3,
}}>
<Drawer.Screen
name="Page1"
options={{
title: 'Page1',
drawerLabel: () => (<Text>Page1</Text>),
drawerIcon: () => (<MaterialCommunityIcons name="file-document-edit" size={30} color={themeColor1}/>),
}}
component={Page1}
/>
</Drawer.Navigator>
</NavigationContainer>
);
}
app.json:
{
"expo": {
"name": "App",
"slug": "App",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/icon.png",
"userInterfaceStyle": "light",
"splash": {
"image": "./assets/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"ios": {
"supportsTablet": true
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"package": "com.nicola.app"
},
"web": {
"favicon": "./assets/favicon.png"
},
"extra": {
"eas": {
"projectId": "04e732f6-d275-463b-b775-45ca301b9be1"
}
},
"runtimeVersion": {
"policy": "appVersion"
},
"plugins": [
[
"expo-build-properties",
{
"android": {
"usesCleartextTraffic": true
}
}
]
]
}
}
和eas.json:
{
"build": {
"preview": {
"android": {
"buildType": "apk"
}
},
"preview2": {
"android": {
"gradleCommand": ":app:assembleRelease"
}
},
"preview3": {
"developmentClient": true
},
"preview4": {
"distribution": "internal"
},
"production": {}
}
}
//logcat log:
AndroidRuntime: com.facebook.react.common.JavascriptException: Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGestureHandlerModule' could not be found. Verify that a module by this name is registered in the native binary.Bridgeless mode: false. TurboModule interop: false. Modules loaded: {"NativeModules":["HeadlessJsTaskSupport","PlatformConstants","SourceCode","DeviceInfo","UIManager","DeviceEventManager","RNCSafeAreaContext","NativeAnimatedModule","SoundManager","I18nManager","Timing","ReanimatedModule","ImageLoader"],"TurboModules":[],"NotFound":["NativePerformanceCxx","NativePerformanceObserverCxx","RedBox","BugReporting","NativeReactNativeFeatureFlagsCxx","FrameRateLogger","KeyboardObserver","RNGestureHandlerModule"]}
您有什么建议吗?老实说,我已经没有主意了。
谢谢
尝试按顺序删除所有代码,直到应用程序仅在使用导航时崩溃。
经过一些调试和其他人的建议后,我必须将问题隔离到添加
import "react-native-gesture-handler";
到我的主app.js
在世博会上开发时这不是问题,但我现在发现它在构建的项目中是必要的。