Maven does not fail from introduced compilation errors - android

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

Related

Intellij Idea stuck on reading pom.xml while importing android project

I have problem with Intellij-Idea. IDE stuck on "Looking for avalible profiles - reading pom.xml" while importing as a maven project, Intelij stuck on reading pom also on orginal project.
I have tried to build project via console mvn clean install and it... works perfectly, building project without errors but in Intellij dependency classes still are not avalible to import and shows up as red in code. I don't if that helps but I'm using mbp with OSx yosemite.
project can be found on github:
wykop offline on github
Restarting Ide/computer does not help
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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mierzejewski.wykopoffline</groupId>
<artifactId>wykop-client</artifactId>
<version>1.0-SNAPSHOT</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>
<sdk.path>/Users/dom/Desktop/adt-bundle-mac-x86_64-20140624/sdk</sdk.path>
</properties>
<!--<repositories>-->
<!--<repository>-->
<!--<id>jitpack.io</id>-->
<!--<url>https://jitpack.io</url>-->
<!--</repository>-->
<!--</repositories>-->
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>4.1.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mcxiaoke.volley</groupId>
<artifactId>library</artifactId>
<version>1.0.16</version>
</dependency>
<dependency>
<groupId>com.mikepenz.materialdrawer</groupId>
<artifactId>library</artifactId>
<version>3.0.9</version>
<scope>system</scope>
<type>aar</type>
<systemPath>${project.basedir}/libs/materialdrawer-3.0.9.aar</systemPath>
</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>
<path>${sdk.path}</path>
<platform>19</platform>
</sdk>
<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>
</project>
you can try to config this into your host file.
127.0.0.1 localhost
This maybe the maven in IDEA force to read localhost first. Then you stuck in reading pom.xml forever.
Is it that you can't go past the import window because clicking the "next" button doesn't produce any result?
if that is the issue, then it is a memory problem:
The default value assigned to Intellij importer is not enough to
handle the operation!
I have documented the solution to this issue in a similar question:
Memory problem as the answer to "Can't import the maven project in IntelliJ Idea"
P.s.: Do not ask me why as i was surprised as well that the selling company could really make such a mistake.

Android ActionBarSherlock Maven - No resources found

I have been trying to add ActionBarSherlock Maven dependecy on my project and i'm getting some problems. When i use ABS themes like:
<style name="AppThemeCustomizada" parent="#style/Sherlock.__Theme.DarkActionBar">
I get the following error:
No resource found that matches the given name '#style/Sherlock.__Theme.DarkActionBar'.
Here is my pom.xml
<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>RunasProject</groupId>
<artifactId>RunasProject</artifactId>
<version>1.0.1-SNAPSHOT</version>
<name>Runas</name>
<dependencies>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.4.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.4.0</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<extensions>true</extensions>
<configuration>
<source>1.6</source>
<target>1.6</target>
<sdk>
<platform>8</platform>
</sdk>
</configuration>
</plugin>
</plugins>
</build>
I have tried many suggestion on net, but i could not solve the problem. ABS classes work fine, but styles don't.
You have to change the packaging of your project to apk and use the Android Maven Plugin. Your configuration is mixing setup from the Android Maven Plugin into the Compiler plugin. That wont work. Check out the sample applications (including an ABS demo) of the Android Maven Plugin.

No plugin found for prefix 'android' in the current project

