我的React Native应用在启动画面消失后立即崩溃。

huangapple go评论74阅读模式
英文:

My React Native App crashes as soon as splash screen disappears

问题

我在使用 eas 构建的简单应用程序上遇到了这个问题。
当从 expo start 运行时,它运行得很完美,但是当构建为 APK 并在 Android 上安装时崩溃。

应用程序记录的错误是:

com.facebook.react.common.JavascriptException: Error: Requiring unknown module "undefined"., js engine: hermes, stack:
unknownModuleError@1:36453
loadModuleImplementation@1:36262
guardedLoadModule@1:35860
metroRequire@1:35531
?anon_0_@1:1397940
asyncGeneratorStep@1:507933
_next@1:508205
anonymous@1:508157
tryCallTwo@61:8
doResolve@216:24
Promise@82:13
anonymous@1:508078
_getDataFromDB@1:1397896
getDataFromDB@1:1397844
?anon_0_@1:1398217
asyncGeneratorStep@1:507933
_next@1:508205
tryCallOne@53:15
anonymous@139:26
anonymous@1:195409
_callTimer@1:194406
_callReactNativeMicrotasksPass@1:194570
callReactNativeMicrotasks@1:196484
__callReactNativeMicrotasks@1:62331
anonymous@1:61473
__guard@1:62208
flushedQueue@1:61384
invokeCallbackAndReturnFlushedQueue@1:61327

	at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
	at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
	at com.facebook.jni.NativeRunnable.run(Native Method)
	at android.os.Handler.handleCallback(Handler.java:914)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
	at android.os.Looper.loop(Looper.java:224)
	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
	at java.lang.Thread.run(Thread.java:919)

Package.json

