升级到React Native 0.60.5后,iOS版本生成给出“ No bundle URL present”错误

时间:2019-09-05 07:22:00

标签: ios react-native upgrade

我刚刚使用0.59.9和官方博客文章中提到的更新助手将我的项目从React Native 0.60.5更新为react-native upgrade。尽管我的项目已经有些复杂,因为它正在使用某些库等。看来更新很成功。

但不幸的是,我的应用无法再使用Test - Release方案。在调试方案上,它可以正常工作。该发行版还达到“构建成功”状态,但是应用程序启动后由于“无捆绑包URL存在”错误而被卡住(另请参阅我随附的Xcode屏幕截图)。

到目前为止,我已经尝试了所有可以在互联网上找到的内容。重新安装NPM依赖项和Pod;删除构建文件夹,更改NSAppTransportSecurity中的Info.plist,但是 它将无法解决问题。.通过TestFlight部署的应用在启动时也会中断。

反应本地信息

System:
    OS: macOS 10.14.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
    Memory: 430.30 MB / 8.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 10.11.0 - ~/.nvm/versions/node/v10.11.0/bin/node
    Yarn: 1.10.1 - /usr/local/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.11.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  SDKs:
    iOS SDK:
      Platforms: iOS 12.4, macOS 10.14, tvOS 12.4, watchOS 5.3
    Android SDK:
      API Levels: 23, 26, 28, 29
      Build Tools: 28.0.3, 29.0.0
      System Images: android-29 | Google APIs Intel x86 Atom
  IDEs:
    Android Studio: 3.4 AI-183.6156.11.34.5522156
    Xcode: 10.3/10G8 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.60.5 => 0.60.5
  npmGlobalPackages:
    react-native-cli: 2.0.1

复制步骤

  1. 将本机反应从0.59.9更新到0.60.5
  2. 删除node_modulesios/Podsios/buildPodfile.lock
  3. 重新安装node_modules并运行pod install
  4. 打开Project.xcworkspace
  5. 选择方案“项目-测试”,转到“编辑方案>运行>构建配置”,然后将方案更改为“测试-发布”
  6. 构建项目(在设备或模拟器上,没关系)
  7. “构建成功”并且应用启动
  8. 应用程序停留在初始屏幕上,并且Xcode如附件屏幕截图所示显示错误

文件/代码

当前这些是我的Info.plistPodfilepackage.json

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CFBundleDevelopmentRegion</key>
    <string>en</string>
    <key>CFBundleDisplayName</key>
    <string>Jobner</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>$(PRODUCT_NAME)</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>1.0</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>2</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>localhost</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
            </dict>
        </dict>
    </dict>
    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIRequiredDeviceCapabilities</key>
    <array>
        <string>armv7</string>
    </array>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>UIStatusBarHidden</key>
    <true/>
    <key>ITSAppUsesNonExemptEncryption</key>
    <false/>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Your location is required for searching jobs near you</string>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your location is required for searching jobs near you</string>
  <key>LSApplicationQueriesSchemes</key>
  <array>
    <string>whatsapp</string>
  </array>
</dict>
</plist>
platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

project 'Project',
  'Prod - Debug' => :debug,
  'Acc - Debug' => :debug,
  'Test - Debug' => :debug,
  'Prod - Release' => :release,
  'Acc - Release' => :release,
  'Test - Release' => :release

target 'Project' do
  # Pods for Project
  pod 'React', :path => '../node_modules/react-native/'
  pod 'React-Core', :path => '../node_modules/react-native/React'
  pod 'React-DevSupport', :path => '../node_modules/react-native/React'
  pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
  pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
  pod 'React-RCTBlob', :path => '../node_modules/react-native/Libraries/Blob'
  pod 'React-RCTImage', :path => '../node_modules/react-native/Libraries/Image'
  pod 'React-RCTLinking', :path => '../node_modules/react-native/Libraries/LinkingIOS'
  pod 'React-RCTNetwork', :path => '../node_modules/react-native/Libraries/Network'
  pod 'React-RCTSettings', :path => '../node_modules/react-native/Libraries/Settings'
  pod 'React-RCTText', :path => '../node_modules/react-native/Libraries/Text'
  pod 'React-RCTVibration', :path => '../node_modules/react-native/Libraries/Vibration'
  pod 'React-RCTWebSocket', :path => '../node_modules/react-native/Libraries/WebSocket'

  pod 'React-cxxreact', :path => '../node_modules/react-native/ReactCommon/cxxreact'
  pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi'
  pod 'React-jsiexecutor', :path => '../node_modules/react-native/ReactCommon/jsiexecutor'
  pod 'React-jsinspector', :path => '../node_modules/react-native/ReactCommon/jsinspector'
  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'

  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'

  target 'ProjectTests' do
    inherit! :search_paths
    # Pods for testing
  end

  use_native_modules!
