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
Related
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 ;-)
When I configured my apklib I included:
<dependency>
<groupId>android</groupId>
<artifactId>android</artifactId>
<version>4.0_r3</version>
<scope>provided</scope>
</dependency>
in the dependencies list. If I don't do that it won't recognize the source code in the editor
and won't compile. However, my question is, does the Android SDK then get included into the
project that uses the apklib? It seems so. However, why would it be so? I thought which SDK to use should be only decided by the project that uses the apklib rather then the apklib itself(?). I don't want to use an apklib that for example use api-level 19 when I use api-level 14 in my main project.
In short: Does an SDK dependency in the apklib pom get included into the main project (using Maven)?
I got it.
One should use scope=provided for the dependency.
Then, Maven assumes that the container project supplies the classes, and so the SDK classes don't get imported together with the apklib.
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...
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>
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.