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.
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.
Hii everyone I am trying to generate automated Maven build script for android project i'm using Maven 3.2.5 for generating build and i'm getting following issues while trying to generate script for sample helloworld project
Exception in thread "pool-1-thread-1"java.lang.NoClassDefFoundError:org/eclipse/aether/spi/connector/Transfer$State
at org.eclipse.aether.connector.wagon.WagonRepositoryConnector$GetTask.run(WagonRepositoryConnector.java:608)
i'm using following script for building
<?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.helloworld</groupId>
<artifactId>HelloWorld</artifactId>
<version>0.1.0</version>
<packaging>apk</packaging>
<properties>
<!-- use UTF-8 for everything -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v4</artifactId>
<version>21.0.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.1</version>
<configuration>
<sdk>
<platform>21</platform>
</sdk>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
tried changing and searched in google didn't find solution please help me
It seems that there is a compatibility issues between android-maven-plugin and the maven release 3.2.5 and later.
For me it works on a 3.2.3 and fails with NoClassDefFoundError exception when I use 3.2.5 and 3.3.1
Try to download an older maven version from the archives at
http://archive.apache.org/dist/maven/maven-3/3.2.3/
Edit
This issue is fixed in later versions(testet with 4.1.1) of the android-maven-plugin. The plugin has moved to github, and is relocated to a new groupId.
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.1.1</version>
</plugin>
New project location:
https://github.com/simpligility/android-maven-plugin/
There is some compatibility problem for maven 3.2 & 3.3. Try this:
brew install homebrew/versions/maven31
sudo ln -s /usr/local/Cellar/maven31/3.1.1 /usr/local/Cellar/maven/
brew switch maven 3.1.1
Recently I started mavenizing my android application. One of the obstacles on my way is following:
During build maven plugin cannot find drawables which are used in layouts in res directory.
I've tarted mavenizing first by using android quick start archetype:
mvn archetype:generate -DarchetypeArtifactId=android-quickstart -DarchetypeGroupId=de.akquinet.android.archetypes -DarchetypeVersion=1.0.8
Then I've copied all my resources to the res directory generated by archetype. IMHO this should be sufficient. But here is what I get after mvn clean install:
[INFO] --- android-maven-plugin:3.4.0:apk (default-apk) # missnanny-android-app ---
[INFO] Copying local assets files to combined assets directory.
[INFO] D:\Environments\AndroidSDK\android-sdk\platform-tools\aapt.exe [package, -f, -M, D:\Programming\myproj.com\myproj\myproj-android-app\MyprojManifest.xml, -S, D:\Programming\myproj.com\myproj\myproj-android-app\res, --auto-add-overlay, -A, D:\Programming\myproj.com\myproj\myproj-android-app\target\generated-sources\combined-assets\assets, -I, D:\Environments\AndroidSDK\android-sdk\platforms\android-7\android.jar, -F, D:\Programming\myproj.com\myproj\myproj-android-app\target\myproj-android-app-0.0.1-SNAPSHOT.ap_]
[INFO] D:\Programming\myproj.com\myproj\myproj-android-app\res\layout\layout_1.xml:8: error: Error: No resource found that matches the given name (at 'src' with value '#drawable/image').
I'm getting many such errors. All of them are saying that no resource can be found for some layout.xml file. I've changed name of project and resources in the log above. The real name is th different than myproj. but that shouldn't matter. During mavenizing i've only copied resources into res directory generated by archetype.
in res folder I've :
res/drawable
res/drawable-hdpi
res/drawable-mdpi
res/drawable-ldpi
res/layout
res/raw
res/values
res/values-pl
I'd like to mention that there is no problem loading drawable in AndroidManifest.xml for application icon. All problems are conneced with layout and selectors in drawable.xml
my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>pl.comapny.groupid</groupId>
<artifactId>projectid</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>appname-android-app</artifactId>
<packaging>apk</packaging>
<name>appname-android-app</name>
<properties>
<platform.version> 2.1.2 </platform.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>pl.company.groupid</groupId>
<artifactId>artifact</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${project.basedir}/res</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<!-- <executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/res</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/src/templates/res</directory>
<targetPath>${project.basedir}/res</targetPath>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions> -->
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.4.0</version> <!--3.4.0, 3.1.1, 3.0.0-alpha-14-->
<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>7</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>
</configuration>
</plugin>
</plugins>
</build>
Ok, I've managed to solve my problem. This was really stupid. There were problems with some 9 patch images which are corrupted. This resulted in build failure. It seems that eclipse android plugin accepts drawables which are marked as 9 patch image, but in fact they are not, and build can be completed ... As for maven android plugin situation is different. But still imho error messages I was getting were inapropriate - there made me focused not on real problem. I've lost a lot of time.. and I'm sure I would find a solution much faster if there weren't those error messages saying that "no resource found that matches given name". Those errors should be skipped by plugin.
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>
Just moving my Android project over to Maven / Jenkins and am exploring the build / compile / testing procedures.
Issue:
I introduced a simple compilation error in the java code, but when i run mvn clean install package I get a build success. It's only when I deploy the App to my device that it crashes and fails.
Is there something wrong with my POM?
ps. I have XXXXX'd out some info. Don't worry about it.
<?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>
<parent>
<groupId>xxxxx</groupId>
<artifactId>xxxxxx</artifactId>
<version>1.0.0</version>
</parent>
<groupId>xxxxx</groupId>
<artifactId>xxxx</artifactId>
<version>1.0.0</version>
<packaging>apk</packaging>
<name>Android App</name>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.0.1.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>4.0.0</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<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>
<path>/Users/aidenfry/android-sdks</path>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I suspect, that the reason you're not seeing an error is most likely because maven didn't even bother compiling your classes in the first place.
Maven has various conventions, and one of them is that it expects your sourcecode to be located under src/main/java.
I'm betting that you've just dropped the above pom.xml into your project root area and run mvn clean install. Maven will happily run that, but since you've probably left your source files in the default IDE locations, maven just skips over it. Have a look in your target directory and you'll see it hasn't compiled any classes in there for you
You have 2 options:
Add this somewhere inside the <build> tags in the above pom :
${basedir}/src
Re-arrange your source files so they follow the src/main/java structure.
Personally, I'd opt for number 2.
P.S, there is also src/main/test too, test classes should go there :)
You can read more about the configuration of the pom file here