end
{
  "name": "project",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "react-native start",
    "lint": "eslint --ext .jsx --ext .js src/",
    "ios": "react-native run-ios --scheme \"Project - Test\" --configuration \"Test - Debug\"",
    "android": "ENVFILE=.env.dev react-native run-android --variant=devDebug --appIdSuffix=dev",
    "postinstall": "npx jetify"
  },
  "dependencies": {
    "@aws-amplify/auth": "1.2.31",
    "@aws-amplify/core": "1.1.0",
    "@babel/polyfill": "7.4.4",
    "@react-native-community/async-storage": "1.6.1",
    "accounting": "0.4.1",
    "amazon-cognito-identity-js": "3.0.15",
    "cross-fetch": "3.0.4",
    "dayjs": "1.8.15",
    "iban": "0.0.12",
    "prop-types": "15.7.2",
    "qs": "6.7.0",
    "react": "16.9.0",
    "react-geocode": "0.1.2",
    "react-native": "0.60.5",
    "react-native-android-keyboard-adjust": "^1.2.0",
    "react-native-bootsplash": "1.0.1",
    "react-native-config": "luggit/react-native-config#master",
    "react-native-datepicker": "1.7.2",
    "react-native-device-info": "2.3.2",
    "react-native-gesture-handler": "1.3.0",
    "react-native-keyboard-aware-scroll-view": "0.9.1",
    "react-native-keyboard-spacer": "^0.4.1",
    "react-native-linear-gradient": "2.5.6",
    "react-native-pdf": "5.1.4",
    "react-native-svg": "9.8.4",
    "react-navigation": "3.11.0",
    "react-redux": "7.1.1",
    "redux": "4.0.4",
    "redux-devtools-extension": "2.13.8",
    "redux-thunk": "2.3.0",
    "reselect": "^4.0.0",
    "rn-fetch-blob": "0.10.16",
    "styled-components": "4.3.2"
  },
  "devDependencies": {
    "@babel/core": "7.5.5",
    "@babel/plugin-proposal-export-default-from": "7.5.2",
    "@babel/plugin-proposal-export-namespace-from": "7.5.2",
    "@babel/plugin-syntax-dynamic-import": "7.2.0",
    "@babel/runtime": "7.5.5",
    "babel-eslint": "10.0.2",
    "babel-plugin-module-resolver": "3.2.0",
    "babel-plugin-styled-components": "1.10.6",
    "eslint": "^5.16.0",
    "eslint-config-react-app": "^4.0.1",
    "eslint-import-resolver-babel-module": "5.1.0",
    "eslint-plugin-flowtype": "3.13.0",
    "eslint-plugin-import": "2.18.2",
    "eslint-plugin-jsx-a11y": "^6.2.1",
    "eslint-plugin-react": "7.14.3",
    "eslint-plugin-react-hooks": "1.6.1",
    "eslint-plugin-react-native": "3.7.0",
    "jetifier": "^1.6.4",
    "metro-react-native-babel-preset": "0.56.0"
  },
  "xcodeSchemes": {
    "Debug": [
      "Test - Debug",
      "Acc - Debug",
      "Prod - Debug"
    ],
    "Release": [
      "Test - Release",
      "Acc - Release",
      "Prod - Release"
    ],
    "projectDirectory": "ios",
    "settings": {}
  },
  "rnpm": {
    "assets": [
      "./src/app/static/fonts/"
    ]
  }
}

AppDelegate.m应该链接到正确的捆绑软件文件吗?这段代码在其中:


- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

(我也在Github上的React Native问题跟踪器中发布了这个问题/错误。)

enter image description here

已编辑:

我在this Stack Overflow post中找到了解决方案。按照这些步骤,您可以创建一个main.jsbundleassets文件夹并将其添加到您的项目中。

  1. 运行以下命令:react-native bundle --dev false --platform ios --entry-file index.js --bundle-output ios/main.jsbundle --assets-dest ./ios
  2. 通过在项目中拖动main.jsbundleassets目录到Xcode中。

尽管这似乎是一个临时解决方案。.我现在有两个main.jsbundle文件。我可以删除项目文件夹中的一个吗?并且assets文件夹中包含一些节点模块,每次添加新模块并在项目根目录中手动拖动资源时,我是否都有此命令?

此外,当我通过CI / CD(Bitrise)构建它时,在根目录中没有创建main.jsbundle,因为默认情况下.gitignore中会忽略它。因此我的TestFlight构建仍然失败。如何处理呢?

这里到底发生了什么?

enter image description here

2 个答案:

答案 0 :(得分:1)

在发布模式下运行时,其强制性要求应具有脱机的main.js捆绑包。如果没有,这个问题只会出现。它不包含0.60.5版本,即使在您以前的版本中也是如此。因此,要创建脱机捆绑包,您需要执行上述解决方案中的步骤1。从0.60版本开始,执行此步骤时将创建一个名为资产的文件夹。我不确定为什么需要拖动,因为如果自动执行步骤1,则必须在xcode中进行索引。如果这没有发生,则仅在需要时您需要拖动并复制项目。

因此,这不是一个临时解决方案,它是您要使用已完成的所有更改创建捆绑包所需的解决方案。在反应式中这是必不可少的。

注意:请删除js bundles和Assets文件夹,然后使用

重新创建
react-native bundle --entry-file index.js --platform ios --dev false --bundle-output ios/main.jsbundle --assets-dest ios

答案 1 :(得分:1)

解决了问题。似乎我的项目缺少一个用于在“构建阶段> Bundle React Native代码和图像”下自动构建包和资产的shell脚本。当我打开此部分时,Xcode也崩溃了。

我打开文件/ios/Project.xcodeproj/project.pbxproj,搜索了该部分:

/* Begin PBXShellScriptBuildPhase section */
        00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = {
            isa = PBXShellScriptBuildPhase;
            buildActionMask = 2147483647;
            files = (
            );
            inputPaths = (
            );
            name = "Bundle React Native code and images";
            outputPaths = (
            );
            runOnlyForDeploymentPostprocessing = 0;
            shellPath = /bin/sh;
        };

并添加了shell脚本,所以我最终得到了:

/* Begin PBXShellScriptBuildPhase section */
        00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = {
            isa = PBXShellScriptBuildPhase;
            buildActionMask = 2147483647;
            files = (
            );
            inputPaths = (
            );
            name = "Bundle React Native code and images";
            outputPaths = (
            );
            runOnlyForDeploymentPostprocessing = 0;
            shellPath = /bin/sh;
            shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh\n";
        };

希望这可以防止其他人花2天的时间;)