proguard模糊处理

pbgvytdp  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(393)

我正在使用com.pyx4me.proguard-maven-plugin对多模块项目中的代码进行模糊处理。如何模糊依赖于来自不同(模糊化)模块的“friend”方法的模块?我希望保留基本模块的所有内容,但在从属模块中尽可能缩小/优化。我尝试了各种各样的“keep*”、“dontoptimize”和“dontshrink”选项,但似乎都没有任何帮助。交叉过帐自https://groups.google.com/forum/#!topic/pyx4me用户/1aum9xsqkly。

上述项目结构产生以下错误:

  1. [proguard] Warning: test.Bar: can't find referenced method 'void x()' in class test.Foo
  2. [proguard] Warning: there were 1 unresolved references to program class members.
  3. [proguard] Your input classes appear to be inconsistent.

/testproj/pom.xml文件

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <groupId>group</groupId>
  5. <artifactId>testproj</artifactId>
  6. <version>1.0.0.0</version>
  7. <packaging>pom</packaging>
  8. <name>testproj</name>
  9. <properties>
  10. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  11. </properties>
  12. <modules>
  13. <module>testproj.a</module>
  14. <module>testproj.b</module>
  15. </modules>
  16. </project>

/testproj/testproj.a/pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>group</groupId>
  6. <artifactId>testproj.a</artifactId>
  7. <version>1.0-SNAPSHOT</version>
  8. <packaging>jar</packaging>
  9. <name>testproj.a</name>
  10. <properties>
  11. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  12. </properties>
  13. <build>
  14. <plugins>
  15. <plugin>
  16. <groupId>org.apache.maven.plugins</groupId>
  17. <artifactId>maven-compiler-plugin</artifactId>
  18. <version>2.3.2</version>
  19. <configuration>
  20. <source>1.7</source>
  21. <target>1.7</target>
  22. </configuration>
  23. </plugin>
  24. <plugin>
  25. <groupId>org.apache.maven.plugins</groupId>
  26. <artifactId>maven-jar-plugin</artifactId>
  27. <version>2.4</version>
  28. <configuration>
  29. <archive>
  30. <index>true</index>
  31. <manifest>
  32. <classpathPrefix>lib/</classpathPrefix>
  33. <addClasspath>true</addClasspath>
  34. <mainClass>com.holliswaite.swmf.FontTableModel</mainClass>
  35. </manifest>
  36. </archive>
  37. </configuration>
  38. </plugin>
  39. <plugin>
  40. <groupId>org.apache.maven.plugins</groupId>
  41. <artifactId>maven-dependency-plugin</artifactId>
  42. <version>2.2</version>
  43. <executions>
  44. <execution>
  45. <id>copy-dependencies</id>
  46. <phase>package</phase>
  47. <goals>
  48. <goal>copy-dependencies</goal>
  49. </goals>
  50. <configuration>
  51. <outputDirectory>${project.build.directory}/lib</outputDirectory>
  52. <overWriteReleases>true</overWriteReleases>
  53. <overWriteSnapshots>true</overWriteSnapshots>
  54. <overWriteIfNewer>true</overWriteIfNewer>
  55. </configuration>
  56. </execution>
  57. </executions>
  58. </plugin>
  59. <plugin>
  60. <groupId>com.pyx4me</groupId>
  61. <artifactId>proguard-maven-plugin</artifactId>
  62. <executions>
  63. <execution>
  64. <phase>package</phase>
  65. <goals>
  66. <goal>proguard</goal>
  67. </goals>
  68. </execution>
  69. </executions>
  70. <configuration>
  71. <options>
  72. <option>-keep class * {*;}</option>
  73. </options>
  74. <libs>
  75. <lib>${java.home}/lib/rt.jar</lib>
  76. <lib>${java.home}/lib/jsse.jar</lib>
  77. </libs>
  78. </configuration>
  79. <dependencies>
  80. <dependency>
  81. <groupId>net.sf.proguard</groupId>
  82. <artifactId>proguard</artifactId>
  83. <version>4.8</version>
  84. <scope>runtime</scope>
  85. </dependency>
  86. </dependencies>
  87. </plugin>
  88. </plugins>
  89. </build>
  90. </project>

