5

I have a third party library coming with .jar and .so file.

I configured pom.xml as following:

<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 configure, I successfully tested through Intellij and apk file under target contains structure like lib/armeabi/sdc.so

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

Searching through the internet, and did not find answer.

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

Updates:

If someone is facing same problem as I am that SO file did not copy over, please try manually copy the so file over as following:

 <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>
Community
  • 1
  • 1
jxyiliu
  • 383
  • 1
  • 4
  • 15

2 Answers2

1

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

The scope of your native lib must be runtime (not sure it is required, but anyway it's a fact)

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>

The artifactId will be the library name so load it with this line of code

System.loadLibrary("sdc");

reference

Note: I don't know if sdc if the real artifactId, but if it's the case you must consider re-publishing it with the lib prefix.

ben75
  • 29,217
  • 10
  • 88
  • 134
  • Thanks Ben75, android-maven-plugin version I am using is:3.6.0. The actual dependency tag I am using is as following, you can see lib is at front: com.baidu.android.maps libBaiduMapSDK_v2_1_3 2.1.3 runtime so – jxyiliu Aug 28 '13 at 20:28
  • another strange thing is: If I use Intellij "Rebuild project" to build this maven projects, it can generate apk file with so inside properly, why maven commend line wont work? – jxyiliu Aug 28 '13 at 20:40
  • is libBaiduMapSDK_v2_1_3.so also under /libs/armeabi/ ? – ben75 Aug 28 '13 at 22:55
  • No, I do not have /libs folder under project. libBaiduMapSDK_v2_1_3.so is stored in remote server, and downloaded to my local maven repository through pom.xml dependency config. – jxyiliu Aug 29 '13 at 00:06
  • Thanks Ben75 for your comments. I have figured out how to solve the issue. – jxyiliu Aug 29 '13 at 16:54
0

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 yet, but I do use it in my regular java server projects which require non-maven items be in expected locations.

Paul Gregoire
  • 9,715
  • 11
  • 67
  • 131