1.安装maven,下载apache-maven-3.1.1,配置环境变量。
2.下载eclipse,在eclipse marketplace中搜索android for maven eclipse下载安装。
3.配置eclipse的maven地址,指定setting文件地址。
setting.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>central</id>
<mirrorOf>*</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://192.168.9.100:8081/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>dev</id>
<repositories>
<repository>
<id>local-nexus</id>
<url>http://192.168.9.100:8081/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
<profile>
<id>android-settings</id>
<properties>
<android.sdk.path>I:/android-sdk_r24.1.2-windows/android-sdk-windows</android.sdk.path>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>dev</activeProfile>
<activeProfile>android-settings</activeProfile>
</activeProfiles>
</settings>
4.在android项目中新建pom.xml文件:
4.1如果是android library则pom文件内容为:注意packaging为apklib,也可以引入其他的apklib
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cc.zenking.android</groupId>
<artifactId>bar_qr_code</artifactId>
<version>1.0.0</version>
<packaging>apklib</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version>4.1.1.21</platform.version>
<android.plugin.version>4.3.0</android.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>3.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cc.zenking.android</groupId>
<artifactId>cc.zenking.android</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<includeLibsJarsFromApklib>true</includeLibsJarsFromApklib>
<sourceDirectories>
<sourceDirectory>./src</sourceDirectory>
<sourceDirectory>./.apt_generated</sourceDirectory>
</sourceDirectories>
<androidManifestFile>./AndroidManifest.xml</androidManifestFile>
<assetsDirectory>./assets</assetsDirectory>
<nativeLibrariesDirectory>./libs</nativeLibrariesDirectory>
<resourceDirectory>./res</resourceDirectory>
<sdk>
<platform>21</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.2如果是普通androd项目则pom文件为:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cc.zenking.android</groupId>
<artifactId>cc.zenking.edu.zksc</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version> 4.1.1.21</platform.version>
<android.plugin.version>4.3.0</android.plugin.version>
<sign.keystore>${project.basedir}\app.keystore</sign.keystore>
<sign.alias>appkey</sign.alias>
<sign.storepass>签名需要的第一个密码</sign.storepass>
<sign.keypassword>签名需要的第二个密码</sign.keypassword>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>3.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>cc.zenking.android</groupId>
<artifactId>barcode</artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>signing</id>
<goals>
<goal>sign</goal>
<goal>verify</goal>
</goals>
<phase>package</phase>
<inherited>true</inherited>
<configuration>
<removeExistingSignatures>true</removeExistingSignatures>
<archiveDirectory />
<includes>
<include>target/${project.artifactId}-${project.version}.apk</include>
</includes>
<keystore>${sign.keystore}</keystore>
<alias>${sign.alias}</alias>
<storepass>${sign.storepass}</storepass>
<keypass>${sign.keypassword}</keypass>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<includeLibsJarsFromApklib>true</includeLibsJarsFromApklib>
<genDirectory>./gen</genDirectory>
<androidManifestFile>./AndroidManifest.xml</androidManifestFile>
<assetsDirectory>./assets</assetsDirectory>
<nativeLibrariesDirectory>./libs</nativeLibrariesDirectory>
<resourceDirectory>./res</resourceDirectory>
<sourceDirectories>
<sourceDirectory>./src</sourceDirectory>
<sourceDirectory>./.apt_generated</sourceDirectory>
</sourceDirectories>
<sdk>
<platform>21</platform>
</sdk>
<sign>
<debug>false</debug>
</sign>
</configuration>
</plugin>
</plugins>
</build>
</project>
注意:
因为框架用的是Androidannotations,所以需要引入
androidannotations包。
至于
androidannotations-api则不需要再pom中引入,直接使用默认的方式引入即可。
如果不使用androidannotations框架则比较简单,因为不涉及生成子类的问题。
5.可以安装android Connector将maven工程与android工程进行关联(用了几个eclipse版本,但是都安装失败,或者找不到该插件。)
如果安装失败,则android与maven工程无法关联,那么android与maven就是独立的,只能各自独立运行。
运行maven工程的时候只能通过点击pom文件运行。
6.右键工程进行编译(如果安装android connector失败,只能右键pom文件),如果上次编译过,需要clean后再编译。
如果使用androidannotations框架,则会提示xxxxx_.java类找不到,不用管它,如果没有其他错误可以编译成功,因为编译顺序的问题
才会提示找不到,打包的时候已经生成xxxxx_.java类了,可以将xxxx_.java类打包进apk,所以打的包也没问题。
编译时课程会出很多错,大部分都是jar包冲突或者资源冲突,可以逐条找到对应的资源或者jar,将重复的jar只保留父工程的,将重复的资源直接删除。还有android的.9图片可能会报错,将.9去掉就行了。