Maven:如何将.so库打包在一起 [英] Maven: How do I get .so libraries bundled in package

查看:116
本文介绍了Maven:如何将.so库打包在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方库,带有.jar和.so文件.

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

我将pom.xml配置如下:

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>

通过此配置,我通过Intellij成功地进行了测试,并且apk文件在目标包含lib/armeabi/sdc.so之类的结构下

With this configure, I successfully tested through Intellij and apk file under target contains structure like lib/armeabi/sdc.so

但是,在我执行 mvn clean package 之后,生成的apk文件不包含sdc.so文件,并且在android设备上安装apk文件之后,lib文件夹为空.

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.

顺便说一句,我确实将< nativeLibrariesDirectory> $ {project.basedir}/libs</nativeLibrariesDirectory> 添加到pluginManagement中,如

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.

更新:

如果有人遇到与我相同的问题,即SO文件未复制过来,请尝试按以下方式手动复制so文件:

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>

推荐答案

我建议您使用2.8.3或更高版本的maven-android-plugin.

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

您的本机lib的范围必须是 runtime (不确定是否是必需的,但无论如何这是事实)

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

artifactId必须以lib开头(即必须为libsdc)

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将是库名,因此请使用此代码行将其加载

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

System.loadLibrary("sdc");

参考

注意:我不知道sdc是否为真正的artifactId,但是如果是这种情况,则必须考虑使用 lib 前缀重新发布.

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.

这篇关于Maven:如何将.so库打包在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