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. vc字符串转换处理:(绝对精华,收集所有的例子)

    vc字符串转换处理:(绝对精华,收集所有的例子) 1.头文件中要定义宏;   #define   UNICODE         #define   _UNICODE     //////////// ...

  2. POJ - 1470 Closest Common Ancestors(离线Tarjan算法)

    1.输出测试用例中是最近公共祖先的节点,以及这个节点作为最近公共祖先的次数. 2.最近公共祖先,离线Tarjan算法 3. /* POJ 1470 给出一颗有向树,Q个查询 输出查询结果中每个点出现次 ...

  3. codeforces 688B B. Lovely Palindromes(水题)

    题目链接: B. Lovely Palindromes time limit per test 1 second memory limit per test 256 megabytes input s ...

  4. 并不对劲的bzoj4827:loj2020:p3723:[AHOI/HNOI2017]礼物

    题目大意 有两个长度为\(n\)(\(n\leq5*10^4\))的数列\(x_1,x_2,...,x_n\)和\(y_1,y_2,...,y_n\),两个数列里的数都不超过\(m\)(\(m\leq ...

  5. SPOJ:The Next Palindrome(贪心&思维)

    A positive integer is called a palindrome if its representation in the decimal system is the same wh ...

  6. hdu4352(数位DP + LIS(nlogn))

    题目描述: 给定一个区间中,将区间的每一个数看成一个字符串,求这个区间内每个字符串的最大上升 子序列等于k的个数. 可以采用nlogn的LIS(用一个C数组记录长度为i的最大上升子序列的结尾最小值), ...

  7. 杂项-Java:Thymeleaf

    ylbtech-杂项-Java:Thymeleaf Thymeleaf is a modern server-side Java template engine for both web and st ...

  8. box-shadow 模拟border

    border会占据空间;如果想加边框效果,但是又不占用空间,可以使用box-shadow来模拟 demo div 100*100 border:10px solid red; 可以写: div 100 ...

  9. JS处理时间相关

    <script>var d=new Date(); alert(d);alert(d.getMonth());alert(d.getHours());alert(d.getYear()); ...

  10. Day.js 是一个仅 2kb 大小的轻量级 JavaScript 时间日期处理库,和 Moment.js 的 API 设计保持完全一样,dayjs

    https://gitee.com/mirrors/Day.js api: https://gitee.com/mirrors/Day.js/blob/master/docs/zh-cn/API-re ...