Expo EAS构建应用在Testflight中卡在启动页求助
Expo EAS构建后Testflight卡在启动页的解决办法
你的代码依赖fontsLoaded为true才会隐藏启动页并标记应用就绪,但Testflight环境里可能出现字体加载失败的情况,导致fontsLoaded一直是false,应用就卡在启动页了——Expo Go和EAS构建的资源打包、缓存机制不一样,这是核心问题。
1. 添加字体加载失败的兜底逻辑
修改useFonts的返回值,同时获取加载错误,不管成功失败都让应用进入,避免卡死:
const [fontsLoaded, fontError] = useFonts({ Lato_100Thin, Lato_100Thin_Italic, Lato_300Light, Lato_300Light_Italic, Lato_400Regular, Lato_400Regular_Italic, Lato_700Bold, Lato_700Bold_Italic, Lato_900Black, Lato_900Black_Italic, Mermaid: require("./assets/fonts/Mermaid1001.ttf"), }); useEffect(() => { async function prepare() { try { // 字体加载成功或失败都进入应用 if (fontsLoaded || fontError) { await SplashScreen.hideAsync(); setAppIsReady(true); if (fontError) { console.warn("字体加载失败:", fontError); } } } catch (e) { console.warn(e); // 捕获其他异常,强制进入应用 await SplashScreen.hideAsync(); setAppIsReady(true); } } prepare(); }, [fontsLoaded, fontError]);
2. 检查EAS构建的字体资源配置
- 确保
app.json或app.config.js里正确声明字体资源路径,EAS构建需要明确配置:
{ "expo": { "assetBundlePatterns": [ "assets/fonts/*" ] } }
- 自定义字体
Mermaid1001.ttf的路径要确认无误,EAS构建的路径解析和Expo Go有差异,建议用expo-asset加载:
import { Asset } from 'expo-asset'; // 替换原来的require写法 Mermaid: Asset.fromModule(require("./assets/fonts/Mermaid1001.ttf")),
3. 添加启动页超时机制
防止异步操作卡住导致永久停在启动页,设置5秒超时强制进入应用:
useEffect(() => { const timeoutId = setTimeout(async () => { await SplashScreen.hideAsync(); setAppIsReady(true); console.warn("启动超时,强制进入应用"); }, 5000); async function prepare() { try { if (fontsLoaded) { clearTimeout(timeoutId); await SplashScreen.hideAsync(); setAppIsReady(true); } } catch (e) { clearTimeout(timeoutId); console.warn(e); await SplashScreen.hideAsync(); setAppIsReady(true); } } prepare(); return () => clearTimeout(timeoutId); }, [fontsLoaded]);
内容的提问来源于stack exchange,提问作者red
相关产品推荐
相关产品推荐

