Jenkins+gradle+android+sonarqube

Source: Internet
Author: User

First, the environment

1. ubuntu14.04(64位)2. jdk 1.73. ant 1.94. jenkins 1.6065. tomcat 7.0.56. android sdk7. gradle8. nexus9. sonarqube

Second, installation

1. JDK environment variable VIM ~/.BASHRC export java_home=/usr/local/lib/jvm/jdk1.7.0_60 export jre_home= $JAVA _HOME/JRE Export Classpath=.:${java_home}/lib:${jre_home}/lib Export path= $JAVA _home/bin: $JRE _home/bin: $PATH 2. Gradle environment variable http://gradle.org/Download the latest package vim ~/.BASHRC export gradle_home=/usr/local/lib/gradle2.2 export path= $GRA Dle_home/bin: $PATH 3. Jenkins environment variable http://jenkins-ci.org/download stable version vim ~/.BASHRC export Jenkins_home=/home/roy/jenkins_home export path= $JENKINS _home: $PATH 4. Android SDK environment variable vim ~/.BASHRC export ANDROID_HOME=/HOME/ROY/SOFT/ANDROID-SDK export path= $ANDROID _home/tools: $AN Droid_home/platform-tools: $PATH 5. Jenkins plug-in installs Gradle plugin sonar plugin6. Because the Android SDK files are compiled in a 32-bit library, it is not possible to find the corresponding library on the 64 operating system, you need to install the sudo apt-get install lib32stdc++6 sudo apt-get install lib32z 1 lib32z1-dev7. Nexus installation Configuration http://www.sonatype.org Download the latest package 1. Unzip 2. Enter the bin directory to execute the./nexus Start Command 3. The Http://localhost:8081/nexus interface Access user name and password is admin/admin1238. SonarqUbe Install http://www.sonarqube.org Download the latest package 1. Unzip 2. Installing the MySQL database sudo apt-get install mysql-server creating a sonar database and user creation database sonar CHARACTER SET UTF8 COLLATE        Utf8_general_ci;        CREATE USER ' sonar ' identified by ' sonar ';        GRANT all on sonar.* to ' sonar ' @ '% ' of ' identified by ' sonar ';    GRANT all on sonar.* to ' sonar ' @ ' localhost ' identified by ' sonar '; 2. Edit the configuration file conf/sonar.properties Modify the configuration of the MySQL database and the configuration of the Web port and URL Sonar.jdbc.username=sonar sonar.jdbc.passwo Rd=sonar sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useunicode=true&characterencoding=utf8&        Rewritebatchedstatements=true&useconfigs=maxperformance sonar.web.host=192.168.33.7 sonar.web.context= sonar.web.port=9000 3. Sonar-runner Configuration Conf/sonar-runner.properties Sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useunicode=true &characterencoding=utf8 Sonar.jdbc.username=sonar Sonar.jdbc.password=sonar Sonar.logIn=admin Sonar.password=jstinno 

Third, Jenkins Configuration

Iv. Engineering Configuration

    buildscript{

repositories{

mavenCentral();

}

dependencies{

classpath ‘com.android.tools.build:gradle:0.14+‘

}

Tasks.withtype (javacompile) {

options.encoding = ‘UTF-8‘

}
}

Apply plugin: ' Android '

dependencies{
Compile Filetree (dir: ' Libs ', include: "*.jar")
}

android{

Applicationvariants.all {variant-

variant.outputs.each { output ->  if(output.outputFile.name.indexOf(‘-debug.apk‘) > -1){    output.outputFile = new File(      output.outputFile.parent,      output.outputFile.name.replace(".apk", "mirror.apk"))    }  }

}

signingconfigs{

myConfig{  storeFile file("/home/roy/jenkins_home/jobs/ApkKeyStore")  storePassword "android"  keyAlias "brilliance"  keyPassword "android"}

}

buildtypes{

release{  signingConfig signingConfigs.myConfig}

}

Compilesdkversion 22
Buildtoolsversion "22.0.1"
Enforceuniquepackagename=false

lintoptions{

abortOnError 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‘]}

}

lintoptions{

abortOnError false

}
}

V. Examples of build.xml

Six, APK automatically installed in the phone

1. 开启手机开发者模式(通过单击设置->关于手机->版本号, 连续单击四次)2. 在开发者选项中,开启USB调试和USB调试授权问题处理:    

List of devices attached
???????????? No permissions
Because the ADB server needs to be started with root privileges
Under the Android-sdk/platform-tools directory, execute the

       $ ./adb kill-server       $ sudo ./adb start-server       在手机上选择Always allow from this computer?       adb devices可以看到了

installation command Gradle installrelease (Gradle IR)

git clone [email protected]:jstinno/apps/cloudfile
git clone [email protected]:jstinno/apps/cloudclient
git clone [email protected]:jstinno/apps/commonupgrade

Gradle androiddependencies Checking Project dependencies
Gradle clean uploadarchives packaged and uploaded to Maven warehouse

    buildscript{

repositories{

mavenCentral();

}

dependencies{

classpath ‘com.android.tools.build:gradle:0.14+‘

}

Tasks.withtype (javacompile) {

options.encoding = ‘UTF-8‘

}
}

Apply plugin: ' Android-library '
Apply plugin: ' maven '