/testproj/testproj.b/pom.xml

  1. <project xmlns="http://maven.apache.org/POM/4.0.0"
  2. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <groupId>group</groupId>
  6. <artifactId>testproj.b</artifactId>
  7. <version>1.0-SNAPSHOT</version>
  8. <packaging>jar</packaging>
  9. <name>testproj.b</name>
  10. <properties>
  11. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  12. </properties>
  13. <dependencies>
  14. <dependency>
  15. <groupId>${project.groupId}</groupId>
  16. <artifactId>testproj.a</artifactId>
  17. <version>1.0-SNAPSHOT</version>
  18. </dependency>
  19. </dependencies>
  20. <build>
  21. <plugins>
  22. <plugin>
  23. <groupId>org.apache.maven.plugins</groupId>
  24. <artifactId>maven-compiler-plugin</artifactId>
  25. <version>2.3.2</version>
  26. <configuration>
  27. <source>1.7</source>
  28. <target>1.7</target>
  29. </configuration>
  30. </plugin>
  31. <plugin>
  32. <groupId>org.apache.maven.plugins</groupId>
  33. <artifactId>maven-jar-plugin</artifactId>
  34. <version>2.4</version>
  35. <configuration>
  36. <archive>
  37. <index>true</index>
  38. <manifest>
  39. <classpathPrefix>lib/</classpathPrefix>
  40. <addClasspath>true</addClasspath>
  41. <mainClass>com.holliswaite.swmf.SWMFFrame</mainClass>
  42. </manifest>
  43. </archive>
  44. </configuration>
  45. </plugin>
  46. <plugin>
  47. <groupId>org.apache.maven.plugins</groupId>
  48. <artifactId>maven-dependency-plugin</artifactId>
  49. <version>2.2</version>
  50. <executions>
  51. <execution>
  52. <id>copy-dependencies</id>
  53. <phase>package</phase>
  54. <goals>
  55. <goal>copy-dependencies</goal>
  56. </goals>
  57. <configuration>
  58. <outputDirectory>${project.build.directory}/lib</outputDirectory>
  59. <overWriteReleases>true</overWriteReleases>
  60. <overWriteSnapshots>true</overWriteSnapshots>
  61. <overWriteIfNewer>true</overWriteIfNewer>
  62. </configuration>
  63. </execution>
  64. </executions>
  65. </plugin>
  66. <plugin>
  67. <groupId>com.pyx4me</groupId>
  68. <artifactId>proguard-maven-plugin</artifactId>
  69. <executions>
  70. <execution>
  71. <phase>package</phase>
  72. <goals>
  73. <goal>proguard</goal>
  74. </goals>
  75. </execution>
  76. </executions>
  77. <configuration>
  78. <options>
  79. <option>-allowaccessmodification</option>
  80. <option>-keep public class test.Bar {*;}</option>
  81. </options>
  82. <libs>
  83. <lib>${java.home}/lib/rt.jar</lib>
  84. <lib>${java.home}/lib/jsse.jar</lib>
  85. </libs>
  86. </configuration>
  87. <dependencies>
  88. <dependency>
  89. <groupId>net.sf.proguard</groupId>
  90. <artifactId>proguard</artifactId>
  91. <version>4.8</version>
  92. <scope>runtime</scope>
  93. </dependency>
  94. </dependencies>
  95. </plugin>
  96. </plugins>
  97. </build>
  98. </project>

/testproj/testproj.a/src/main/java/test/foo.java

  1. package test;
  2. public class Foo {
  3. void x() {}
  4. public void y() {}
  5. }

/testproj/testproj.b/src/main/java/test/bar.java

  1. package test;
  2. public class Bar {void z() {(new Foo()).x();}}

引用 y() 工作正常,但打电话 x() 导致错误。

uyto3xhc

uyto3xhc1#

使用 -dontskipnonpubliclibraryclassmembers 选项(在testproj.b/pom.xml中)。

相关问题