Maven + RoboGuice + ActionBarSherlock + RoboGuice-Sherlock - android

I am trying to create an Android base project using android-quickstart archetype, and adding RoboGuice, ActionBarSherlock dependencies, plus RoboGuice-Sherlock to combine the two.
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.myapp</groupId>
<artifactId>BaseApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<name>BaseApp</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<platform.version> 4.1.1.4
</platform.version>
<android.plugin.version>3.6.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.roboguice</groupId>
<artifactId>roboguice</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>1.3.9</version>
</dependency>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.4.0</version>
<type>apklib</type>
</dependency>
<dependency>
<groupId>com.github.rtyley</groupId>
<artifactId>roboguice-sherlock</artifactId>
<version>1.5</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>${android.plugin.version}</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>
</configuration>
</plugin>
</plugins>
</build>
</project>
But m2eclipse wont work with this Pom.xml, as it is unable to find the apklib dependency.
Speficically I am getting the following message under "Problems" tab in Eclipse:
dependency=[com.actionbarsherlock:actionbarsherlock:apklib:4.4.0:compile] not found in workspace pom.xml /BaseApp line 1 me.gladwell.eclipse.m2e.android.markers.dependency.apklib
I have tried removing the <type>apklib</type> line but then my ABS resources (namely the required Themes) are not imported into the project.
I've read in several questions that the apklib type only works on command line, and that if I want to stick to the IDE I need to import ABS manually as a library. I did, but then RoboGuice crashes because the project becomes a library project and, apparently, resource ids are not final anymore in library projects. (The compile-time error I get is "The value for annotation attribute InjectView.value must be a constant expression"). For reference, this is my only Activity:
public class HelloAndroidActivity extends RoboSherlockActivity {
#InjectView(R.id.helloworld) TextView textView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView.setText("Roboguice says Hello World");
}
}
IS there any proper way to create a base project with these three elements using maven and Eclipse?

Turns out I accidentally clicked the "Is Library" checkbox on Project Properties. Now it works with ABS manually imported as a library.
It is a pity though not being able to use Maven directly :(

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.

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!

ActionBarSherlock + maven + eclipse: dependency not found in workspace

I've updated to lastest version of ADT Plugin and I faced this issue, solved updating also m2e-android eclipse plugin. Now, I'm able to compile my project through console, but not with eclipse. This is the exception thrown by pom.xml file in eclipse:
dependency=[com.actionbarsherlock:library:apklib:4.1.0:compile] not found in workspace
In previous versions of ADT/m2e-android, I was able to build both console and eclipse without problems.
Does anyone know how to solve this? Maybe my pom.xml is wrong?
Thanks for your time.
Currently using:
Eclipse classic 3.7.2 (with Juno the problem persists)
ADT 20.0.3
m2e-android 0.42
android-maven-plugin 3.3.0
maven 3.0.4
m2e 1.1.0 (included as a dependency in m2e-android 0.42)
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.jelies</groupId>
<artifactId>my-project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>apk</packaging>
<dependencies>
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.1_r2</version>
<scope>provided</scope>
</dependency>
<!-- some unrelated dependencies -->
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>4.1.0</version>
<type>apklib</type>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<executions>
<execution>
<id>attach-sources</id>
<phase>verify</phase>
<goals>
<goal>jar-no-fork</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.4</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>com.jayway.maven.plugins.android.generation2</groupId>
<artifactId>android-maven-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<sdk>
<platform>16</platform>
</sdk>
<emulator>
<avd>avd-4.1</avd>
</emulator>
<deleteConflictingFiles>true</deleteConflictingFiles>
<undeployBeforeDeploy>true</undeployBeforeDeploy>
</configuration>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>eclipse</id>
<activation>
<!-- This profile is only activated when m2e.version is present (only
in eclipse) -->
<property>
<name>m2e.version</name>
</property>
</activation>
<dependencies>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r7</version>
<scope>provided</scope>
</dependency>
</dependencies>
</profile>
</profiles>
</project>
EDIT:
Answer is right. Having ABS library project mavenized in my workspace, error is gone! But, another problem appeared: ABS transitive dependencies are added to my project, causing eclipse to be not able to launch the application. This is a known issue you can follow here.
As of Android 0.4.2 you now need to mavenise the Android library projects in your Eclipse workspace for m2e-android to successfully detect them. The POM for ActionBarSherlock can be found here:
https://github.com/JakeWharton/ActionBarSherlock/blob/master/library/pom.xml#
Note: m2e-android is beta software and so changes that might affect functionality can occur between releases.
For those who don't know what "MAVENIZED" means it is convert a simple project to be a Maven Project.
In Eclipse, right click in your project, Configure -> Convert to Maven Project
you can include the actionbarsherlock dependency as jar file only when using eclipse via profiles
<profile>
<id>m2e</id>
<activation>
<property><name>m2e.version</name></property>
</activation>
<dependencies>
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>${abs.version}</version>
<type>jar</type>
</dependency>
</dependencies>
</profile>
and don't need to include the entire actionbarsherlock as project in eclipse
Add this to your parent pom.xml file as a dependency:
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<type>apklib</type>
<version>4.2.0</version>
</dependency>
And the following lines to your project pom.xml:
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>actionbarsherlock</artifactId>
<version>4.2.0</version>
</dependency>
I've wrote detailed tutorial about mvn + eclipse + action bar sherlock integration http://v.zasadnyy.com/blog/abs-maven-eclipse-integration/
Hope it will be helpful.

Categories

Resources