Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android project build with native libraries inside using maven

I have an Android project with Maven that uses internal libraries. When I run a maven install the so library is not inside the jar file generated and in consequence is not inside the apk generated. I'm using Eclipse with maven and android maven plugin v.3.7.0.

My pom.xml is:

    <build>
    <sourceDirectory>src</sourceDirectory>
    <finalName>../bin/${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>com.jayway.maven.plugins.android.generation2</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
                <sdk>
                    <path>${env.ANDROID_HOME}</path>
                    <platform>15</platform>
                </sdk>
            </configuration>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

It seems that nativeLibrariesDirectory tag doesn't works for me.

Any idea to fix this problem? Thanks

like image 413
Plebios Avatar asked Jul 04 '26 12:07

Plebios


1 Answers

Here is how to include native libraries in your apk:

    <build>
    <finalName>${project.artifactId}</finalName>
    <plugins>
        <plugin>
            <groupId>com.simpligility.maven.plugins</groupId>
            <artifactId>android-maven-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <manifest>
                    <debuggable>true</debuggable>
                </manifest>
                <!-- Where the native files are located; in the future we should use src/main/libs -->
                <nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>                
            </configuration>
            <executions>
                <execution>
                    <id>manifestUpdate</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>manifest-update</goal>
                    </goals>
                </execution>
                <execution>
                    <id>alignApk</id>
                    <phase>package</phase>
                    <goals>
                        <goal>zipalign</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
like image 59
Paul Gregoire Avatar answered Jul 07 '26 02:07

Paul Gregoire



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!