Maven: How to get the bundle’s .so library in a package
I have a third-party library with .jar and .so files.
I configure pom.xml as follows:
<dependency>
<groupId>com.abc.def</groupId>
<artifactId>sdc</artifactId>
<version>1.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.abc.def</groupId>
<artifactId>sdc</artifactId>
<version>3</version>
<scope>compile</scope>
<type>so</type>
</dependency>
With this configuration, I successfully tested with Intellij, and the apk file under the target contains a structure like lib/armeabi/sdc.so
However, after
I did MVN Clean Package
, the generated apk file does not contain sdc.so files, and after installing the apk file on android devices, the lib folder is empty.
Searching the internet, no answer was found.
By the way, I did add <nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>
going into plugin management as described earlier Native libraries (.so files) are not added to an android project, but to no avail.
Update:
If anyone has the same problem as me, the SO file is not copied over, try copying the so file manually as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.abc.def</groupId>
<artifactId>libdef</artifactId>
<version>2.1.3</version>
<type>so</type>
<destFileName>libdef.so</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/libs/armeabi</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Solution
It is recommended to use Maven-Android-Plugin version 2.8.3 or later
The scope of your native library must be runtime
(not sure if it’s needed, but it’s true anyway).
The artifactId must start with lib (i.e. it must be libsdc).
<dependency>
<groupId>com.abc.def</groupId>
<artifactId>libsdc</artifactId>
<version>3</version>
<scope>runtime</scope>
<type>so</type>
</dependency>
artifactId will be the library name, so load it with this line of code
System.loadLibrary("sdc");
Note: I don’t know if sdc is a real artifactId, but if so, you have to consider republishing it with the lib prefix. p>