React Native 0.72升级后CircleCI Android构建失败求助
React Native 0.72升级后CircleCI构建失败解决方案
问题背景
将React Native升级至0.72版本后,原本通过CircleCI构建Android APK并分发到AppCenter的流程持续失败,错误提示Node.js版本不符合要求。
原CircleCI配置(config.yml)
version: 2.1 jobs: node: working_directory: ~/driver-app docker: - image: circleci/node:lts steps: - checkout - restore_cache: key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }} - restore_cache: key: node-v1-{{ checksum "package.json" }}-{{ arch }} - run: yarn install --ignore-engines - save_cache: paths: - node_modules key: node-v1-{{ checksum "package.json" }}-{{ arch }} - run: name: Decrypt env file command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -pass pass:$ENCRYPT_SECRET_KEY -d -p -in encrypted-env-staging -out .env - persist_to_workspace: root: ~/driver-app paths: - node_modules android-build: working_directory: ~/driver-app/android docker: - image: circleci/android:api-30-node environment: APP_VERSION: "2.3.8" steps: - checkout: path: ~/driver-app - attach_workspace: at: ~/driver-app - restore_cache: key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} - save_cache: paths: - .gradle key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} - run: name: Decrypt env file command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -pass pass:$ENCRYPT_SECRET_KEY -d -p -in ~/driver-app/encrypted-env-staging -out ~/driver-app/.env - run: name: Decrypt google-services.json command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt -pass pass:$ENCRYPT_SECRET_KEY -d -p -in app/encrypted-google-services -out app/google-services.json - run: name: Decrypt production keystore command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt -d -p -in app/encrypted-tkyr-keystore -out app/tkyrkey.keystore -pass pass:$ENCRYPT_SECRET_KEY - run: name: Change the .gradlew permission command: chmod +x ./gradlew - run: name: Assemble Release APK command: ./gradlew assembleRelease -PMYAPP_UPLOAD_STORE_FILE=tkyrkey.keystore -PMYAPP_UPLOAD_KEY_ALIAS=$MYAPP_UPLOAD_KEY_ALIAS -PMYAPP_UPLOAD_STORE_PASSWORD=$MYAPP_UPLOAD_STORE_PASSWORD -PMYAPP_UPLOAD_KEY_PASSWORD=$MYAPP_UPLOAD_KEY_PASSWORD - run: name: Rename the APK command: mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/test_driver_app_v$APP_VERSION.apk - run: name: Install appcenter cli command: sudo npm install appcenter-cli -g - run: name: Distribute APK to testers command: appcenter distribute release --debug --app hhmem-tkyr.net/TkyrCaptain --file app/build/outputs/apk/release/test_driver_app_v$APP_VERSION.apk --group "App Testers" --token $APPCENTER_CLI_TOKEN - run: name: Remove secrets command: rm -rf app/google-services.json ~/driver-app/.env.staging app/tkyrkey.keystore workflows: build-android-workflow: jobs: - node: filters: branches: only: - test - android-build: requires: - node filters: branches: only: - test
错误信息
FAILURE: Build failed with an exception.
- 位置:脚本
/home/circleci/driver-app/node_modules/@react-native-community/cli-platform-android/native_modules.gradle第389行 - 错误原因:评估脚本时出现问题
- 核心提示:
React Native需要Node.js >= 16。当前版本为v14.17.5,请升级Node.js至支持版本后重试。
解决方案
问题根源是两个CircleCI job使用的Docker镜像自带Node.js版本低于RN 0.72要求的16.x,需针对性修改:
1. 更新node job的Node版本
将circleci/node:lts替换为明确的Node 18版本(RN 0.72官方推荐Node 18),同时移除--ignore-engines参数,避免依赖兼容性问题:
node: working_directory: ~/driver-app docker: - image: circleci/node:18 steps: # ... 其他步骤保持不变 - run: yarn install # 移除--ignore-engines
2. 更新android-build job的镜像
原circleci/android:api-30-node自带Node 14,需替换为包含Node 18的Android镜像,比如circleci/android:api-33-node18:
android-build: working_directory: ~/driver-app/android docker: - image: circleci/android:api-33-node18 # ... 其他步骤保持不变
修改后的完整配置示例
version: 2.1 jobs: node: working_directory: ~/driver-app docker: - image: circleci/node:18 steps: - checkout - restore_cache: key: yarn-v1-{{ checksum "yarn.lock" }}-{{ arch }} - restore_cache: key: node-v1-{{ checksum "package.json" }}-{{ arch }} - run: yarn install - save_cache: paths: - node_modules key: node-v1-{{ checksum "package.json" }}-{{ arch }} - run: name: Decrypt env file command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -pass pass:$ENCRYPT_SECRET_KEY -d -p -in encrypted-env-staging -out .env - persist_to_workspace: root: ~/driver-app paths: - node_modules android-build: working_directory: ~/driver-app/android docker: - image: circleci/android:api-33-node18 environment: APP_VERSION: "2.3.8" steps: - checkout: path: ~/driver-app - attach_workspace: at: ~/driver-app - restore_cache: key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} - save_cache: paths: - .gradle key: jars-{{ checksum "build.gradle" }}-{{ checksum "app/build.gradle" }} - run: name: Decrypt env file command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -pass pass:$ENCRYPT_SECRET_KEY -d -p -in ~/driver-app/encrypted-env-staging -out ~/driver-app/.env - run: name: Decrypt google-services.json command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt -pass pass:$ENCRYPT_SECRET_KEY -d -p -in app/encrypted-google-services -out app/google-services.json - run: name: Decrypt production keystore command: openssl enc -aes-256-cbc -md sha512 -pbkdf2 -iter 100000 -salt -d -p -in app/encrypted-tkyr-keystore -out app/tkyrkey.keystore -pass pass:$ENCRYPT_SECRET_KEY - run: name: Change the .gradlew permission command: chmod +x ./gradlew - run: name: Assemble Release APK command: ./gradlew assembleRelease -PMYAPP_UPLOAD_STORE_FILE=tkyrkey.keystore -PMYAPP_UPLOAD_KEY_ALIAS=$MYAPP_UPLOAD_KEY_ALIAS -PMYAPP_UPLOAD_STORE_PASSWORD=$MYAPP_UPLOAD_STORE_PASSWORD -PMYAPP_UPLOAD_KEY_PASSWORD=$MYAPP_UPLOAD_KEY_PASSWORD - run: name: Rename the APK command: mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/test_driver_app_v$APP_VERSION.apk - run: name: Install appcenter cli command: sudo npm install appcenter-cli -g - run: name: Distribute APK to testers command: appcenter distribute release --debug --app hhmem-tkyr.net/TkyrCaptain --file app/build/outputs/apk/release/test_driver_app_v$APP_VERSION.apk --group "App Testers" --token $APPCENTER_CLI_TOKEN - run: name: Remove secrets command: rm -rf app/google-services.json ~/driver-app/.env.staging app/tkyrkey.keystore workflows: build-android-workflow: jobs: - node: filters: branches: only: - test - android-build: requires: - node filters: branches: only: - test
内容的提问来源于stack exchange,提问作者Hamza Hmem
相关产品推荐
相关产品推荐

