AWS Amplify 客户端始终无法使用 Expo 进行构建

问题描述 投票:0回答:2

按照 AWS Amplify Expo 文档 执行以下步骤,使用 EAS 构建进行构建失败并显示

[RUN_FASTLANE] › Executing baseline » Bundle React Native code and images
[RUN_FASTLANE]     the transform cache was reset.
[RUN_FASTLANE] › Generating debug baseline » baseline.app.dSYM
[RUN_FASTLANE] ▸ ** ARCHIVE FAILED **
[RUN_FASTLANE] ▸ The following build commands failed:
[RUN_FASTLANE] ▸    PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/Rax/Library/Developer/Xcode/DerivedData/baseline-hhrsifdg
[RUN_FASTLANE] ▸ (1 failure)
[RUN_FASTLANE] ** ARCHIVE FAILED **
[RUN_FASTLANE] 
[RUN_FASTLANE] 
[RUN_FASTLANE] The following build commands failed:
[RUN_FASTLANE]  PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/Rax/Library/Developer/Xcode/DerivedData/baseline-xxxxxxx
[RUN_FASTLANE] (1 failure)
[RUN_FASTLANE] Exit status: 65
[RUN_FASTLANE] 
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] |           Build environment           |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] | xcode_path  | /Applications/Xcode.app |
[RUN_FASTLANE] | gym_version | 2.205.2                 |
[RUN_FASTLANE] | sdk         | iPhoneOS15.2.sdk        |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] Looks like fastlane ran into a build/archive error with your project
[RUN_FASTLANE] It's hard to tell what's causing the error, so we wrote some guides on how
[RUN_FASTLANE] to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[RUN_FASTLANE] Before submitting an issue on GitHub, please follow the guide above and make
[RUN_FASTLANE] sure your project is set up correctly.
[RUN_FASTLANE] fastlane uses `xcodebuild` commands to generate your binary, you can see the
[RUN_FASTLANE] the full commands printed out in yellow in the above log.
[RUN_FASTLANE] Make sure to inspect the output above, as usually you'll find more error information there
[RUN_FASTLANE] 
[RUN_FASTLANE] [!] Error building the application - see the log above
[RUN_FASTLANE] Error: Fastlane build failed with unknown error. Please refer to the "Run fastlane" and "Xcode Logs" phases.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when lo
[CLEAN_UP_CREDENTIALS] Destroying keychain - XXXXXXXXXX.keychain
[CLEAN_UP_CREDENTIALS] Removing provisioning profile

Build failed
Fastlane build failed with unknown error. Please refer to the "Run fastlane" and "Xcode Logs" phases.
Fastlane errors in most cases are not printed at the end of the output, so you may not find any useful information in the last lines of output when lo
    Error: npx exited with non-zero code: 1


遵循的步骤:

  1. 使用
    expo init
    创建一个新项目并使用基本导航关闭 TypeScript。
  2. 使用以下命令安装 AWS Amplify 依赖项
    expo install aws-amplify aws-amplify-react-native @react-native-community/netinfo  @react-native-async-storage/async-storage @react-native-picker/picker
    
  3. 使用
    amplify pull
    拉取我的 AWS Amplify 项目,并进行以下选择:
    ? Select the authentication method you want to use: AWS profile
    ? Please choose the profile you want to use amplify-cli
    ? Which app are you working on? XXXXXXXX
    Backend environment 'dev' found. Initializing...
    ? Choose your default editor: IntelliJ IDEA
    ? Choose the type of app that you're building javascript
    Please tell us about your project
    ? What javascript framework are you using react-native
    ? Source Directory Path:  /
    ? Distribution Directory Path: /
    ? Build Command: eas build --profile development --platform ios --local
    ? Start Command: expo start --dev-client
    
  4. 将指定的 AWS Amplify 样板添加到
    App.tsx
    import { Amplify } from 'aws-amplify'
    import awsconfig from 'aws-exports'
    
    Amplify.configure(awsconfig)
    
  5. 构建
    eas build --profile development --platform ios --local
    

{
  "name": "amptest",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest --watchAll"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^13.0.0",
    "@react-native-async-storage/async-storage": "^1.17.4",
    "@react-native-community/netinfo": "8.2.0",
    "@react-native-picker/picker": "2.4.0",
    "@react-navigation/bottom-tabs": "^6.0.5",
    "@react-navigation/native": "^6.0.2",
    "@react-navigation/native-stack": "^6.1.0",
    "aws-amplify": "^4.3.22",
    "aws-amplify-react-native": "^6.0.4",
    "expo": "~45.0.0",
    "expo-asset": "~8.5.0",
    "expo-constants": "~13.1.1",
    "expo-dev-client": "~0.9.5",
    "expo-font": "~10.1.0",
    "expo-linking": "~3.1.0",
    "expo-splash-screen": "~0.15.1",
    "expo-status-bar": "~1.3.0",
    "expo-system-ui": "~1.2.0",
    "expo-web-browser": "~10.2.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-safe-area-context": "4.2.4",
    "react-native-screens": "~3.11.1",
    "react-native-web": "0.17.7"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.66.13",
    "jest": "^26.6.3",
    "jest-expo": "~45.0.0",
    "react-test-renderer": "17.0.2",
    "typescript": "~4.3.5"
  },
  "private": true
}

amazon-web-services react-native expo aws-amplify fastlane
2个回答
0
投票

我已经找到了问题的原因,只有通过更改 AWS Amplify 的工作方式才能完全解决该问题。

问题

AWS Amplify 在由

aws-exports.js
界定的部分中将
.gitignore
添加到
#amplify-do-not-edit-begin/end
。这是有一定道理的,因为该文件包含 API 密钥。但无论合理与否,都会产生问题。 AWS Amplify 开箱即用,无法与 
eas build
或其他使用 Git 识别项目文件的工具配合使用。

短期修复

手动禁用忽略(例如使用

!aws-exports.js
)使
aws-exports.js
可用于
eas build
。 (使用
.easignore
也是一种可能性,但 有缺点 并且可能有点过分了。)

长期解决方案

显然,上述内容不是任何现实世界项目的长期解决方案,因为不管文档怎么说

aws-exports.js
包含敏感信息,确实应该被Git忽略。相反,AWS Amplify 需要能够使用以下方法:

  • 不要 git-ignore
    aws-exports.js
  • aws-exports.js
    中的敏感信息值替换为环境变量,这些变量 (i) 由 AWS 在后端自动管理(例如,用于托管构建),并且 (ii) 在其他环境(例如 CI、本地)中以常规方式设置由用户构建等)。

按原样,感觉 Amplify 是为 Web 托管应用程序设计的(例如

aws-exports.js
为它们重新生成),但没有考虑到移动应用程序的场景。


0
投票

短期修复对我有用。 非常感谢!

© www.soinside.com 2019 - 2024. All rights reserved.