简体   繁体   English

如何以OS独立的方式在Proguard配置中包含rt.jar / classes.jar?

[英]How to include rt.jar/classes.jar in Proguard configuration in an OS independant way?

As described in Proguard's troubleshooting page : 如Proguard的故障排除页面所述

In MacOS X, the run-time classes may be in a different place than on most other platforms. 在MacOS X中,运行时类可能与大多数其他平台上的位置不同。 You'll then have to adapt your configuration, replacing the path <java.home>/lib/rt.jar by <java.home>/../Classes/classes.jar . 然后,您必须调整配置,将路径<java.home>/lib/rt.jar<java.home>/../Classes/classes.jar

So for instance, on non-Mac environments you might have the following in your Proguard config: 因此,例如,在非Mac环境中,Proguard配置中可能包含以下内容:

-libraryjars <java.home>/lib/rt.jar

But for Mac environments you would point to classes.jar . 但是对于Mac环境,您将指向classes.jar


This is fine if this is only ever developed on a Mac, but if this code is checked into version control and shared by developers on multiple OSs and also on a build server running a different OS, it needs to be more flexible. 如果仅在Mac上进行过开发,这很好,但是如果将此代码签入版本控制并由开发人员在多个OS上以及在运行其他OS的构建服务器上共享,则它需要更加灵活。

Is there a way to configure this in Proguard to work no matter what OS it runs on, without requiring users of the code to make filesystem changes ? 是否可以在Proguard中将其配置为可以运行,而不管它在什么操作系统上运行,而无需代码用户更改文件系统

You could define a system variable that depends on the environment and use that: 您可以定义一个取决于环境的系统变量,并使用它:

-libraryjars <runtime.jar>

However, if you are developing for Android: 但是,如果您正在为Android开发:

  • You should not refer to rt.jar or classes.jar , since they contain many java runtime classes that are not present in the Android runtime. 您不应引用rt.jarclasses.jar ,因为它们包含许多Android运行时中不存在的Java运行时类。
  • You should not specify -libraryjars , since the Ant/Eclipse/Gradle build processes already automatically specify all necessary -injars , -outjars , and -libraryjars for you. 您不应该指定-libraryjars ,因为Ant / Eclipse / Gradle构建过程已经为您自动指定了所有必需的-injars-outjars-libraryjars

If you see warnings about missing java runtime classes, you should consider an option like -dontwarn javax.** . 如果看到有关缺少Java运行时类的警告,则应考虑使用-dontwarn javax.**类的选项。 See the ProGuard manual > Troubleshooting > Warning: can't find referenced class . 请参阅ProGuard手册>故障排除> 警告:找不到引用的类

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM