混淆 module/library
Obfuscating a module/library
我有一个将被应用程序使用的库。这个模块有接口和助手 类.
我怎样才能混淆整个模块,但仍然允许访问所有这些接口和助手 类?
我试过这个:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
然后我发现自己必须在 proguard 中对所有 类 执行 --keep
。有没有我可以添加到 pro guard 的东西,这样我就可以保留所有这些 interfaces/helper-classes 并且仍然将其混淆?
如果您只想让您的库的 public API 不被混淆,您需要指定此 public API。库有多种方法:
为 public API 和实际实现提供单独的包,例如com.example.library
包含 public API,而 com.example.library.internal
包含隐藏的实际实现。
将实际的实现包设为私有
ProGuard 规则将如下所示:
-keep public class com.example.library.* { public protected *; }
这将仅在 com.example.library 包中保留 public 类 及其 public 或受保护的方法/字段。
我有一个将被应用程序使用的库。这个模块有接口和助手 类.
我怎样才能混淆整个模块,但仍然允许访问所有这些接口和助手 类?
我试过这个:
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
然后我发现自己必须在 proguard 中对所有 类 执行 --keep
。有没有我可以添加到 pro guard 的东西,这样我就可以保留所有这些 interfaces/helper-classes 并且仍然将其混淆?
如果您只想让您的库的 public API 不被混淆,您需要指定此 public API。库有多种方法:
为 public API 和实际实现提供单独的包,例如
com.example.library
包含 public API,而com.example.library.internal
包含隐藏的实际实现。将实际的实现包设为私有
ProGuard 规则将如下所示:
-keep public class com.example.library.* { public protected *; }
这将仅在 com.example.library 包中保留 public 类 及其 public 或受保护的方法/字段。