android自动化静态代码分析,Jenkins+Gradle+checkstyle对Android工程源码进行静态代码分析...

转载请注意出处:http://blog.csdn.net/hwhua1986/article/details/49278773

环境说明

Gradle 2.6.

OS:windows server 2008

Jenkins 1.620

checkstyle 6.11.6

前提:

Jenkins需要提前安装好Checkstyle Plug-in插件

一、Jenkins配置如下:

1、  新建job

3e8655b1cfcdf508528d9d0a73c44a99.png

2、  配置svn

61d6c604513f2cf0c5f23bd91892dd92.png

3、  配置构建操作

5d3769de439d04abd2231b10fb1f8ae6.png

备注:

Tasks指的是build.gradle里面的task名称

配置info参数是用来看调试日志,也可以配置debug级别。主要用来查看构建失败的原因。

4、  配置分析报告

98de5daedaad3d680587fd6190d84f5f.png

二、gradle.build的配置如下

1、添加checkstyle的依赖

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath 'com.android.tools.build:gradle:1.0.0+'

//classpath  'io.fabric.tools:gradle:1.+'

//classpath  'com.google.code.findbugs:findbugs:3.0.1'

//classpath  'com.puppycrawl.tools:checkstyle:6.11.2'

//classpath  'net.sourceforge.pmd:pmd:5.4.0'

}

}

备注:版本包可以通过中央仓库(http://mvnrepository.com/artifact/)查看,如图

fdb59a8d41ad7b0a95cc0b87934eea93.png

版本列表:

7786041767c7c6f81f860560baaf2a4d.png

2、增加checkstyle的task

apply plugin: "checkstyle"

repositories {

mavenCentral()

}

task checkstyle(type: Checkstyle) {

//toolVersion = "2.0.1"

ignoreFailures = true

//config= files("$rootProject.projectDir/config/checkstyle/checkstyle.xml")

source= fileTree('build/intermediates/classes/debug/com/sn/')

classpath= files()

reports{

xml {

destination "build/checkstyle-result.xml"

}

}

}

备注:其中检查规则文件checkstyle.xml需要创建,步骤如下

5401007e46b231777eec2fd346a8f55c.png

Xml内容代码:

/p>

"-//Puppy Crawl//DTD Check Configuration 1.3//EN"

"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

三、构建结果查看

6a47c6b5afc04f625003e4694d5b5c90.png

13b8993528a25f744518a55288efe8ab.png

四、build.gradle的所有代码如下

buildscript {

repositories {

mavenCentral()

}

dependencies {

classpath 'com.android.tools.build:gradle:1.0.0+'

//classpath 'io.fabric.tools:gradle:1.+'

//classpath 'com.google.code.findbugs:findbugs:3.0.1'

//classpath 'com.puppycrawl.tools:checkstyle:6.11.2'

//classpath 'net.sourceforge.pmd:pmd:5.4.0'

}

}

apply plugin: 'android'

dependencies {

compile fileTree(dir: 'libs', include: '*.jar')

}

android {

compileSdkVersion 20

buildToolsVersion "20.0.0"

//忽略编码错误

lintOptions {

abortOnError false

}

//设置版本号

defaultConfig {

versionCode 1

versionName "1.0"

minSdkVersion 8

targetSdkVersion 18

}

//引用so包

sourceSets{

main{

jniLibs.srcDir(['libs'])

jniLibs.srcDir(['obj'])

}

}

//设置编译编码

tasks.withType(JavaCompile) {

options.encoding = 'UTF-8'

}

//autograph

signingConfigs{

//keystore info

myConfig {

storeFile file("bgkey")

storePassword "[email protected]"

keyAlias "com.sn.bloodglucose"

keyPassword "[email protected]"

}

}

//混淆

buildTypes{

release{

signingConfig signingConfigs.myConfig

minifyEnabled false

}

}

sourceSets {

main {

manifest.srcFile 'AndroidManifest.xml'

java.srcDirs = ['src']

resources.srcDirs = ['src']

aidl.srcDirs = ['src']

renderscript.srcDirs = ['src']

res.srcDirs = ['res']

assets.srcDirs = ['assets']

}

// Move the tests to tests/java, tests/res, etc...

instrumentTest.setRoot('tests')

// Move the build types to build-types/

// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...

// This moves them out of them default location under src//... which would

// conflict with src/ being used by the main source set.

// Adding new build types or product flavors should be accompanied

// by a similar customization.

debug.setRoot('build-types/debug')

release.setRoot('build-types/release')

}

}

apply plugin: "findbugs"

repositories {

mavenCentral()

}

task findbugs(type: FindBugs) {

//toolVersion = "2.0.1"

ignoreFailures = true

effort = "max"

reportLevel = "low"

classes = files("$project.buildDir/intermediates/classes")

source = fileTree('build/intermediates/classes/debug/com/sn/')

classpath = files()

reports {

xml {

destination "build/findbugs.xml"

}

}

}

apply plugin: "checkstyle"

repositories {

mavenCentral()

}

task checkstyle(type: Checkstyle) {

ignoreFailures = true

//config = files("build/config/checkstyle/checkstyle.xml")

source = fileTree('build/intermediates/classes/debug/com/sn/')

classpath = files()

reports {

xml {

destination "build/checkstyle-result.xml"

}

}

}

apply plugin: "pmd"

repositories {

mavenCentral()

}

task pmd(type: Pmd) {

ignoreFailures = true

source = fileTree('src/com/sn/')

//ruleSetConfig = resources.file("${project.rootDir}/config/pmd/PmdRuleSets.xml")

//ruleSetFiles = files("config/pmd/PmdRuleSets.xml")

ruleSetFiles = files("${project.rootDir}/config/pmd/PmdRuleSets.xml")

ruleSets = ["java-android"]

reports {

xml {

destination "build/pmd.xml"

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值