【问题标题】:Travis CI build fails on react-native androidTravis CI 构建在 react-native android 上失败
【发布时间】:2019-12-09 00:59:44
【问题描述】:

我正在尝试使用以下命令使用 travis ci 构建我的 react-native 项目:

script: 
    - npm install -g npx && cd android && sudo chmod +x gradlew && sudo ./gradlew assembleRelease#3

但是,我的构建失败并出现以下错误: 无法运行程序“npx”:错误=2,没有这样的文件或目录

我的完整配置如下:

language: android
before_install: #1.1
- nvm install 10
- node --version
install: #1.2
- npm install
android: #1.3
  components:
  - build-tools-23.0.1
  - android-23
  - extra-android-m2repository
  - extra-google-google_play_services
  - extra-google-m2repository
  - addon-google_apis-google-16
script: 
    - npm install -g npx && cd android && sudo chmod +x gradlew && sudo ./gradlew assembleRelease#3
deploy: # mostly generated by `> travis deploy releases`
  skip_cleanup: true

即使我已使用 npm 全局安装,构建文件似乎也无法找到 npx。在错误所在的native_modules.gradle文件中,错误行如下:

def npx = Os.isFamily(Os.FAMILY_WINDOWS) ? "npx.cmd" : "npx"

这是发生错误的调用堆栈:

Welcome to Gradle 5.5!
1776
1777
Here are the highlights of this release:
1778
 - Kickstart Gradle plugin development with gradle init
1779
 - Distribute organization-wide Gradle properties in custom Gradle distributions
1780
 - Transform dependency artifacts on resolution
1781
1782
For more details see https://docs.gradle.org/5.5/release-notes.html
1783
1784
Starting a Gradle Daemon (subsequent builds will be faster)
1785
1786
1787
> Starting Daemon<-------------> 0% INITIALIZING [21ms]<-------------> 0% INITIALIZING [121ms]> Evaluating settings<-------------> 0% INITIALIZING [221ms]<-------------> 0% INITIALIZING [321ms]<-------------> 0% INITIALIZING [421ms]<-------------> 0% INITIALIZING [521ms]<-------------> 0% INITIALIZING [621ms]<-------------> 0% INITIALIZING [721ms]<-------------> 0% INITIALIZING [822ms]> Evaluating settings > Compiling /home/travis/build/daniel-sudz/bbox-mobile/an<-------------> 0% INITIALIZING [921ms]<-------------> 0% INITIALIZING [1s]> Evaluating settings> Evaluating settings > Compiling /home/travis/build/daniel-sudz/bbox-mobile/no> Evaluating settingsmand from 'null' directory failed.
1788
1789
FAILURE: Build failed with an exception.
1790
1791
* Where:
1792
Script '/home/travis/build/daniel-sudz/bbox-mobile/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 154
1793
1794
* What went wrong:
1795
A problem occurred evaluating script.
1796
> Cannot run program "npx": error=2, No such file or directory

注意:构建发生在 ubuntu 上

关于解决方案的任何想法?

【问题讨论】:

    标签: javascript android react-native npm travis-ci


    【解决方案1】:

    我通过添加 openjdk8 并设置我的 android sdk 路径解决了我的问题。对我来说完整的工作配置:

    os:
    - linux
    before_install:
    - curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
    - sudo apt-get install -y nodejs
    - npm --version
    - node --version
    - npx --version
    - export ANDROID_HOME=/usr/local/android-sdk
    - export PATH=$PATH:$ANDROID_HOME/emulator
    - export PATH=$PATH:$ANDROID_HOME/tools
    - export PATH=$PATH:$ANDROID_HOME/tools/bin
    - export PATH=$PATH:$ANDROID_HOME/platform-tools
    - git clone https://github.com/facebook/watchman.git -b v4.9.0 --depth 1
    - cd watchman
    - "./autogen.sh"
    - "./configure"
    - make
    - sudo make install
    - cd ..
    install:
    - npm install
    language: android
    jdk:
    - oraclejdk8
    dist: trusty
    android:
      components:
      - tools
      - platform-tools
      - build-tools-28.0.3
      - android-28
      - extra-google-google_play_services
      - extra-google-m2repository
      - extra-android-m2repository
    script:
    - cd android && sudo chmod +x gradlew && sudo ./gradlew clean && sudo ./gradlew assembleRelease
    - cd ..
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多