CentOS7最小化环境Jenkins构建Android APK遇Ninja启动失败求助
Hey there! Let's tackle your Android build issues on CentOS 7 Jenkins step by step—since you're new to Android dev, we'll keep this straightforward and actionable.
1. Fix the "No such file or directory" for Ninja (Direct Build Failure Cause)
Even though you installed Ninja, it's likely not in the PATH that Jenkins uses (system PATH and Jenkins runtime PATH can differ). Here's how to fix it:
- First, find where Ninja is installed on your CentOS machine. Run this in a terminal:
You'll get a path likewhich ninja/usr/local/bin/ninjaor/opt/ninja/ninja. - Option 1: Add Ninja to Jenkins' global PATH
Go to Jenkins → Manage Jenkins → Configure System → Global properties → Check "Environment variables" → Add a variable namedPATHwith value$PATH:/your/ninja/path(replace with the path fromwhich ninja). - Option 2: Hardcode Ninja path in Gradle
If you don't want to mess with Jenkins global config, add this to your app module'sbuild.gradleunder theandroidblock:externalNativeBuild { cmake { path "CMakeLists.txt" // Make sure this path matches your project's CMake file arguments "-DCMAKE_MAKE_PROGRAM=/your/ninja/path/ninja" } }
2. Resolve the ANDROID_NDK_DEPRECATED Warning
The warning tells you to replace the ANDROID_NDK_HOME environment variable with a direct version spec in Gradle. Do this in your app's build.gradle:
android { // Replace with your exact NDK r21 version (check SDK Manager for the full version string) ndkVersion "21.4.7075529" // Rest of your android config... }
This makes Gradle use the exact NDK version you specify, no more relying on environment variables.
3. Address the 64-bit Library Requirement (Google Play Warning)
This is a warning, not an immediate build failure, but you'll need to fix it if you plan to publish to Google Play:
- Update your app's
build.gradleto include 64-bit ABIs:android { defaultConfig { externalNativeBuild { cmake { abiFilters "x86", "x86_64", "armeabi-v7a", "arm64-v8a" } } } } - Double-check your
CMakeLists.txtdoesn't have any restrictions that block 64-bit targets (look for lines likeSET(CMAKE_C_FLAGS "-m32")and remove them if present).
4. Fix the "Cannot execute CMake from NDK" Issue
Once you set ndkVersion in Gradle, this should resolve itself—Gradle will automatically locate the CMake bundled with your specified NDK version, so you won't get the "skipped" error anymore.
After applying these changes, try rerunning your Jenkins build. If you still hit issues, add --info to your Gradle build command in Jenkins to get more detailed logs!
内容的提问来源于stack exchange,提问作者Marko Barbančić

