如何导出 AAR 库及其文档? [英] How to export AAR library with its documentation?

查看:16
本文介绍了如何导出 AAR 库及其文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么我的库在构建为 AAR 格式后总是丢失其文档.此外,Android Studio 对代码进行了压缩,即构建前的代码始终与构建成 AAR 格式后的代码不同,没有原始代码.我希望我的库有自己的文档和原始代码.您可以在下面看到不同之处:

I'm wondering why my library always lost its documentation once it was built to AAR format. Also, Android Studio shrinks the code, i.e. the code before built always different with the code after built into AAR format, none originals. I want my library to has its own documentation and has the original code. You can see the different below:

建成前

内置成AAR格式后

文档在哪里?!此外,您会注意到整个代码确实缩小了并且有所不同.

Where is the documentation?! Also, you'll notice that the whole code are really shrunk and different.

那么,如何在不压缩代码的情况下导出 AAR 库及其文档?

推荐答案

代码缩小",因为一旦您创建了 AAR 原始源代码不包含在 AAR 中.这只是 Java 字节码.

The code "shrinks" because once you create the AAR the original source code isn't included in the AAR. It's just the Java byte code.

然后当您在应用中使用 AAR 库时.源代码是从字节码逆向工程.原始变量名不可用,并且由于字节码编译器的优化等原因,可能存在一些编码风格差异.当然,注释不包含在字节码中,因为它是给计算机的,而注释是给人的.

Then when you use your AAR library in an app. the source code is reverse engineered from the byte code. The original variable names are not available and there can be some coding style differences due to byte code compiler's optimizations and whatnot. And of course the comments are not included in the byte code because it's for the computer and the comments are for the people.

因此,在使用 AAR 库时,如果您不想在调试时看到原始源代码等.您需要将它与 AAR 作为单独的源 JAR 一起交付,并且可能会告诉 Android Studio 使用源 JAR(如果没有)不要自动执行.

So when using the AAR library if you wan't to see the original source code when debugging etc. you need to deliver it with the AAR as a separate source JAR and probably tell Android Studio to use the source JAR if it doesn't do it automatically.

作为将生成的 AAR/JAR上传"到本地 Maven 存储库的过程的一部分,我已经能够自动创建源 JAR.我不知道你有什么样的构建系统,所以我不会详细介绍.

I've been able to automate the source JAR creation as part of a process of "uploading" the generated AAR/JAR to a local Maven repository. I don't know what kind of a build system you have so I won't go into those details.

无论如何,您都可以将其添加到模块的 build.gradle 中:

Anyway you can add this to your modules's build.gradle:

task sourcesJar(type: Jar) {
    classifier = 'sources'
    from android.sourceSets.main.java.srcDirs
}

然后,只要您想创建/更新源 JAR,就需要单独运行它:

You'll then need to run it separately whenever you want to create/update the source JAR:

Gradle -> 任务 -> 其他 -> 源文件

Gradle -> Tasks -> Other -> sourcesJar

也许有一些方法可以使任务自动化,成为 assembleRelease 任务的一部分,但我对 Gradle 还不是很熟悉.

And probably there's some way to automate the task to be part of the assembleRelease task but I'm not very much familiar with Gradle yet.

源 JAR 将出现在 ...\MyLibrary\app\build\libs\ 路径中.

The source JAR will appear in the ...\MyLibrary\app\build\libs\ path.

这篇关于如何导出 AAR 库及其文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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