带有gradlew的Jenkins android构建失败:“无法在类路径或引导类路径中找到包java.lang”

时间:2018-10-26 13:00:39

标签: java android jenkins gradle android-sdk-tools

我正在尝试使用Jenkins自动化我的Android应用程序构建,但是gradlew阶段始终会因该错误而失败 :app:compileDebugJavaWithJavacFatal Error: Unable to find package java.lang in classpath or bootclasspath

我正在手动下载并安装Android SDK和Java,因为Jenkins奴隶有时会被清除。

我的Jenkinsfile中用于构建apk的阶段如下:

stage('android sdk setup') {
  steps {
    sh 'wget https://download.java.net/java/jdk8u192/archive/b04/binaries/jdk-8u192-ea-bin-b04-linux-x64-01_aug_2018.tar.gz'
    sh 'tar xvf jdk-8*.tar.gz'
    script {
      JAVA_HOME='jdk1.8.0_192'
    }

    sh 'wget https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip'
    sh 'unzip -o sdk-tools-linux-4333796.zip'
    script {
      sh 'mkdir sdkTools'
      env.ANDROID_HOME = "sdkTools"
      env.PATH = "tools:tools/bin:${env.PATH}"
    }
    // ensures that all platform licences are automatically accepted
    sh 'yes | sdkmanager --licenses --sdk_root=sdkTools'
  }
}

stage('build debug apk') {
  steps {
    sh './android/gradlew assembleDebug -p android/'

  }
}

失败的gradlew阶段的日志(使用4.4级我们):

Running shell script

+ ./android/gradlew assembleDebug -p android/

Starting a Gradle Daemon (subsequent builds will be faster)

Download https://dl.google.com/dl/android/maven2/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-api.pom

Download https://dl.google.com/dl/android/maven2/com/android/tools/build/transform-api/2.0.0-deprecated-use-gradle-api/transform-api-2.0.0-deprecated-use-gradle-api.jar

File /root/.android/repositories.cfg could not be loaded.

Checking the license for package Android SDK Build-Tools 27.0.3 in sdkTools/licenses

License for package Android SDK Build-Tools 27.0.3 accepted.

Preparing "Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)".
"Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)" ready.
Installing Android SDK Build-Tools 27.0.3 in sdkTools/build-tools/27.0.3
"Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)" complete.
"Install Android SDK Build-Tools 27.0.3 (revision: 27.0.3)" finished.
Checking the license for package Android SDK Platform 27 in sdkTools/licenses
License for package Android SDK Platform 27 accepted.
Preparing "Install Android SDK Platform 27 (revision: 3)".
"Install Android SDK Platform 27 (revision: 3)" ready.
Installing Android SDK Platform 27 in sdkTools/platforms/android-27
"Install Android SDK Platform 27 (revision: 3)" complete.
"Install Android SDK Platform 27 (revision: 3)" finished.
Checking the license for package Android SDK Platform-Tools in sdkTools/licenses
License for package Android SDK Platform-Tools accepted.
Preparing "Install Android SDK Platform-Tools (revision: 28.0.1)".
"Install Android SDK Platform-Tools (revision: 28.0.1)" ready.
Installing Android SDK Platform-Tools in sdkTools/platform-tools
"Install Android SDK Platform-Tools (revision: 28.0.1)" complete.
"Install Android SDK Platform-Tools (revision: 28.0.1)" finished.
:app:preBuild UP-TO-DATE
:app:preDebugBuild
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:checkDebugManifest
:app:generateDebugBuildConfig
:app:prepareLintJar
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:bundleDebugJsAndAssets SKIPPED
:app:generateDebugResValues
:app:generateDebugResources
:app:mergeDebugResources
:app:copyDebugIconFonts
:app:mainApkListPersistenceDebug
:app:createDebugCompatibleScreenManifests
:app:processDebugManifest
:app:splitsDiscoveryTaskDebug
:app:processDebugResources
:app:generateDebugSources
:app:javaPreCompileDebug
:app:compileDebugJavaWithJavacFatal Error: Unable to find package java.lang in classpath or bootclasspath

FAILED



FAILURE: Build failed with an exception.



* What went wrong:

Execution failed for task ':app:compileDebugJavaWithJavac'.

> Compilation failed; see the compiler error output for details.



* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.



* Get more help at https://help.gradle.org



BUILD FAILED in 39s

19 actionable tasks: 19 executed

script returned exit code 1

此外,当使用--info参数运行gradlew时,将输出与该步骤有关的以下内容:     :app:compileDebugJavaWithJavac-不是增量的(例如,输出已更改,之前没有执行等)。

file or directory '/root/workspace/aeroview-in-field_PR-8-MSJGTZ4DUFADZRNZTDSELHAK7UOP377PTK64G7JQLSMR4VWKVA6Q/android/app/src/debug/java', not found

Compiling with JDK Java compiler API.

Fatal Error: Unable to find package java.lang in classpath or bootclasspath

:app:compileDebugJavaWithJavac FAILED

:app:compileDebugJavaWithJavac (Thread[Daemon worker,5,main]) completed. Took 1.355 secs.

任何帮助将不胜感激!自动构建apk将是一个巨大的优势,并且可以节省大量时间。

0 个答案:

没有答案