在 Android Studio 中显示混淆的 android 库 (AAR) 的 API 源

问题描述

我目前正在开发一个具有以下包层次结构的 android 库项目:

com.example
    |_______ api (contains the public interface of the library)
    |_______ internal (contains the remaining internal classes)

不幸的是,我需要混淆内部类。这会导致以下 proguard-rules.pro 文件

# preserve the line number @R_518_4045@ion for stack traces and android studio integration
-keepattributes SourceFile,LineNumberTable

# hide the original source file name. (<--- This messes up android-studio integration)
-renamesourcefileattribute SourceFile

# Preserve @R_518_4045@ion about throwing exceptions and deprecation of methods
-keepattributes Exceptions,Deprecated,Signature

# Preserve the original parameter names of kept methods
-keepparameternames

# Keeps the names of all public/protected classes/fields/methods in the api package
-keep public class com.example.api.* {
  public protected *;
}

生成的库作为 AAR 发布到包注册表中,并且可以使用 gradle 进行集成。 为了在 android-studio 中获得良好的用户体验(javadocs 作为工具提示,单击类型/方法/等时快速查找代码),我还发布了一个包含源代码的 jar 和一个包含 javadocs 的 jar(当然仅用于com.example.api 包内的类)。

问题是,如果我使用 -renamesourcefileattribute,Android-Studio 不会显示相应类的源。

这意味着,它们不会显示在编辑器窗口中。而是显示了反编译的类文件。另一方面,JavaDoc 工具提示按预期工作。请注意:源 jar 和 javadoc jar 都显示在 aar 的库属性中,表明 android studio 正确地将源 jar 附加到了 aar。

如果源文件属性重命名,则一切正常。 不幸的是,这不是一个选项,因为它会大大削弱对内部类的混淆。

编辑:就像附加信息一样:使用的收缩器是 R8(认的)。

有没有人知道如何解决这个问题?提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)