如何在Maven中解包AAR依赖项类? [英] How do I unpack AAR dependency classes in Maven?

查看:242
本文介绍了如何在Maven中解包AAR依赖项类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Maven,我需要处理其他依赖项中的类.在处理这些类之前,使用maven-dependency-plugin将这些依赖项与unpack-dependencies目标一起解压缩,因此我可以在target目录中处理这些类.将引用的依赖项打包为JAR时,一切都很好.现在,我面临着需要以特殊方式进行类处理的AAR依赖关系.到目前为止,我得到的错误是:

I use Maven and I need to process classes from another dependencies. Before processing the classes, maven-dependency-plugin is used to unpack those dependencies with the unpack-dependencies goal, so then I can process the classes in the target directory. Everything is fine while the referenced dependencies are packaged as JARs. Now I'm faced with an AAR dependency that is required to be class-processed in a special way. The error I get so far is:

Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.10:unpack-dependencies (aars-only) on project app-android: Unknown archiver type: No such archiver: 'aar'. -> [Help 1]

aars-only执行标识符来自下面的配置,但是通常,如果不分割执行,它将给出相同的错误.这是我的maven-dependency-plugin配置,稍后我将其分为两个执行:

The aars-only execution identifier comes from the configuration below, but in general it gives the same error if not splitting the executions. Here is my maven-dependency-plugin configuration I have split later into two executions:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>jars-only</id>
            <phase>process-classes</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeScope>runtime</includeScope>
                <includeGroupIds>foo-group,bar-group</includeGroupIds>
                <includeTypes>jar</includeTypes> <!-- this is necessary to skip AAR dependencies -->
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
            </configuration>
        </execution>
        <execution>
            <id>aars-only</id>
            <phase>process-classes</phase>
            <goals>
                <goal>unpack-dependencies</goal>
            </goals>
            <configuration>
                <includeScope>runtime</includeScope>
                <includeGroupIds>baz-group</includeGroupIds>
                <includeTypes>aar</includeTypes> <!-- hoping this can process AARs as well, but it's just another execution, nothing special -->
                <outputDirectory>${project.build.directory}/classes</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

注释aars-only执行会导致运行时应用程序崩溃,但是由于jars-only执行仅包括jar类型而无法通过构建-

Commenting out the aars-only execution leads to a runtime application crash, but the build passes as the jars-only execution includes the jar type only -- not exactly what I need.

如何将AAR依赖项(baz-group)解压缩到target/classes目录?是否可以通过某种方式配置maven-dependency-plugin,以便它可以接受AAR及其打包的classes.jar?还是有其他方法可以使其仅使用另一个插件就可以工作?

How do I unpack the AAR dependency (baz-group) to the target/classes directory? Is it possible to configure the maven-dependency-plugin somehow so it could accept AAR and its packed classes.jar? Or is there any other way to make it work probably just using another plugin?

(也许这是一个有用的提示:我也使用com.simpligility.maven.plugins:android-maven-plugin.)

(Maybe it's a useful hint: I also use com.simpligility.maven.plugins:android-maven-plugin.)

推荐答案

MDP插件似乎无法与此直接配合使用.

It looks as though the MDP plugin won't work with this directly.

如本主题所述-如何将AAR转换为JAR ,AAR本质上是一个包含其他存档信息的zip.

As pointed out in this thread - How to convert AAR to JAR, the AAR is essentially a zip with other archive information in it.

我可以在这里看到2种可能的方法.

There are 2 possible approaches I can see here.

1)-使用ANT解压缩AAR,找到其中包含的jar文件,然后也使用ANT解压缩.

1) - Use ANT to unzip the AAR, find the jar file contained in it, then unzip with ANT as well.

2)-使用ANT像以前一样解压缩AAR,然后将其复制到中间文件夹,然后使用maven-dependency-plugin解压缩jar.

2) - Use ANT to unzip the AAR as before, then copy it to an intermediate folder, and use the maven-dependency-plugin to unpack the jar.

https://maven.apache.org/guides/mini /guide-using-ant.html

我无法对此进行测试,但是此POM片段可能用作起点.

I'm not able to test this, but this POM snippet might be of use as a starting point.

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
    <execution>
        <id>prepare</id>
        <phase>build</phase>
        <configuration>
            <tasks>
                <unzip src="source/my_archive.aar" dest="output/" />
                <copy file="output/classes.jar" tofile="my_archive.jar"/>

                <!-- 
                     Either extract the jar here, 
                     or place it where the maven dependencies plugin 
                     can find it, and extract it in a later build phase 
                -->
            </tasks>
        </configuration>
        <goals>
            <goal>run</goal>
        </goals>
    </execution>
</executions>

这篇关于如何在Maven中解包AAR依赖项类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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