简体   繁体   English

Maven:我如何获得捆绑在包中的.so库

[英]Maven: How do I get .so libraries bundled in package

I have a third party library coming with .jar and .so file. 我有一个第三方库,附带.jar和.so文件。

I configured pom.xml as following: 我将pom.xml配置如下:

<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 有了这个配置,我成功通过Intellij和apk文件测试目标包含的结构如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. 但是,在我做了mvn clean package ,生成的apk文件不包含sdc.so文件,并且在android设备上安装apk文件后,lib文件夹为空。

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. 顺便说一句,我确实将<nativeLibrariesDirectory>${project.basedir}/libs</nativeLibrariesDirectory>到pluginManagement中,如上所述Native库(.so文件)没有添加到android项目中 ,但没有帮助。

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: 如果某人遇到与我相同的问题,SO文件没有复制,请尝试手动复制so文件,如下所示:

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

我建议查看Assembly插件: http//maven.apache.org/plugins/maven-assembly-plugin/我还没有在任何Android项目中使用过它,但我确实在我的常规java服务器项目中使用它要求非maven项目在预期的位置。

I suggest you to use maven-android-plugin version 2.8.3 or more. 我建议你使用maven-android-plugin 2.8.3或更高版本。

The scope of your native lib must be runtime (not sure it is required, but anyway it's a fact) 您的本机库的范围必须是runtime (不确定它是否是必需的,但无论如何它是一个事实)

The artifactId must start with lib (ie it must be libsdc) artifactId必须以lib开头(即必须是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 artifactId将是库名,因此使用此行代码加载它

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. 注意 :我不知道sdc是否真的是artifactId,但是如果是这种情况你必须考虑用lib前缀重新发布它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM