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

查看:334
本文介绍了如何导出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-> Tasks-> Other-> sourcesJar

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天全站免登陆