{
  "name": "app-name",
  "version": "1.0.0",
  "author": "njbsyd",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~48.0.18",
    "expo-status-bar": "~1.4.4",
    "react": "18.2.0",
    "react-native": "0.71.8",
    "@expo/vector-icons": "^13.0.0",
    "@react-native-async-storage/async-storage": "1.17.11",
    "@react-navigation/material-bottom-tabs": "^6.2.15",
    "@react-navigation/native": "^6.1.6",
    "@react-navigation/stack": "^6.3.16",
    "axios": "^1.4.0",
    "expo-sqlite": "~11.1.1",
    "lottie-ios": "^3.4.0",
    "lottie-react-native": "5.1.4",
    "react-native-action-button": "^2.8.5",
    "react-native-autocomplete-input": "^5.3.2",
    "react-native-element-dropdown": "^2.9.0",
    "react-native-gesture-handler": "~2.9.0",
    "react-native-paper": "^5.8.0",
    "react-native-safe-area-context": "4.5.0",
    "react-native-screens": "~3.20.0",
    "react-native-vector-icons": "^9.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

eas.json

{
  "cli": {
    "version": ">= 3.13.3"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {
      "android": {
        "buildType": "apk"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

我使用以下命令构建:eas build -p android --profile production
请帮忙解决。

预期应用程序构建会加载,我在启动屏幕上添加了一些获取数据的功能,加载完成后应用程序会进入下一个屏幕。但它突然崩溃。

英文:

I encountered this problem on simple app build with eas.
It works perfectly when running from expo start but crashes when build as apk and installed on android.

The error that is logged by the app is:

com.facebook.react.common.JavascriptException: Error: Requiring unknown module "undefined"., js engine: hermes, stack:
unknownModuleError@1:36453
loadModuleImplementation@1:36262
guardedLoadModule@1:35860
metroRequire@1:35531
?anon_0_@1:1397940
asyncGeneratorStep@1:507933
_next@1:508205
anonymous@1:508157
tryCallTwo@61:8
doResolve@216:24
Promise@82:13
anonymous@1:508078
_getDataFromDB@1:1397896
getDataFromDB@1:1397844
?anon_0_@1:1398217
asyncGeneratorStep@1:507933
_next@1:508205
tryCallOne@53:15
anonymous@139:26
anonymous@1:195409
_callTimer@1:194406
_callReactNativeMicrotasksPass@1:194570
callReactNativeMicrotasks@1:196484
__callReactNativeMicrotasks@1:62331
anonymous@1:61473
__guard@1:62208
flushedQueue@1:61384
invokeCallbackAndReturnFlushedQueue@1:61327

	at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
	at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
	at com.facebook.jni.NativeRunnable.run(Native Method)
	at android.os.Handler.handleCallback(Handler.java:914)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
	at android.os.Looper.loop(Looper.java:224)
	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
	at java.lang.Thread.run(Thread.java:919)

Package.json

{
  "name": "app-name",
  "version": "1.0.0",
  "author": "njbsyd",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~48.0.18",
    "expo-status-bar": "~1.4.4",
    "react": "18.2.0",
    "react-native": "0.71.8",
    "@expo/vector-icons": "^13.0.0",
    "@react-native-async-storage/async-storage": "1.17.11",
    "@react-navigation/material-bottom-tabs": "^6.2.15",
    "@react-navigation/native": "^6.1.6",
    "@react-navigation/stack": "^6.3.16",
    "axios": "^1.4.0",
    "expo-sqlite": "~11.1.1",
    "lottie-ios": "^3.4.0",
    "lottie-react-native": "5.1.4",
    "react-native-action-button": "^2.8.5",
    "react-native-autocomplete-input": "^5.3.2",
    "react-native-element-dropdown": "^2.9.0",
    "react-native-gesture-handler": "~2.9.0",
    "react-native-paper": "^5.8.0",
    "react-native-safe-area-context": "4.5.0",
    "react-native-screens": "~3.20.0",
    "react-native-vector-icons": "^9.2.0"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

eas.json

{
  "cli": {
    "version": ">= 3.13.3"
  },
  "build": {
    "development": {
      "developmentClient": true,
      "distribution": "internal"
    },
    "preview": {
      "distribution": "internal"
    },
    "production": {
      "android": {
        "buildType": "apk"
      }
    }
  },
  "submit": {
    "production": {}
  }
}

I build with eas build -p android --profile production command.
Please! Help.

The app build is expected to load and on the splash screen I added some Fetching functions and after it is loaded the app proceeds to next screen. But it crashes unexpectedly.

答案1

得分: 0

我找到了我的问题答案。因此,我将在Stack Overflow上回答它,以帮助任何遇到相同问题的人。

问题出在一个由EAS构建的Android应用程序上,当启动画面加载时就会崩溃。问题在于代码中缺少了一些文件。这是因为EAS会将文件打包并上传到服务器进行构建过程。然而,它只包括那些在提交中的文件,并跳过在忽略文件中指定的文件,例如.gitignore

为了解决这个问题,首先运行以下命令:

eas build:inspect --platform android|ios --stage archive --output <现有目录>/eas归档文件夹名称 --profile <eas.json中的配置文件名称>

此命令可以帮助您检查哪些文件被包含在您的构建中。请将占位符替换为适当的信息。

然后,打开生成的归档文件并检查是否缺少任何文件。在我的情况下,我发现我的"Secret File"文件缺失,因为我将其放在了.gitignore文件中,以避免提交到GitHub。

通过按照这些步骤操作,您可以确定哪些文件包含在您的构建中,并确保由于忽略配置而未被遗漏的任何必要文件。

希望这个解释有所帮助!

英文:

I found the answer to my question. So I will answer it on Stack Overflow to help anyone else who encounters the same problem.

The problem was with an EAS-built Android app that kept crashing as soon as the splash screen loaded. The issue in the code was that some files were missing. This happened because EAS zips the files and uploads them to servers for the build process. However, it only includes files that are part of the commits and skips those specified in the ignore files like .gitignore.

To solve this problem, first run this command:


eas build:inspect --platform android|ios --stage archive --output &lt;Existing Directory&gt;\folder name for_eas_archive --profile &lt;profile name from eas.json&gt;

This command helps you check which files of yours are being included in your build. Replace the placeholders with appropriate information.

Then, open the generated archive and check if any files are missing. In my case, I found my Secret File file missing because I had put it in the .gitignore file to avoid committing it to GitHub.

By following these steps, you can identify which files are being included in your build and ensure that any necessary files are not being omitted due to ignore configurations.

I hope this explanation helps!

huangapple
  • 本文由 发表于 2023年6月19日 03:15:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76502165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定