I prepared the following pom.xml to enable Maven builds for the opensource project MapChange:
<?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>
<artifactId>mapchange</artifactId>
<groupId>com.bricolsoftconsulting</groupId>
<version>0.1.0-SNAPSHOT</version>
<packaging>apklib</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Plugins -->
<jdk.version>1.6</jdk.version>
<api.platform>7</api.platform>
<android-maven-plugin.version>3.6.0</android-maven-plugin.version>
<maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version>
<!-- Dependencies -->
<android.version>4.1.1.4</android.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<scope>provided</scope>
<version>${android.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android-maven-plugin.version}</version>
<extensions>true</extensions>
<configuration>
<sdk>
<platform>${api.platform}</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
<lazyLibraryUnpack>true</lazyLibraryUnpack>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
When I run mvn clean install the build finishes successfully.
But when I deploy and run the app to a device using mvn clean install android:deploy android:run the activity cannot be found.
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2: \
android-maven-plugin:3.6.0:run (default-cli) on project mapchange: \
Unable to run launcher Activity: Starting: \
Intent { cmp=com.bricolsoftconsulting.mapchange/.MyMapActivity }
[ERROR] Error type 3
[ERROR] Error: Activity class \
{com.bricolsoftconsulting.mapchange/com.bricolsoftconsulting \
.mapchange.MyMapActivity} does not exist.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven \
with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, \
please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/ \
MAVEN/MojoFailureException
Please notice that I am new to using Maven and the pom.xml might contain misconfigurations.
Finally, I was able to set up a multi-module Maven project. Please find the current (working) implementation here:
https://github.com/johnjohndoe/MapChange/commits/refactor-project-structure
Related
When I try compile a android project generated with this command:
mvn archetype:generate \
-DarchetypeArtifactId=android-quickstart \
-DarchetypeGroupId=de.akquinet.android.archetypes \
-DarchetypeVersion=1.0.11 \
-DgroupId=com.kleber \
-DartifactId=app2
which generates a project with this structure:
app2
-assets
-res
...
-layout
-menu
-values
...
-src
-main
-java
-com
-kleber
HelloAndroidActivity.java
AndroidManifest.xml
default.properties
pom.xml
I got this error:
[ERROR] Found files or folders in non-standard locations in the project!
[ERROR] ....This might be a side-effect of a migration to Android Maven Plugin 4+.
[ERROR] ....Please observe the warnings for specific files and folders above.
[ERROR] ....Ideally you should restructure your project.
[ERROR] ....Alternatively add explicit configuration overrides for files or folders.
[ERROR] ....Finally you could set failOnNonStandardStructure to false, potentially resulting in other failures.
I have this pom.xml file:
<?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.kleber</groupId>
<artifactId>app2</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<name>app2</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version>4.1.1.4</platform.version>
<android.plugin.version>4.1.1</android.plugin.version>
<android.sdk.path>C:\Users\00940831503\AppData\Local\Android\Sdk</android.sdk.path>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<!--<groupId>com.jayway.maven.plugins.android.generation2</groupId>-->
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>29</platform>
</sdk>
</configuration>
</plugin>
<!--<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>29</platform>
</sdk>
</configuration>
</plugin>-->
</plugins>
</build>
</project>
What the correct project structure to compile the project without errors? Is there a maven archetype which generate the project with the correct structure already?
The Android Maven plugin expects AndroidManifest.xml in src/main rather than in the root.
Option 1: Move AndroidManifest.xml to the location in which the plugin expects it, though this may have side effects in the IDE you’re using (Eclipse seems to fine with it, as far as I can tell).
Option 2: Tell the plugin where to look for the file by adding the following to the POM, at projects/build/plugins/plugin/configuration:
<androidManifestFile>
${project.basedir}/AndroidManifest.xml
</androidManifestFile>
The same applies to resources if your project has them anywhere other than src/main/res (old projects originally built for the Eclipse/ant toolchain have them under res). The property for these is resourceDirectory.
I am trying building a android application with maven and this pom.xml:
<?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>org.kleber</groupId>
<artifactId>app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>app</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version> 4.1.1.4</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.8.2</version>
<extensions>true</extensions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<configuration>
<sdk>
<platform>16</platform>
</sdk>
<emulator>
<avd>avd</avd>
</emulator>
</configuration>
</plugin>
</plugins>
</build>
</project>
and keeping getting this error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.213 s
[INFO] Finished at: 2019-09-25T22:03:34-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.9.0-rc.2:generate-sources (default-generate-sources) on project app: Execution default-generate-sources of goal com.jayway.maven.plugins.android.generation2:android-maven-plugin:3.9.0-rc.2:generate-sources failed.: NullPointerException -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Anyone can tell what's the problem here?
I'm converting a simple android app to Maven, and I've hit a snag with a 3rd party jar (ActiveAndroid) that contains an annotation class that I'm using within my code. I've confirmed that the jar does contain the annotations class files, and the jar works fine when I include it in the libs directory, and compile with Eclipse.
Here's my POM.xml:
<?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.danh32</groupId>
<artifactId>testapp</artifactId>
<version>1.0</version>
<packaging>apk</packaging>
<name>testapp</name>
<properties>
<platform.version> 4.1.1.4</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.2.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.activeandroid</groupId>
<artifactId>activeandroid</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.5.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>16</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
And here's my compilation error:
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.339s
[INFO] Finished at: Wed Apr 10 14:18:51 CDT 2013
[INFO] Final Memory: 17M/81M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project testapp: Compilation failure: Compilation failure:
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[9,43] cannot find symbol
[ERROR] symbol : class ConflictAction
[ERROR] location: #interface com.activeandroid.annotation.Column
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[15,32] cannot find symbol
[ERROR] symbol : method unique()
[ERROR] location: #interface com.activeandroid.annotation.Column
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[15,47] cannot find symbol
[ERROR] symbol : method onUniqueConflict()
[ERROR] location: #interface com.activeandroid.annotation.Column
[ERROR] /Users/danh32/code/android/workspace-android/TestApp/src/com/danh32/testapp/db/DSLocation.java:[15,66] cannot find symbol
[ERROR] symbol : variable ConflictAction
[ERROR] location: class com.danh32.testapp.db.DSLocation
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
I'm just starting out with Maven and compiling Android apps outside of Eclipse, so I'm sure I'm missing something simple. Any nudge in the right direction is highly appreciated!
Thanks!
You're using LATEST. Is it possible you have more than one version of that artifact, and Maven is picking up a different one from Eclipse?
it doesn't look like the active android artifact is available in the Maven Central Repo (see this search). You can install that jar in your own local repository (using mvn install-file but that will only work on your local machine. Alternatively you can deploy that artifact to a repository that you control and reference that in your POM.
Have you considered class version problem? Just speculating, but it could be that the jar was built using 1.6 JDK (target 1.6) Your POM has specified the source and target as 1.5, considering you are also using 1.5 JDK, it is possible that the compiler is simply not able to read the classes in your jar file compiled with 1.6
During my maven build I'm getting errors like this:
[ERROR] /sandbox/mobile-apps/quickdroid/test/src/com/xxx/MyActivity.java:[14,21] java.util.LinkedHashMap.Entry has private access in java.util.LinkedHashMap
I created a simple test project with one class. This error corresponds to this code:
LinkedHashMap.Entry<String, Object> test;
Intellij compiles this code just fine. If I change the -target=1.5 in my intellij javac parameters then I get the same error. Below in my pom.xml I've specified target 1.6 and verified with the -X parameter that maven is getting this setting. Why do I get errors as if it's still compiling target 1.5?
excerpts from maven -X output:
1.6
.
[DEBUG] (f) source = 1.6
[DEBUG] (f) staleMillis = 0
[DEBUG] (f) target = 1.6
.
[DEBUG] Command line options:
[DEBUG] -d /sandbox/mobile-apps/quickdroid/test/target/classes -classpath {...} -g -nowarn -target 1.6 -source 1.6
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
<groupId>com.xxx.android</groupId>
<artifactId>test</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>test</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<extensions>true</extensions>
<configuration>
<sdk>
<!-- platform or api level (api level 4 = platform 1.6)-->
<platform>11</platform>
</sdk>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
I try to use Maven and androidannotations to build my apk, but independently of any IDE (I'm actually using IntelliJ IDEA and not Eclipse, but I would like to have it entirely IDE-independent, so that it would also work perfectly on any build server).
The annotations seem to get processed properly, but they're not being compiled into the apk, which is where I'm currently stuck.
I try to use the <includes> section in the maven-compiler-plugin, and the path should be correct - it exists and also contains the annotation processed, generated, java class, which is the Android main activity but with a underscore (_) suffix.
There is a wiki page description how to use Maven+Eclipse, but it's too much bound to the Eclipse IDE. https://github.com/excilys/androidannotations/wiki/Building-Project-Maven-Eclipse
so it doesn't help me solve the problem.
This is my pom.xml:
<?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.mycompany</groupId>
<artifactId>de-mycompany-myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>apk</packaging>
<name>com-mycompany-base-myproject</name>
<prerequisites>
<maven>2.2.1</maven>
</prerequisites>
<properties>
<platform.version>2.3.3</platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.2.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.googlecode.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<version>2.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.googlecode.androidannotations</groupId>
<artifactId>androidannotations</artifactId>
<classifier>api</classifier>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.1.1</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>10</platform>
</sdk>
<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>
<includes>
<include>${project.basedir}/target/generated-sources/apt/**</include>
<!--<include>target/generated-sources/apt/**</include>-->
</includes>
</configuration>
</plugin>
<plugin>
<artifactId>versions-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<version>1.3.1</version>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.0.5</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<processors>
<processor>com.googlecode.androidannotations.AndroidAnnotationProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
<dependencies/>
</plugin>
</plugins>
</build>
</project>
mvn install even shows me the -s compiler option with the correct path:
[INFO] javac option: -proc:only
[INFO] javac option: -processor
[INFO] javac option: com.googlecode.androidannotations.AndroidAnnotationProcessor
[INFO] javac option: -d
[INFO] javac option: /Users/myuser/path/to/com.mycompany.myproject/target/classes
[INFO] javac option: -s
[INFO] javac option: /Users/myuser/path/to/com.mycompany.myproject/target/generated-sources/apt
[INFO] diagnostic Note: Starting AndroidAnnotations annotation processing
[INFO] diagnostic warning: Supported source version 'RELEASE_6' from annotation processor 'com.googlecode.androidannotations.AndroidAnnotationProcessor' less than -source '1.7'
[INFO] diagnostic Note: Dummy source file: file:///Users/path/to/com.mycompany.myproject/target/generated-sources/apt/dummy1341816057285.java
[INFO] diagnostic Note: AndroidManifest.xml file found: /Users/myuser/path/to/com.mycompany.myproject/AndroidManifest.xml
[INFO] diagnostic Note: Number of files generated by AndroidAnnotations: 1
[INFO] diagnostic Note: Generating source file: com.mycompany.myproject.activity.HelloAndroidActivity_
(The complete log of mvn install is here: http://pastebin.com/6dQkcNXD)
But still running the apk fails with:
E/AndroidRuntime( 6942): Caused by: java.lang.ClassNotFoundException: com.mycompany.myproject.activity.HelloAndroidActivity_ in loader dalvik.system.PathClassLoader
and the annotation processed HelloAndroidActivity_ is not inside the apk / classes.dex.
Found the problem: <extensions>true</extensions> was missing under maven-compiler-plugin:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<includes>
<include>${project.basedir}/target/generated-sources/apt/**</include>
</includes>
</configuration>
<extensions>true</extensions>
</plugin>
After further research, I've determined that my original answer was incorrect.
The problem actually lies in the generated .classpath file. See: https://gist.github.com/cwc/5224145
In that example, broken_cp.xml causes the processed annotations to not be included in the APK when used as .classpath. Changing its contents to that of working_cp.xml and refreshing the project (prompting a build) immediately fixes the APK issue, and I can launch my Android app from Eclipse successfully.
The broken form of the classpath file is regenerated every time I use the Maven > Update Project... project menu option to reload POM files. I'm working around the issue by paying close attention to updates to the .classpath file, and making sure I don't commit a broken version.