android 使用Jenkins打包遇到的问题

使用Jenkins持续集成时运行遇到的问题总结

问题一

java.io.IOException: Cannot run program "gradle" (in directory "/Users/Shared/Jenkins/Home/jobs/test/workspace"): error=2, No such file or directory

    at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)

    at hudson.Proc$LocalProc.(Proc.java:244)

    at hudson.Proc$LocalProc.(Proc.java:216)

    at hudson.Launcher$LocalLauncher.launch(Launcher.java:707)

    at hudson.Launcher$ProcStarter.start(Launcher.java:338)

    at hudson.Launcher$ProcStarter.join(Launcher.java:345)

    at hudson.plugins.gradle.Gradle.performTask(Gradle.java:201)

    at hudson.plugins.gradle.Gradle.perform(Gradle.java:97)

    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)

    at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:695)

    at hudson.model.Build$RunnerImpl.build(Build.java:178)

    at hudson.model.Build$RunnerImpl.doRun(Build.java:139)

    at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:465)

    at hudson.model.Run.run(Run.java:1404)

    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)

    at hudson.model.ResourceController.execute(ResourceController.java:88)

    at hudson.model.Executor.run(Executor.java:238)

Caused by: java.io.IOException: error=2, No such file or directory

    at java.lang.UNIXProcess.forkAndExec(Native Method)

    at java.lang.UNIXProcess.(UNIXProcess.java:53)

    at java.lang.ProcessImpl.start(ProcessImpl.java:91)

    at java.lang.ProcessBuilder.start(ProcessBuilder.java:453)

    ... 16 more

Build step 'Invoke Gradle script' changed build result to FAILURE

Build step 'Invoke Gradle script' marked build as failure

Finished: FAILURE

解决:

这个gradle的配置不对。进入项目的详情页,点击设置,找到“构建”那里的Invoke Gradle script,设置为:Use Gradle Wrapper,然后task里输入build。最后保存。

问题二

’Users/wys/Library/Android/sdk’ not exist


在这里插入图片描述

Google 了一下原因:是由于文件权限的问题
https://stackoverflow.com/questions/39568402/jenkins-giving-the-sdk-directory-doesnt-exist#comment66465785_39568402

设置的路径是Android Studio sdk的默认路径 Users/***/Library/Android/sdk,Library目录是系统的目录,没有读取Library 目录的权限,所以导致失败。

解决办法

  • 添加权限:
    通过终端进入Library目录

    执行 chmod -R 777

    或者 sudo chmod -R 777

  • 把sdk换个目录存放 。

问题三:

* What went wrong:
Execution failed for task ':app:lint'.
> Lint found errors in the project; aborting build.

  Fix the issues identified by lint, or add the following to your build script to proceed with errors:
  ...
  android {
      lintOptions {
          abortOnError false
      }
  }
  ...
 
  Errors found:
 
  /Users/Shared/Jenkins/Home/workspace/test/app/build.gradle: Error: All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes). Found versions 28.0.0-alpha1, 28.0.0. Examples include com.android.support:support-media-compat:28.0.0-alpha1 and com.android.support:animated-vector-drawable:28.0.0 [GradleCompatible]  

从log 理可以看出,是由于引入的库版本不一致造成的,解决方法可以是:

添加:


 android {
      lintOptions {
          abortOnError false
      }
  }
 

或者修改一致版本

问题四

这个问题是自己忘了配置打包环境。。。


Build step 'Invoke Gradle script' changed build result to SUCCESS
[WanAndroid] $ echo '"resolving effective environment"'
ERROR: Build step failed with exception
java.lang.NullPointerException
    at org.jenkinsci.plugins.androidsigning.SigningComponents.fromCredentials(SigningComponents.java:22)
    at org.jenkinsci.plugins.androidsigning.SignApksBuilder.perform(SignApksBuilder.java:294)
    at hudson.tasks.BuildStepCompatibilityLayer.perform(BuildStepCompatibilityLayer.java:81)
    at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
    at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:744)
    at hudson.model.Build$BuildExecution.build(Build.java:206)
    at hudson.model.Build$BuildExecution.doRun(Build.java:163)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:504)
    at hudson.model.Run.execute(Run.java:1810)
    at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
    at hudson.model.ResourceController.execute(ResourceController.java:97)
    at hudson.model.Executor.run(Executor.java:429)
Build step 'Sign Android APKs' marked build as failure
Finished: FAILURE

在android gradle下:


signingConfigs {
    release {
        keyAlias '*****'
        keyPassword '****'
        storeFile file('****')
        storePassword '***'
    }
}

问题五 配置打包后文件

在项目配置中

Jenkins 构建后操作 -- Archive the artifacts


在这里插入图片描述

在这里插入图片描述

构建完成后的控制台会显示出构建成功的apk文件


在这里插入图片描述

希望能够帮到遇到相同问题的小伙伴~~~

你可能感兴趣的:(android 使用Jenkins打包遇到的问题)