How can I add an apklib dependency to your android maven project? - android

I have an android project which I am developing on eclipse and building with maven. I wanted to include a lib (apklib) in it, and similarly to other includes, I have tried appending the dependency to my pom in the following way:
<dependency>
<groupId>groupID.name</groupId>
<artifactId>artifact.name</artifactId>
<version>version</version>
</dependency>
However, when trying to build it either from m2eclipse or from maven on the console, I would get an error
(Failed to execute goal on project projectName: Could not resolve
dependencies for project project Failure to find apklib in
repo was cached in the local repository, resolution will not be reattempted until the update interval of repo has elapsed or
updates are forced)
saying that this dependency could not be found even if I can see the dependency in my .m2 directory

The solution was quite simple, but since I found it through an example trying to demonstrate something else, rather than a Q&A (and I did not find it easily in the maven-android-plugin project,) I decided to share it here with the hope it can help someone.
The solution was just to set my dependency type to apklib in this way:
<dependency>
<groupId>groupID.name</groupId>
<artifactId>artifact.name</artifactId>
<version>version</version>
<type>apklib</type>
</dependency>

Related

Android Maven SDK Deployer

I need to include appcompat-v7 in a maven build. Please note this is a question about a library with resources and not a jar. It's currently an aar artifact. The documentations on the SDK Deployer does not cover version 23.1.0 or version 23.0.1. I need to know what dependency needs to be in pom to include the compatibility library. Its either aar or apklib, and or also the include of a jar file as well. If anyone has got this working I would appreciate it if you would share the correct pom dependency. This problem appears to have been solved here:
How can I add an apklib dependency to your android maven project?
but this solution expressed in latest Android would be:
<dependency>
<groupId>android.support</groupId>
<artifactId>compatibility-v7-appcompat</artifactId>
<version>23.1.0</version>
<type>apklib</type>
</dependency>
This does not work now because apklib is not what is there. It is aar and changing type to aar does not seem to work either. Resulting in lots of conflicts or missing classes or class conflicts. I can think of no more commonly needed library from SDK Deployer than this. So could someone please answer the quesiton. In addition, I think the documentation of the deployer should reflect current versions, not just versions that are years old. Thanks.
The documentation of the SDK deployer references all dependencies that are custom created in addition to the ones from the repositories of the SDK itself. You can run the deployer and deploy all the components into a repository manager like Nexus and then search there or you can browse the local file system repository in ~/.m2/repository. For example look in the directory ~/.m2/repository/com/android/support/appcompat-v7/
In your case you probably want to use something like
<dependency>
<groupId>com.android.support</groupId>
<artifactId>appcompat-v7</artifactId>
<version>23.1.1</version>
<type>aar</type>
</dependency>
This is all mentioned in the docs. And the deployer is open source and I do accept pull requests ;-)

Red squiggly line in Maven dependency list in IntelliJ - where do I start debugging?

I'm getting a red squiggly line under the maven dependency to play-services-maps, a library that is installed locally with the M2 repository coming with the Android SDK. I've configured it correcly as a local repository in maven. The dependency is resolved when I look at the XML file, but the "Maven projects" tab show otherwise and the project does not compile (classes from the AAR is not found).
Where do I even start looking for the error? Why is it not presenting an error message with the squiggly line?
I've looked in idea.log but nothing. The dependency graph looks ok as well:
Any hints?
I'm using IntelliJ 14.1.2
edit: After running mvn install from the command line I realised it attempted to fetch the dependency as a .jar. It is a .aar, so adding <type>aar</type> to the dependency specification fixed it
Execute mvn install from command line, or from IntelliJ directly, to see details. Or you could try hovering over the module...
Click on this refresh button. This reimports all maven projects.
Close the project and import project again by selecting the POM file
The only solution that woked for me is downloading .jar file of dependency, placing it directly in the project. Dependency changed to:
<dependency>
<groupId>bad.robot</groupId>
<artifactId>simple-excel</artifactId>
<version>1.0</version>
<scope>test</scope>
<systemPath>${project.basedir}/resources/libs/simple-excel-1.0.jar</systemPath>
</dependency>

