Cannot get Android to work with maven. What could be the problem (generated from maven quickstart archetype):
<?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>asd</groupId>
<artifactId>asd</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>asd</name>
<properties>
<platform.version>4.0.3</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<assetsDirectory>${project.basedir}/assets</assetsDirectory>
<resourceDirectory>${project.basedir}/res</resourceDirectory>
<nativeLibrariesDirectory>${project.basedir}/src/main/native</nativeLibrariesDirectory>
<sdk>
<platform>15</platform>
</sdk>
<emulator>
<avd>Android4</avd>
</emulator>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Leads to:
Project build error: Unknown packaging: apk
+
Project build error: Unresolveable build extension: Plugin
com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.2.0 or one of its
dependencies could not be resolved: Failed to collect dependencies for
com.jayway.maven.plugins.android.generation2:android-maven-plugin:jar:3.2.0 ()
I am currently using android-maven-plugin 3.1.1 for my project and give it a try with 3.2.0, It looks like Maven has some trouble downloading one of the required dependencies emma-2.1.5320.jar
from Maven Central Repository, however, I have tired mvn clean install
several times and finally get emma-2.1.5320.jar downloaded.
Try running mvn clean install
several times, if it still doesn't work, download and install it manually, emma-2.1.5320.jar with source and javadoc are available on Maven Central Repository:
mvn install:install-file -Dfile=emma-2.1.5320.jar \
-Dsources=emma-2.1.5320-sources.jar \
-Djavadoc=emma-2.1.5320-javadoc.jar \
-DgroupId=emma \
-DartifactId=emma \
-Dversion=2.1.5320 \
-Dpackaging=jar
You should be able to use android-maven-plugin 3.2.0 now, hope this helps.
I had same problem because I had android plugin added in <build><pluginManagement>
section of configuration.
Moving it to <build><plugins>
solved my issue.
Add extensions
option to your android-maven-plugin
configuration.
extensions
Whether to load Maven extensions (such as packaging and type handlers) from this plugin.
Sample configuration:
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.2</version>
<extensions>true</extensions>
<configuration>
<sdk>
<platform>${android.platform}</platform>
</sdk>
</configuration>
</plugin>
This solves probem with apk unknown packaging.
Replace the <version>3.2.0</version>
with <version>3.6.0</version>
and then clean and then install the package. 3.6.0 is the latest version of android-maven-plugin.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With