Maven and POM

1. 什么是Maven?

官方的解释是: http://maven.apache.org/guides/getting-started/index.html#What_is_Maven

2. 什么是POM

官方的解释是: http://maven.apache.org/pom.html#What_is_the_POM

3. POM的具体例子

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.demo</groupId>
<artifactId>maven-demo</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging> <dependencies>
<!-- 加入android依赖,scope=provided -->
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<!-- 加入android项目依赖,type=apklib -->
<!-- 如果是android library形式的依赖,需使用这种,使用前需要将项目打包成apklib并上传到仓库 -->
<!-- 如果使用maven打包library依赖,pom.xml需改用 <packaging>apklib</packaging> ,并用install命令上传 -->
<dependency>
<groupId>com.example.demo</groupId>
<artifactId>android-framework</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
<!-- 加入facebook依赖,type=aar -->
<dependency>
<groupId>fr.avianey</groupId>
<artifactId>facebook-android-api</artifactId>
<version>3.8.0</version>
<type>aar</type>
</dependency>
<!-- 加入android support依赖 -->
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
</dependency>
<!-- 加入junit依赖,scope=test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.build.timestamp.format>yyyy-MM-dd-HH-mm-ss</maven.build.timestamp.format><!-- 增加一个时间戳的属性,生成的apk名可以加入该属性 -->
</properties> <profiles>
<profile>
<id>dev</id>
<properties>
<package.type>dev</package.type><!-- 增加一个包类型的属性,mvn命令以参数-P传入,生成的apk名可以加入该属性 -->
</properties>
<build>
<!-- 打包后替换apk中的指定文件 -->
<!--
<resources>
<resource>
<directory>res\values\dev</directory>
<targetPath>config</targetPath>
<includes>
<include>strings.*</include>
</includes>
</resource>
<resource>
<directory>res\layout</directory>
<filtering>true</filtering>
<includes>
<include>*.*</include>
</includes>
</resource>
</resources>
-->
</build>
</profile> <profile>
<id>prod</id>
<properties>
<package.type>prod</package.type><!-- 增加一个包类型的属性,mvn命令以参数-P传入,生成的apk名可以加入该属性 -->
</properties>
<build><!--
<resources>
<resource>
<directory>res\values\prod</directory>
<targetPath>config</targetPath>
<includes>
<include>*.*</include>
</includes>
</resource>
</resources>-->
</build>
</profile>
</profiles> <build>
<sourceDirectory>src</sourceDirectory><!-- 源代码目录 -->
<testSourceDirectory>test</testSourceDirectory><!-- 测试代码目录 -->
<finalName>${project.artifactId}_${project.version}_${package.type}_${maven.build.timestamp}</finalName><!-- 生成的apk文件名 -->
<plugins>
<!-- android-maven-plugin,打包apk -->
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<configuration>
<sdk>
<platform>19</platform>
<!--
<path>D:\adt-bundle\sdk</path>
-->
</sdk>
<!-- "false"执行代码混淆 -->
<proguard>
<skip>false</skip><!--
<config>proguard.cfg</config>
<jvmArguments>
<jvmArgument>-Xms256m</jvmArgument>
<jvmArgument>-Xmx512m</jvmArgument>
</jvmArguments>-->
</proguard>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<sign>
<debug>false</debug><!-- 生成未签名的apk -->
</sign>
</configuration>
<extensions>true</extensions>
<inherited>true</inherited>
</plugin>
<!-- maven-jarsigner-plugin,用于创建签名 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.3.2</version>
<executions>
<execution>
<id>signing</id>
<goals>
<goal>sign</goal>
</goals>
<phase>package</phase>
<inherited>true</inherited>
<configuration>
<removeExistingSignatures>true</removeExistingSignatures>
<archiveDirectory></archiveDirectory>
<!-- SF 和 RSA的文件名 -->
<sigfile>CERT</sigfile>
<!-- 用于签名的apk(貌似这一项不起作用) -->
<includes>
<include>${project.artifactId}_${project.version}_${package.type}_${maven.build.timestamp}.apk</include>
</includes>
<keystore>D:\keys\key.store</keystore><!-- keystore位置 -->
<storepass>123456</storepass><!-- store密码 -->
<keypass>123456</keypass><!-- key密码-->
<alias>maven_demo</alias><!-- alias -->
<verbose>false</verbose><!-- 是否输出过程讯息 -->
<!-- 指定加密算法 -->
<arguments>
<argument>-sigalg</argument><argument>MD5withRSA</argument>
<argument>-digestalg</argument><argument>SHA1</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin> <plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>maven-android-plugin</artifactId>
<version>2.8.4</version>
<inherited>true</inherited>
<configuration>
<sign>
<debug>false</debug>
</sign>
<!-- zipalign对齐优化 -->
<zipalign>
<verbose>false</verbose>
<inputApk>target\${project.artifactId}_${project.version}_${package.type}_${maven.build.timestamp}.apk</inputApk>
<outputApk>target\${project.artifactId}_${project.version}_${package.type}_${maven.build.timestamp}-aligned.apk</outputApk>
</zipalign>
</configuration>
<executions>
<execution>
<id>alignApk</id>
<phase>package</phase>
<goals>
<goal>zipalign</goal>
</goals>
</execution>
</executions>
</plugin> <!-- jacoco plugin检查测试代码覆盖率 -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<executions>
<!-- prepare agent for measuring integration tests -->
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build> <!-- 生成测试代码覆盖率报告 -->
<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.1.201405082137</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>

