RELASE AAR不包含任何代码Android?

发布于 2025-01-18 10:49:05 字数 402 浏览 3 评论 0 原文

我正在使用Android Studio Bumble Bee 时,该库具有单个类,

class Lib2 {

fun print(){
    println("From lib2")
}
}

我创建了一个模块库,该模块库在

-keepclasseswithmembers class com.example.lib2.Lib2{
    public <methods>;
    public <fields>;
}

使用 minifyEnabled true 创建版本的AAR

但是当我将AAR集成到App Module时,我没有得到 lib2 。这里怎么了?

I am using android studio bumble bee
I created a module library which has a single class

class Lib2 {

fun print(){
    println("From lib2")
}
}

The proguard as

-keepclasseswithmembers class com.example.lib2.Lib2{
    public <methods>;
    public <fields>;
}

I create the release aar with minifyEnabled true

However when I integrate the aar with my app module I am not getting Lib2. What is wrong here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ゃ懵逼小萝莉 2025-01-25 10:49:05

来自文档

在所有指定的类成员都存在的条件下指定要保留的类和类成员。例如,您可能需要保留所有具有主要方法的应用程序,而不必明确列出它们。

在英语中,它的意思是“不要混淆具有以下方法和字段结构的类”。

例如,保留所有具有单个构造函数的类上下文参数:

-keepclasseswithmembers class * { 
    public <init>(android.content.Context); 
} 

从我的理解来看,您只想保留整个课程,就可以使用:

-keep public class com.example.lib2.Lib2

我认为,最好使用@keep 直接在课堂中发出通知,因为:

  1. proguard规则与源相关,随着时间的流逝,我们忘记了规则在那里。通过使用 @keep ,您立即知道混淆中要保留哪些类,并且更可读性。
  2. 此注释带有您的AAR,因此当您发布它时,消费者应用程序也不会混淆它。借助Proguard规则,您必须添加另一个规则文件与您的AAR包装,该文件“告诉”消费者应用程序不要混淆此类。

更简单:

@Keep
class Lib2 {

    fun print(){
        println("From lib2")
    }

}

From documentation:

Specifies classes and class members to be preserved, on the condition that all of the specified class members are present. For example, you may want to keep all applications that have a main method, without having to list them explicitly.

In English it means "Don't obfuscate classes that have the following methods and fields structure".

For example, keeping all classes which have constructors with single Context parameter:

-keepclasseswithmembers class * { 
    public <init>(android.content.Context); 
} 

Since, from my understanding, you simply want to keep the whole class, you can use:

-keep public class com.example.lib2.Lib2

In my opinion, it's better to use @Keep annnotation directly in the class, because:

  1. The proguard rules is decoupled from source and as the time flies we forget that the rule is there. by using @Keep you know immediately what classes are being kept from obfuscation and it's much more readable.
  2. This annotation is packed with your AAR so when you publish it, consumer apps won't obfuscate it as well. With proguard rules you must add another rules file to pack with your AAR that "tells" the consumer app to not obfuscate this class.

Much more simple:

@Keep
class Lib2 {

    fun print(){
        println("From lib2")
    }

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文