I have started since 2 days learning Maven & using goals as deploy and install.So I hv used this command:
mvn install android:deploy
Note:clean,install commands work fine
this is what I get:
[ERROR] No plugin found for prefix 'android' in the current project
and in the plugin groups [com.cryptolog.maven.plugins,
org.apache.maven.plugins, org.codehaus.mojo] available from the
repositories [local (/home/yougostt/.m2/repository), central
and this is the 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>univer.lib.androidtestxmlrpc</groupId>
<artifactId>android_xmlrpc</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.cryptolog.rpc</groupId>
<artifactId>libxmlrpc</artifactId>
<version>${rpc.version}</version>
</dependency>
<dependency>
<groupId>com.cryptolog.rpc</groupId>
<artifactId>libxmlrpc-client</artifactId>
<version>${rpc.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<rpc.version>3.7</rpc.version>
</properties>
</project>
How can I fix it please?
Supposing you are using the com.simpligilty.maven.plugins Android Maven Plugin (but the same would also work for any other plugin), you can add to your pom the following (as also explained by its official usage page:
<build>
<plugins>
<plugin>
<groupId>com.simpligility.maven.plugins</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>4.4.1</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
If instead you are using the Jayway Androind Maven Plugin, the configuration would look like (as also explained by the official Spring guide:
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.9.0-rc.1</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>

How to build a JAR for an android project

I am working on a small project to allow cookies to persist. I want to make the project as a JAR so other developers can use it in there project. At the moment I am able to build the project as an APKLIB however this seems unnecessary as the resources are not needed. If I change the packaging to JAR I get the follow error when building
Results :
Tests in error:
shouldAddCookie(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
shouldClearAllCookies(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
shouldClearExpired(com.doward.persistantcookietest.PersistantCookieStoreTest):
java.lang.ClassNotFoundException: caught an exception while obtaining
a class file for com.doward.persistantcookies.R
The POM looks like this
<?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.doward</groupId>
<artifactId>persistantcookiestore</artifactId>
<version>1</version>
<packaging>jar</packaging>
<name>persistantcookies</name>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.pivotallabs</groupId>
<artifactId>robolectric</artifactId>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.2.2_r2</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.2</version>
<configuration>
<androidManifestFile>${project.basedir}/AndroidManifest.xml</androidManifestFile>
<sdk>
<platform>17</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>
</project>
If you want to just build a JAR file from .class files and no resources e.g. no XML files releating to layouts, values, colours etc then you can do so from the command line:
jar -cvf <filenameorjar.jar> <files to be included>
Example:
jar -cvf cookiepersist.jar com/*
This will create a jar file in the present working directory and include all the .class files from the directory com in the present working directory.
If you have a andorid project and you wish to use the same in another project you can make the project as a library project and refer the same in another Android project. This can include your resources also.
http://developer.android.com/tools/projects/projects-eclipse.html
You export your utility classes that do not refer to resources in android ie pure java classes. If you use eclipse you can have a look at the tutorial below
http://androiddevelopement.blogspot.in/2011/01/creating-jar-file-in-eclipse.html

POM error when using ActionbarSherlock with Eclipse and Maven

I'm starting a project which I want to compile with both Eclipse and Maven. On command line everything works fine and if I remove Maven nature the project runs OK in Eclipse. However with Maven enabled I get this error in first line of the POM
dependency=[com.actionbarsherlock:actionbarsherlock:apklib:4.2.0:compile]
not found in workspace
Here's my complete 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.foo.bar</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>test</name>
<properties>
<java.version>1.6</java.version>
<platform.version> 4.1.1.4</platform.version>
<android.platform>16</android.platform>
<android-support.version>r7</android-support.version>
<abs-version>4.2.0</abs-version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>${platform.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>${android-support.version}</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>${abs-version}</version>
<type>apklib</type>
</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>${android.platform}</platform>
</sdk>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
I also noticed that there's no link to ABS from Eclipse->Properties->Android->Library
What am I missing in this setup?
Like you I compile with Maven and Eclipse, however I do not use the maven nature as it was too painful when I tried to use it.
Given that your error mentions ABS and that is a APKLIB which is kinda "faked" by Maven you might want ensure that this APKLIB is installed into your local maven repo. I dont believe that the maven nature supports workspace resolution but I could be wrong in this.
If that doesnt work you can always follow my example and just set eclipse up they default way which would mean turning off the maven nature and linking using Eclipse->Properties->Android->Library as you mentioned
I was stuck with this and tried the following and it worked:
right click on project → maven → update project configuration → select all → enjoy!

Categories

Resources