Proguard 不会在 ZipEntry 中保留包层次结构
Proguard does not keep package hierarchy in ZipEntry
我使用混淆器混淆了我的代码。在代码中,我想使用以下代码从指定包中读取所有 classes。
URL directoryURL = Thread.currentThread().getContextClassLoader()
.getResource("com/test/ui/controller");
此代码无效,因为 proguard 创建的 jar 不保留包层次结构。我写了一个代码,从混淆的 jar.This 输出中读取条目。
看到 class 包没有保存在 zip 文件中。所以 getResource() 不起作用。
com/test/ui/controller/a.class
com/test/ui/controller/c.class
com/test/ui/controller/b.class
com/test/ui/controller/d.class
当我 运行 使用未混淆的 jar 的相同代码时,这里是输出。包级别保持在 jar.Do 你知道我如何告诉 Proguard 通过保持包级别来创建 jar。
com/
com/test/
com/test/ui/
com/test/ui/控制器/
com/test/ui/controller/a.class
com/test/ui/controller/c.class
com/test/ui/controller/b.class
com/test/ui/controller/d.class
-keeppackagenames [package_filter]
Specifies not to obfuscate the given package names. The optional filter is a comma-separated list of package names. Package names can
contain ?, *, and ** wildcards, and they can be preceded by the !
negator. Only applicable when obfuscating.
(来源:http://proguard.sourceforge.net/manual/usage.html#obfuscationoptions)
-keepdirectories 解决了我的问题。
Specifies the directories to be kept in the output jars (or aars,
wars, ears, zips, apks, or directories). By default, directory entries
are removed. This reduces the jar size, but it may break your program
if the code tries to find them with constructs like
"mypackage.MyClass.class.getResource("")". You'll then want to keep
the directory corresponding to the package, "-keepdirectories
mypackage". If the option is specified without a filter, all
directories are kept. With a filter, only matching directories are
kept. For instance, "-keepdirectories mydirectory" matches the
specified directory, "-keepdirectories mydirectory/*" matches its
immediate subdirectories, and "-keepdirectories mydirectory/**"
matches all of its subdirectories.
我使用混淆器混淆了我的代码。在代码中,我想使用以下代码从指定包中读取所有 classes。
URL directoryURL = Thread.currentThread().getContextClassLoader()
.getResource("com/test/ui/controller");
此代码无效,因为 proguard 创建的 jar 不保留包层次结构。我写了一个代码,从混淆的 jar.This 输出中读取条目。 看到 class 包没有保存在 zip 文件中。所以 getResource() 不起作用。
com/test/ui/controller/a.class
com/test/ui/controller/c.class
com/test/ui/controller/b.class
com/test/ui/controller/d.class
当我 运行 使用未混淆的 jar 的相同代码时,这里是输出。包级别保持在 jar.Do 你知道我如何告诉 Proguard 通过保持包级别来创建 jar。
com/
com/test/
com/test/ui/
com/test/ui/控制器/
com/test/ui/controller/a.class
com/test/ui/controller/c.class
com/test/ui/controller/b.class
com/test/ui/controller/d.class
-keeppackagenames [package_filter]
Specifies not to obfuscate the given package names. The optional filter is a comma-separated list of package names. Package names can contain ?, *, and ** wildcards, and they can be preceded by the ! negator. Only applicable when obfuscating.
(来源:http://proguard.sourceforge.net/manual/usage.html#obfuscationoptions)
-keepdirectories 解决了我的问题。
Specifies the directories to be kept in the output jars (or aars, wars, ears, zips, apks, or directories). By default, directory entries are removed. This reduces the jar size, but it may break your program if the code tries to find them with constructs like "mypackage.MyClass.class.getResource("")". You'll then want to keep the directory corresponding to the package, "-keepdirectories mypackage". If the option is specified without a filter, all directories are kept. With a filter, only matching directories are kept. For instance, "-keepdirectories mydirectory" matches the specified directory, "-keepdirectories mydirectory/*" matches its immediate subdirectories, and "-keepdirectories mydirectory/**" matches all of its subdirectories.