Java – Create apklibs using maven and IntelliJ

Create apklibs using maven and IntelliJ… here is a solution to the problem.

Create apklibs using maven and IntelliJ

I’m creating an apklib by sliding the menu because I can’t find any Maven repository. The problem is that when I try from intellij, it imports the library but doesn’t add dependencies to the sliding menu library, I have to add it manually.

<?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.slidingmenu</groupId>
<artifactId>library</artifactId>
<version>1.2</version>
<type>apklib</type>

<dependencies>
    <dependency>
        <groupId>com.google.android</groupId>
        <artifactId>android</artifactId>
        <version>4.1.1.4</version>
    </dependency>
    <dependency>
        <groupId>com.google.android.maps</groupId>
        <artifactId>maps</artifactId>
    </dependency>
    <dependency>
            <groupId>com.google.android</groupId>
            <artifactId>support-v13</artifactId>
            <version>r12</version>
        </dependency>
    <dependency>
            <groupId>com.github.rtyley</groupId>
            <artifactId>roboguice-sherlock</artifactId>
            <version>1.5</version>
        </dependency>
    <dependency>
            <groupId>org.roboguice</groupId>
            <artifactId>roboguice</artifactId>
            <version>2.0</version>
        </dependency>
    <dependency>
        <groupId>com.actionbarsherlock</groupId>
        <artifactId>actionbarsherlock</artifactId>
        <version>4.2.0</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>
            <extensions>true</extensions>
            <configuration>
                <nativeLibrariesDirectory>ignored</nativeLibrariesDirectory>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>

I created the zip according to the instructions on the maven plugin and then pushed it to ~/.m2:: using the following command

 mvn org.apache.maven.plugins:maven-install-plugin:2.4:install-file -DgroupId=com.slidingmenu -DartifactId=library -Dfile=sliding-menu.apklib -Dversion=1.2 - Dpackaging=apklib

Solution

You need to use mvn clean install instead of install:install-file to install com.slidingmenu in your local repository

MVN Clean Install puts all the metadata and dependencies required by Maven into your local repository (i.e. ~/.m2/repository).

In your apk, specify Artifact com.slidingmenu as a dependency of type apklib

Hope this solves your problem.

Related Problems and Solutions