Error with Maven Dependencies when building HoloEverywhere

I'm trying to use HoloEverywhere in an Android application but I cannot get it to work properly. Whenever I try to import the library I get some errors. After Googling I've been able to remove error up to this one:
The container 'Maven Dependencies' references non existing library
'C:\Users\myself\.m2\repository\com\google\android\support-v4\r12\support-v4-r12.jar'
I have this library in the folder "HoloEverywhere-master\support-library" because it is included with HoloEverywhere. I am not at all familiar with Maven so I'm not too sure what exactly it is trying to do. Any ideas?
check this dependency in pom.xml , you can link it as dependency with system scope :
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r12</version>
<scope>system</scope>
<systemPath>${project.basedir}/external/something.jar</systemPath>
</dependency>
then just correct system path. This is just quick fix. A bit better solution is to install that jar library into your local repository with this command :
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
OR
look for maven repository which contains given library e.g. :
http://mvnrepository.com/artifact/com.google.android/support-v4/r6 (be carefull this is r6 version and you propably need r12)
<repositories>
<repository>
<id>my-alternate-repository</id>
<url>http://myrepo.net/repo</url>
</repository>
Is this really a Maven problem?
Have you tried Right-clicking on your project.
Selecting Android Tools > Add Support Libraries...

Android Eclipse project compilation errors with maven provided dependency

I'm converting an android application to be maven-based
what I've done is:
Insert pom.xml
List item
copy java classes into main/java directory and make this directory
the source path
insert the maven nature into .project file
I add the google android library dependency into pom.xml:
<dependency>
<groupId>com.google.android</groupId>
<artifactId>android</artifactId>
<version>2.1.2</version>
<scope>provided</scope>
</dependency>
I then realised that I don't need the android library to be included in the class path as I'm actually refering it from the pom.xml
So I removed the library, and what happend is the the project has compilation errors, though It exports the apk successfully when I right click > Run As> Maven Install, and this means that this project is a correct project from a maven perspective, so what's wrong with eclipse ??
What I found is that the Maven Dependency Library is abscent when I set the library scope as provided,
<scope>provided</scope>
but is back when I set the dependency to it's default(Compile),
<scope>compile</scope>
Though this scope makes maven fail to package as this library is a core library that must not be included, and anyway I find it a terrible solution even if it's packaging well
What am I missing here ??
NB: I'm using MotoDev IDE
It turned out that there is an issue with the android-maven-plugin with apk packaging ... will post the solution when solved

APKLIB does not get installed in Maven Repo

This must be a very stupid newbie question, but I have spent my whole day trying to figure out what is wrong with this thing.
I was about to include a dependency on Sherlock Action bar into my Android-Maven project. The site made a repo to support maven-android setup. I know that I was supposed to just include the dependency, then specify the repo inside the pom, that I have managed to do, but to no luck did this just not work for me.
these are the dependency and repository tags I used
<dependency>
<groupId>com.actionbarsherlock</groupId>
<artifactId>library</artifactId>
<version>3.5.1</version>
<type>apklib</type>
</dependency>
and this
<repository>
<id>jakewharton</id>
<url>http://r.jakewharton.com/maven/release/</url>
</repository>
i don't have any errors at all. It's just that I can't see the APKLIB under the maven dependencies directory on my package explorer at eclipse. But most importantly, I can't use the packages/classes under the apklib.
Am I missing anything?
This special type of apklib dependency only works in android-maven-plugin from command line console. adding it as a dependency in your main project's POM does not automatically import the library project into your Eclipse, so no library project shown in Package Explorer.
Simply adding the apklib as a dependency in pom doesn't help much for project development. as packages/classes under the apklib is not referenced/linked to your main project. it is different from the regular jar dependency, where you simply add jar dependency into your project and start import/use packages/classes in your main project.
Your need import the library project into your Eclipse workspace, and link it with your main project. As you already use android-maven-plugin, the most straight forward way to do this is change your maven project into multi-module project and add the library project as a sub-module
check out the LibraryProjects from android-maven-plugin sample here
Hope this help.

Categories

Resources