Maven: How to get bundled .so libraries

I have a third-party library that comes with .jar and .so files.

I configured 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> 

Using this configuration, I successfully tested the Intellij and apk files under an object containing a structure like lib / armeabi / sdc.so

However, after I made mvn clean package , the generated apk file did not contain the sdc.so file, and after installing the apk file on the Android device, the lib folder is empty.

Search over the Internet and did not find an answer.

Btw, I add <nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory> to pluginManagement, as mentioned. Native libraries (.so files) are not added to the android project , but they do not help.

Update:

If someone is facing the same problem as me, so the SO file is not copied, try manually copying the file this way:

  <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> 
+4
source share
2 answers

I suggest you use maven-android-plugin version 2.8.3 or later.

The volume of your own lib should be runtime (not sure if this is required, but it is a fact anyway)

The artifact should start with lib (i.e. it should 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 name of the library, so load it with this line of code

 System.loadLibrary("sdc"); 

link

Note I do not know if sdc, if the real artifactId, but if so, you should consider re-publishing it with the lib prefix.

0
source

I would suggest looking into the Assembly plugin: http://maven.apache.org/plugins/maven-assembly-plugin/ I have not used it in any Android project, but I use it in my usual Java server projects, which require non-maven elements in expected places.

0
source

Source: https://habr.com/ru/post/1499469/


All Articles