例子中各个plugin的版本互相有依赖关系的,如果换了其他版本,有可能导致失败。有时在运行测试的过程会提示java.lang.RuntimeException: Stub! at junit.framework.Assert.assertEquals(Assert.java:30),可以尝试调整dependencies中的依赖顺序来解决问题。

最后打包出来的apk,可以用aapt dump badging APK文件名来查看包信息,解压出CERT.RSA,用keytool -printcert -file CERT.RSA 命令来查看签名的MD5、SHA1、SHA256值及签名算法。

使用Jenkins进行android项目的自动构建(2)的更多相关文章

  1. 使用Jenkins进行android项目的自动构建(5)

    之前在项目中引入的单元测试使用的是JUnit,可以在构建前进行测试,这里在介绍一下使用Instrumentation 进行单元测试.使用Instrumentation进行测试,比之前多一些步骤,需要把 ...

  2. 使用Jenkins进行android项目的自动构建(3)

    建立Jenkins项目 1. “新增作业”->填写作业名称->选择“建置 Maven 2 或 3 專案”->OK.新增成功后会进入“組態設定”,暂时先保留默认值,稍后再进行设定. 2 ...

  3. 使用Jenkins进行android项目的自动构建(4)

    加入单元测试 android单元测试很多都是使用Instrumentation进行的,这里讲的是试用JUnit,为什么用JUnit呢?因为使用Instrumentation需要打包apk安装,然后再进 ...

  4. 使用Jenkins进行android项目的自动构建(6)

    之前已经介绍过使用Maven做构建,在来介绍一下Gralde的自动化构建. 什么是Gralde?官方的解释是 Gradle is an open source build automation sys ...

  5. 使用Jenkins进行android项目的自动构建(1)

    环境搭建 1. 下载JDK,安装,并将JDK的安装目录加入到环境变量JAVA_HOME,将JDK的bin目录加入到环境变量PATH. 2. 下载Android SDK,解压,并将SDK的安装目录加入到 ...

  6. 用Ant实现Java项目的自动构建和部署

    原文地址:http://tech.it168.com/j/2007-11-09/200711091344781.shtml         本文请勿转载! Ant是一个Apache基金会下的跨平台的构 ...

  7. 用Ant实现Java项目的自动构建和部署(转)

    Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一.            ...

  8. 用Ant实现Java项目的自动构建和部署(转)

    Ant是一个Apache基金会下的跨平台的构件工具,它可以实现项目的自动构建和部署等功能.在本文中,主要让读者熟悉怎样将Ant应用到Java项目中,让它简化构建和部署操作. 一.            ...

  9. 使用Bitbucket Pipeline进行.Net Core项目的自动构建、测试和部署

    1. 引言 首先,Bitbucket提供支持Mercurial和Git版本控制系统的网络托管服务.简单来说,它类似于GitHub,不同之处在于它支持个人免费创建私有项目仓库.除此之外,Bitbucke ...

随机推荐

  1. ibatis和mybatis的区别

    区别1:全局配置文件(sqlMapConfig.xml)的差异 主要是元素标签命名的差异,比如mybatis的根元素标签为<configuration>,ibatis的 根元素标签为< ...

  2. JDBC各种数据库连接URL关键代码

    通过JDBC连接数据库时,各个数据库有着不同的URL格式,为了方便大家使用,我在以下提供了常见的7种数据库连接示例代码,请根据实际需要进行相应的更改. 1.Oracle数据库 Class.forNam ...

  3. Ural2040:Palindromes and Super Abilities(离线&manecher算法)

    Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tel ...

  4. BZOJ_4184_shallot_线段树按时间分治维护线性基

    BZOJ_4184_shallot_线段树按时间分治维护线性基 Description 小苗去市场上买了一捆小葱苗,她突然一时兴起,于是她在每颗小葱苗上写上一个数字,然后把小葱叫过来玩游戏. 每个时刻 ...

  5. AutoIT: 处理GridView控件的一些折中方法

    一般情况下,Gridview是无法通过AutoIT Window Info来获取控件信息的,但是可以有折中的办法对Gridview中的字段赋值. #include<array.au3> $ ...

  6. 初探js闭包

    1.变量的作用域:全局变量.局部变量 函数内部可以直接读取局部变量 js代码 var n=2; function fun(){ alert(n); } fun();  //2 函数外部不能读取函数内部 ...

  7. word excel 等导出相关操作

    无插件,无com组件,利用EXCEL.WORD模板做数据导出(一) http://www.cnblogs.com/tzy080112/p/3413938.html 使用Aspose.Cells组件生成 ...

  8. Codeforces Round #382 (Div. 2) (模拟|数学)

    题目链接: A:Ostap and Grasshopper B:Urbanization C:Tennis Championship D:Taxes 分析:这场第一二题模拟,三四题数学题 A. 直接模 ...

  9. P3161 [CQOI2012]模拟工厂

    传送门 先枚举选择哪些订单,然后转为判定是否可行 在能完成的情况下肯定是花越多时间提高生产力越优 我们设可以有\(x\)单位时间来提高生产力,那么如果当前离下一个订单的时间为\(T\)时,这个订单要\ ...

  10. 洛谷P4344 [SHOI2015]脑洞治疗仪(珂朵莉树)

    传送门 看到区间推倒……推平就想到珂朵莉树 挖脑洞直接assign,填坑先数一遍再assign再暴力填,数数的话暴力数 //minamoto #include<iostream> #inc ...