我正在尝试使用以下命令使用travis ci构建我的react-native项目:
script:
- npm install -g npx && cd android && sudo chmod +x gradlew && sudo ./gradlew assembleRelease#3
但是,我的构建因以下错误而失败: 无法运行程序“ npx”:error = 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上
对解决方案有何想法?
答案 0 :(得分:0)
我已经通过添加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 ..