简体   繁体   English

ProGuard可以将访问修饰符更改为程序包专用吗?

[英]Can ProGuard change access modifers to package-private?

Is it possible, using ProGuard, to move all your obfuscated classes to a named package and change their public or protected methods or member variables to package protected? 是否可以使用ProGuard将所有混淆的类移动到命名包,并将其公共或受保护的方法或成员变量更改为受保护的包?

I know you can use -repackageclasses to move the classes, but it seems -allowaccessmodification changes access modifiers to public. 我知道您可以使用-repackageclasses移动类,但是-allowaccessmodification似乎将访问修饰符更改为public。 The goal is to prevent users of my library from being able to use anything but the exposed public API. 目的是防止我的图书馆用户只能使用公开的公共API之外的任何东西。 Any help is appreciated. 任何帮助表示赞赏。

Edit: I meant package-private not package-protected. 编辑:我的意思是包私有而不是包保护的。

I don't think you can, and I don't think you should. 我认为您不能,我也不应该。 When classes are compiled and code won't change, relaxing the object/method qualifiers won't alter access patterns; 当类被编译并且代码不会改变时,放宽对象/方法限定符不会改变访问模式。 in other words, an object that successfully called a protected method/object would still have access to it if the qualifier is changed to public . 换句话说,如果将限定符更改为public ,则成功调用protected方法/对象的对象仍然可以访问它。 The opposite is not true; 相反的事实是不正确的。 a public object/method that turns protected could become invisible/inaccessible to the calling object all of a sudden - rendering badly compiled code. 变成protectedpublic对象/方法可能突然变得对调用对象不可见/不可访问-导致编译不良的代码。 I have used ProGuard before, but my answer is based on logic rather than experimentation. 我以前使用过ProGuard,但是我的回答是基于逻辑而不是实验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 IntelliJ 中禁用“访问可以是包私有的”消息? - How to disable "Access can be package-private" message in IntelliJ? 对于@Transactional方法,禁用警告“Access可以是包私有” - Disable warning “Access can be package-private” for @Transactional methods 在Eclipse中将package-private变量更改为private - Change package-private variable to private in Eclipse 防止混淆在Maven模块之间共享的包私有成员 - proguard obfuscation of package-private members shared across maven modules Proguard / R8 规则保持包私有 class 成员 - Proguard / R8 rule to keep package-private class members 应用程序类可以是包私有的吗? - Can Application class be package-private? 为什么我无法访问android.widget包中的package-private字段? - Why can't I access package-private fields in the android.widget package? Spring @Autowired 字段 - 哪个访问修饰符是私有的还是包私有的? - Spring @Autowired fields - which access modifier, private or package-private? 发生包冲突时的Java包私有访问修饰符行为 - Java package-private access modifier behavior in case of package collision 为什么私有访问方法比package-private更可取? - Why private access for methods is more preferable than package-private?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM