我正在尝试构建适用于 iOS 的 React Native 应用程序,但遇到了一些问题。首先,这是我的
package.json
文件:
{
"name": "MyRNApp",
"version": "1.7.0",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@apollo/client": "^3.11.4",
"@notifee/react-native": "^7.8.2",
"@react-native-async-storage/async-storage": "^1.24.0",
"@react-native-clipboard/clipboard": "^1.13.0",
"@react-native-community/blur": "^4.4.0",
"@react-native-community/checkbox": "^0.5.17",
"@react-native-community/datetimepicker": "^8.2.0",
"@react-native-community/geolocation": "^3.3.0",
"@react-native-firebase/app": "^20.3.0",
"@react-native-firebase/messaging": "^20.3.0",
"@react-native-google-signin/google-signin": "^12.2.1",
"@react-navigation/bottom-tabs": "^6.6.0",
"@react-navigation/drawer": "^6.7.0",
"@react-navigation/elements": "^1.3.31",
"@react-navigation/material-top-tabs": "^6.6.14",
"@react-navigation/native": "^6.1.17",
"@react-navigation/native-stack": "^6.10.0",
"@react-navigation/stack": "^6.4.1",
"@tanstack/react-query": "^5.50.1",
"@twotalltotems/react-native-otp-input": "^1.3.11",
"axios": "^1.7.2",
"datetimepicker": "^0.1.39",
"graphql": "^16.9.0",
"i18next": "^23.12.2",
"lottie-react-native": "^6.7.2",
"react": "18.2.0",
"react-i18next": "^15.0.0",
"react-native": "0.74.3",
"react-native-android-location-enabler": "^2.0.1",
"react-native-animatable": "^1.4.0",
"react-native-calendars": "^1.1306.0",
"react-native-dotenv": "^3.4.11",
"react-native-elements": "^3.4.3",
"react-native-gesture-handler": "^2.18.0",
"react-native-get-location": "^4.0.1",
"react-native-image-picker": "^7.1.2",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"react-native-keychain": "^8.2.0",
"react-native-linear-gradient": "^2.8.3",
"react-native-pager-view": "^6.3.3",
"react-native-paper": "^5.12.3",
"react-native-ratings": "^8.1.0",
"react-native-raw-bottom-sheet": "^3.0.0",
"react-native-reanimated": "^3.14.0",
"react-native-responsive-screen": "^1.4.2",
"react-native-safe-area-context": "^4.10.8",
"react-native-screens": "^3.32.0",
"react-native-size-matters": "^0.4.2",
"react-native-svg": "^15.4.0",
"react-native-svg-transformer": "^1.5.0",
"react-native-tab-view": "^3.5.2",
"react-native-vector-icons": "^10.1.0",
"socket.io-client": "^4.7.5",
"zustand": "^4.5.4"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "0.74.85",
"@react-native/eslint-config": "0.74.85",
"@react-native/metro-config": "0.74.85",
"@react-native/typescript-config": "0.74.85",
"@types/react": "^18.2.6",
"@types/react-native-check-box": "^2.1.6",
"@types/react-native-vector-icons": "^6.4.18",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.57.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
},
"engines": {
"node": ">=18"
}
}
这是
Podfile
:
# Resolve react_native_pods.rb with node to allow for hoisting
require Pod::Executable.execute_command('node', ['-p',
'require.resolve(
"react-native/scripts/react_native_pods.rb",
{paths: [process.argv[1]]},
)', __dir__]).strip
platform :ios, min_ios_version_supported
prepare_react_native_project!
linkage = ENV['USE_FRAMEWORKS']
if linkage != nil
Pod::UI.puts "Configuring Pod with #{linkage}ally linked Frameworks".green
use_frameworks! :linkage => linkage.to_sym
end
target 'MyRNApp' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
# An absolute path to your application root.
:app_path => "#{Pod::Config.instance.installation_root}/.."
)
target 'MyRNAppTests' do
inherit! :complete
# Pods for testing
end
post_install do |installer|
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
react_native_post_install(
installer,
config[:reactNativePath],
:mac_catalyst_enabled => false,
# :ccache_enabled => true
)
end
end
当我这样做时
pod install
我收到此错误:
[!] The following Swift pods cannot yet be integrated as static libraries:
The Swift pod `FirebaseCoreInternal` depends upon `GoogleUtilities`, which does not define modules. To opt into those targets generating module maps (which is necessary to import them from Swift when building as static libraries), you may set `use_modular_headers!` globally in your Podfile, or specify `:modular_headers => true` for particular dependencies.
如果我尝试添加行
use_modular_headers!
,我可以执行 pod install
但是当我在 XCode 中运行该项目并构建它时,我收到此错误:
/Users/myuser/Library/Developer/Xcode/DerivedData/MyRNApp-bbxbgmmqpwnecedpcqqamjhrxvpq/Build/Intermediates.noindex/MyRNApp.build/Debug-iphoneos/MyRNApp.build/DerivedSources/MyRNApp.c module map file '/Users/myuser/Library/Developer/Xcode/DerivedData/MyRNApp-bbxbgmmqpwnecedpcqqamjhrxvpq/Build/Products/Debug-iphoneos/FirebaseCoreInternal/FirebaseCoreInternal.modulemap' not found
看来最新的错误可以通过清理 DerivedData 文件夹来解决。请转到此文件夹
/Users/myuser/Library/Developer/Xcode/DerivedData/
,删除与您的项目相关的子文件夹,然后重试。
PS:如果您尝试集成最新版本的 React Native,我建议不要从头开始集成,您可能需要使用 expo 模板(https://docs.expo.dev/get-started/create-a -project )或社区模板( https://github.com/react-native-community/template )。如果此后仍然出现错误,请在此处提供更多信息。