我构建了eas build -p android --profile production(使用Expo SDK 51,构建成功,没有任何问题)。然后,我将 apk 下载到物理设备中。安装并打开它时,应用程序在显示闪屏后崩溃。
模拟器和expo go app没有任何问题
所以我将物理设备连接到电脑并再次尝试如下
1. eas build -p android --profile production --clear-cache
2. adb install -r MyApp.apk
3. adb logcat
但是应用程序在再次显示启动屏幕后崩溃了。
我在Logcat的日志中发现异常如下。
06-18 15:16:23.359 1455 3526 W WindowManager: Exception thrown during dispatchAppVisibility Window{b491ce8 u0 com.myApp.MyApp/com.myApp.MyApp.MainActivity EXITING}
06-18 15:35:37.566 1455 1567 W PackageManager: java.lang.IllegalArgumentException: Unable to get package com.myApp.MyApp
06-18 15:35:38.323 18370 18370 W Finsky : [2] aegq.b(126): STU: Failed to get storage stats for package 'com.myApp.MyApp' (1601: Error getting stats: android.content.pm.PackageManager.NameNotFoundException)
06-18 15:57:18.002 25857 25946 W GOS:PackageUtil: isPackageInstalledAsUser(). Exception: android.content.pm.PackageManager$NameNotFoundException: com.myApp.MyApp
06-18 15:57:53.221 1455 2981 W WindowManager: Exception thrown during dispatchAppVisibility Window{1ccb0a5 u0 com.myApp.MyApp/com.myApp.MyApp.MainActivity EXITING}
06-18 15:58:02.730 1455 6310 E AppOps : java.lang.SecurityException: Specified package "com.myApp.MyApp" under uid -1 but it is not
06-18 16:06:54.320 26999 26999 E AppButtonsPrefCtl: Exception when retrieving package:com.myApp.MyApp
06-18 16:06:54.320 26999 26999 E AppButtonsPrefCtl: android.content.pm.PackageManager$NameNotFoundException: com.myApp.MyApp
06-18 16:06:54.537 18370 18612 W ResourcesManager: java.io.IOException: Failed to load asset path /data/app/~~DvIivdyMBKmqze5UOR38yA==/com.myApp.MyApp-djdb_-FbcxNuzhRd3BN9Dw==/base.apk
有人可以告诉我、指导我或给我建议吗?
这是我的app.json,eas.json和package.json
app.json
{
"expo": {
"name": "MyApp",
"slug": "MyApp",
"platforms": [
"ios",
"android"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"scheme": "myapp",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.myApp.MyApp",
"buildNumber": "1.0.0"
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/images/icon.png",
"backgroundColor": "#ffffff"
},
"package": "com.myApp.MyApp",
"versionCode": 1
},
"web": {
"bundler": "metro",
"output": "static",
"favicon": "./assets/images/favicon.png"
},
"plugins": [
"expo-router",
"expo-font"
],
"experiments": {
"typedRoutes": true,
"tsconfigPaths": true
},
"extra": {
"router": {
"origin": false
},
"eas": {
"projectId": "xxxx-xxxx-xxxx-xxxx-xxxx"
}
}
}
}
eas.json
{
"cli": {
"version": ">= 9.2.0"
},
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"preview": {
"distribution": "internal"
},
"production": {
"android": {
"buildType": "apk"
}
}
},
"submit": {
"production": {}
}
}
package.json
{
"name": "myApp",
"main": "expo-router/entry",
"version": "1.0.0",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"test": "jest --watchAll"
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@expo/vector-icons": "^14.0.0",
"@react-native-async-storage/async-storage": "1.23.1",
"@react-native-community/datetimepicker": "8.0.1",
"@react-native-picker/picker": "2.7.5",
"@react-navigation/native": "^6.0.2",
"@supabase/supabase-js": "^2.43.1",
"@tanstack/react-query": "^5.36.0",
"expo": "^51.0.14",
"expo-constants": "~16.0.2",
"expo-device": "~6.0.2",
"expo-font": "~12.0.7",
"expo-linking": "~6.3.1",
"expo-notifications": "~0.28.9",
"expo-router": "~3.5.16",
"expo-splash-screen": "~0.27.5",
"expo-status-bar": "~1.12.1",
"expo-system-ui": "~3.0.6",
"expo-web-browser": "~13.0.3",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.51.3",
"react-native": "0.74.2",
"react-native-elements": "^3.4.3",
"react-native-modal-datetime-picker": "^17.1.0",
"react-native-safe-area-context": "4.10.1",
"react-native-screens": "3.31.1",
"react-native-select-dropdown": "^4.0.1",
"react-native-url-polyfill": "^2.0.0",
"react-native-web": "~0.19.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "~18.2.45",
"jest": "^29.2.1",
"jest-expo": "~51.0.1",
"react-test-renderer": "18.2.0",
"typescript": "~5.3.3"
},
"private": true
}
我的项目 EXPO SDK 51 也有同样的问题。Expo Go 上一切正常,但生产版本崩溃了。