来自这个引用:
https://github.com/codepath/android_guides/wiki/Building-your-own-Android-library
我有以下 gradle 文件:
android {
compileSdkVersion 25
buildToolsVersion "26.0.2"
buildTypes {
release {
minifyEnabled true
consumerProguardFiles 'consumer-proguard-rules.pro'
}
}
}
以及以下混淆文件:
-dontobfuscate
-optimizations !code/allocation/variable
-keep public class * {
public protected *;
}
但是,当我运行“assembleRelease”任务来构建我的发布 aar 文件时,我在 aar 中的所有类都丢失了。
有什么想法吗?
最佳答案
您应该将 minifyEnabled
设置为 false
(默认值):
consumerProguardFiles
不用于立即缩小(即在构建库本身时)。它在构建库的使用者(例如应用程序)时使用。
不建议在使用前压缩库,因为在最终构建之前你无法知道哪些部分将被实际使用。图书馆通常不这样做。例如LeakCanary , ACRA , Butter Knife
关于android - Proguard 在构建 aar 时不保留类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48067344/