android{

signingconfigs{

myConfig{  storeFile file("/home/roy/jenkins_home/jobs/ApkKeyStore")  storePassword "android"  keyAlias "brilliance"  keyPassword "android"}

}

buildtypes{

release{  signingConfig signingConfigs.myConfig}

}

Compilesdkversion 22
Buildtoolsversion "22.0.1"

sourcesets{

main{  manifest.srcFile ‘AndroidManifest.xml‘  java.srcDirs = [‘src‘]  resources.srcDirs = [‘src‘]  aidl.srcDirs = [‘src‘]  renderscript.srcDirs = [‘src‘]  res.srcDirs = [‘res‘]  assets.srcDirs = [‘assets‘]}

}

lintoptions{

abortOnError false

}
}

dependencies{
Compile Filetree (dir: ' Libs ', include: "*.jar")
}

uploadarchives{
repositories.mavendeployer{

name = ‘mavenCentralReleaseDeployer‘repository(url: "http://192.168.33.25:8081/nexus/content/repositories/releases"){  authentication(userName: ‘admin‘, password: ‘admin123‘)}snapshotRepository(url: "http://192.168.33.25:8081/nexus/content/repositories/snapshots/"){  authentication(userName: ‘admin‘, password: ‘admin123‘)}pom.version = "1.0.0"pom.artifactId = "cloudclient"pom.groupId = "com.cloud"pom.name = "cloudclient"pom.packaging = "aar"

}

}

Compiling the jar package to upload the local maven repository
buildscript{
repositories{

mavenCentral();

}

dependencies{

classpath ‘com.android.tools.build:gradle:0.14+‘

}

Tasks.withtype (javacompile) {

options.encoding = ‘UTF-8‘

}
}

Apply plugin: ' Android-library '
Apply plugin: ' maven '

dependencies{
Compile Filetree (dir: ' Libs ', include: "*.jar")
}

android{

signingconfigs{

myConfig{  storeFile file("/home/roy/jenkins_home/jobs/ApkKeyStore")  storePassword "android"  keyAlias "brilliance"  keyPassword "android"}

}

buildtypes{

release{  signingConfig signingConfigs.myConfig}

}

Compilesdkversion 22
Buildtoolsversion "22.0.1"

sourcesets{

main{  manifest.srcFile ‘AndroidManifest.xml‘  java.srcDirs = [‘src‘]  resources.srcDirs = [‘src‘]  aidl.srcDirs = [‘src‘]  renderscript.srcDirs = [‘src‘]  res.srcDirs = [‘res‘]  assets.srcDirs = [‘assets‘]}

}

lintoptions{

abortOnError false

}

Android.libraryVariants.all {variant-

def name = variant.buildType.nameif (name.equals(com.android.builder.core.BuilderConstants.DEBUG)) {  return; // Skip debug builds.}def task = project.tasks.create "jar${name.capitalize()}", Jartask.dependsOn variant.javaCompiletask.from variant.javaCompile.destinationDirartifacts.add(‘archives‘, task);

}

uploadarchives{

repositories.mavenDeployer{  name = ‘mavenCentralReleaseDeployer‘  repository(url: "http://192.168.33.25:8081/nexus/content/repositories/releases"){    authentication(userName: ‘admin‘, password: ‘admin123‘)  }  snapshotRepository(url: "http://192.168.33.25:8081/nexus/content/repositories/snapshots/"){    authentication(userName: ‘admin‘, password: ‘admin123‘)  }  pom.version = "1.0.0"  pom.artifactId = "cloudclient"  pom.groupId = "com.cloud"  pom.name = "cloudclient"  pom.packaging = "jar"}

}
}

Relying on other APK's compilation and installation
buildscript{
repositories{

mavenCentral()

}

dependencies{

classpath ‘com.android.tools.build:gradle:0.14+‘

}

Tasks.withtype (javacompile) {

options.encoding = ‘UTF-8‘

}

}

Apply plugin: ' Android '

repositories{

maven{

url "http://192.168.33.25:8081/nexus/content/repositories/releases"

}
}
dependencies{
Compile Filetree (dir: ' Libs ', include: "*.jar")
Compile "com.common:upgrade:1.0.0"
Compile "com.cloud:cloudclient:1.0.0"
}

android{

Applicationvariants.all {variant-

variant.outputs.each { output ->  String apk_name = output.outputFile.name;  if(output.outputFile.name.indexOf(‘-debug.apk‘) > -1){    output.outputFile = new File(      output.outputFile.parent,      output.outputFile.name.replace(".apk", "mirror.apk"))  }else if(output.outputFile.name.indexOf(‘-release.apk‘) > -1){      output.outputFile = new File(      output.outputFile.parent,      output.outputFile.name.replace(apk_name, "CloudFile-release.apk"))  }}

}

signingconfigs{

myConfig{  storeFile file("/home/roy/jenkins_home/jobs/ApkKeyStore")  storePassword "android"  keyAlias "brilliance"  keyPassword "android"}

}

buildtypes{

release{  signingConfig signingConfigs.myConfig}

}

Compilesdkversion 22
Buildtoolsversion "22.0.1"
Enforceuniquepackagename=false

lintoptions{

abortOnError 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‘]}

}

lintoptions{

abortOnError false

}

}

Jenkins+gradle+android+sonarqube

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.