如何转换为apklib AAR [英] How to convert apklib to aar

查看:508
本文介绍了如何转换为apklib AAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于摇篮不支持 apklib 依赖一个人如何可以从 apklib 依赖迁移到 AAR 的依赖?是否可以手动或自动转换 apklib 依赖于 AAR ?如果是 - 怎么样,如果没有 - 为什么不呢?

As Gradle does not support apklib dependencies how can one migrate from apklib dependencies to aar dependencies? Is it possible to either manually or automatically convert apklib dependency to aar? If yes - how, if no - why not?

在这个问题,我认为我没有为 apklib 原项目,而是文件本身。

In this question I assume that I don't have original project for apklib, but rather the file itself.

推荐答案

apklib不包含目标文件,只有源文件,所以唯一的办法就可以被包含在任何项目是通过重新编译它。据一些文档你可以阅读:

apklib doesn't contain object files, only source files, so the only way it can be included in any project is by recompiling it. According to some docs you can read at:

Android的依赖关系:apklib VS AAR文件和<一个href=\"https://plus.google.com/+ChristopherBroadfoot/posts/7uyipf8DTau\">https://plus.google.com/+ChristopherBroadfoot/posts/7uyipf8DTau

该apklib格式的发明者,以此来分享的Andr​​oid code +资源。它本质上是一个压缩了的Andr​​oid库项目,这已经是现状为code +资源共享。

The apklib format was invented as a way to share Android code+resources. It’s essentially a zipped up Android library project, which was already the status quo for code+resource sharing.

和您可以在克里斯布罗德福特的帖子看到,产生apklib只是拉链了的Andr​​oidManifest.xml 文件和的src RES 目录:

And you can see in Chris Broadfoot's post that the task that generates the apklib just zips up the AndroidManifest.xml file and the src and res directories:

task apklib(type: Zip) {
    appendix = extension = 'apklib'

    from 'AndroidManifest.xml'
    into('res') {
        from 'res'
    }
    into('src') {
        from 'src'
    }
}

请注意,他的文章是关​​于创建从摇篮,这是想要做一个稍微奇怪的事情了apklib,但它提供了pretty的这些东西是如何结构清晰的概念。

Note that his post is about creating an apklib from Gradle, which is a slightly weird thing to want to do, but it provides a pretty clear idea of how one of these things is structured.

好消息是,这是标准的Andr​​oid项目结构时的Eclipse是主IDE的,和Android工作室知道如何导入这个样子的模块。所以,请按照下列步骤操作:

The good news is that this is "standard" Android project structure as of when Eclipse was the primary IDE, and Android Studio knows how to import modules that look like this. So follow these steps:


  1. 包装打开apklib到一个临时目录。它在zip格式,所以像解压library.apklib 应该工作。

看看有哪些解压缩。你应该看到一个包含目录的Andr​​oidManifest.xml 的src RES 文件夹。

Look at what's unpacked. You should see a directory containing AndroidManifest.xml, src, and res folders.

在Android的工作室,现有项目中,选择File> Import模块,并在该目录从步骤2点吧。

In Android Studio, inside an existing project, choose File > Import Module and point it at the directory from step 2.

Android的工作室应该复制文件到您的项目在一个新的模块,在其preferred目录结构安排他们管理的进口,并会添加一个的build.gradle 文件模块。

Android Studio should manage the import by copying the files into your project in a new module, arranging them in its preferred directory structure, and will add a build.gradle file for the module.

在这一点上你是启动和运行。如果你真的想在 .aar 文件,然后检查,看看你的新的模块被设置为一个库模块或应用程序模块。在其的build.gradle ,如果你有应用插件:'com.android.library那么它是一个库模块和摇篮将生成一个 .aar 作为构建的一部分:它会在建/输出/ AAR 成功构建后的目录。

At this point you're up and running. If you actually want the .aar file, then check to see if your new module is set up as a library module or an application module. In its build.gradle, if you've got apply plugin: 'com.android.library' then it's a library module, and Gradle will generate an .aar as part of the build: it will be in the build/outputs/aar directory after a successful build.

如果您的模块导入为一个应用程序模块,而不是一个库(应用插件:'com.android.application,然后更改应用插件语句,你可能还需要从构建文件中删除的applicationID 语句。现在应该编译为库并生成一个 .aar

If your module imported as an app module and not a library (apply plugin: 'com.android.application', then change that apply plugin statement, and you may also need to remove the applicationId statement from the build file. Now it should compile as a library and generate a .aar.

编程快乐!

这篇关于如何转换为apklib AAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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