我想使用ProGuard对Java JAR文件进行模糊处理和优化。 JAR文件是JDBC和SQLite的自编写类和导入类的集合。
导入的类不必进行模糊处理,但可以进行优化。如果有一个配置可以混淆所有并优化所有和一个配置,只是优化和混淆我的代码并保持导入的类不受影响,那将是很好的。
我做了一些研究并尝试了不同的配置来实现这一点但失败了,ProGuard显示了许多警告和几个错误,我尝试更改脚本没有或几乎没有效果。
我在Eclipse中开发并使用Ant build.xml
文件来完成工作。
有人知道应该怎么做吗?
这是我的Ant构建文件:
<?xml version="1.0" ?>
<project name="Ant-ProGuard-Build" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="docs.dir" location="docs" />
<property name="lib.dir" location="lib" />
<!-- Define external resources -->
<taskdef resource="proguard/ant/task.properties"
classpath="C:\eclipse\ProGuard-4.8\lib\proguard.jar" />
<target name="main" depends="compile, jar, obfuscate"
description="Create project">
</target>
<echo>-== Creating project ==-</echo>
<!-- Compiles the java code (including the usage of library for JUnit -->
<target name="compile" description="Compile target">
<javac srcdir="${src.dir}" destdir="${build.dir}">
</javac>
</target>
<!--Creates the deployable jar file -->
<target name="jar" depends="compile">
<jar destfile="${dist.dir}\Myprogram_Ant.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="se.me.myprogram.main.ProgMain" />
</manifest>
<zipgroupfileset dir="./lib" includes="**/*.jar" />
</jar>
</target>
<target name="obfuscate" depends="compile, jar"
description="Obfuscate compiled classes">
<proguard>
-libraryjars "${java.home}\lib\rt.jar"
-libraryjars "${lib.dir}\mysql-connector-java-5.1.22-bin.jar"
-libraryjars "${lib.dir}\sqlite-jdbc-3.7.15-SNAPSHOT.jar"
-injars "${dist.dir}\StockWatch_Ant.jar"
-outjars "${dist.dir}\StockWatch_ProGuard.jar"
# All entry points will be in this package
-keep public class se.me.myprogram.main.*
-keepclassmembers public class se.me.myprogram.main.ProgMain {
public static void main(java.lang.String[]);
}
# Keep the imported classes public
-keep public class com.mysql.**
-keep public class org.**
</proguard>
</target>
<echo>---------- Creation of project is done! ----------</echo>
我得到的错误是:
Buildfile: C:\ECLIPSE-WORKSPACE\MyProgram\Ant_ProGuard_Build.xml
[echo] -== Creating project ==-
[echo] ---------- Creation of project is done! ----------
compile:
[javac] C:\ECLIPSE-WORKSPACE\MyProgram\Ant_ProGuard_Build.xml:29: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=last; set to false for repeatable builds
jar:
obfuscate:
[proguard] ProGuard, version 4.8
[proguard] Reading program jar [C:\ECLIPSE-WORKSPACE\MyProgram\dist\MyProgram_Ant.jar]
[proguard] Reading library jar [C:\Program Files\Java\jre7\lib\rt.jar]
[proguard] Warning: com.mysql.jdbc.integration.c3p0.MysqlConnectionTester: can't find superclass or interface com.mchange.v2.c3p0.QueryConnectionTester
[proguard] Warning: com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter: can't find superclass or interface org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
[proguard] Warning: com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker: can't find superclass or interface org.jboss.resource.adapter.jdbc.ValidConnectionChecker
[proguard] Warning: org.sqlite.SQLite: can't find superclass or interface org.ibex.nestedvm.UnixRuntime
[proguard] Warning: com.mysql.jdbc.integration.c3p0.MysqlConnectionTester: can't find referenced class com.mchange.v2.c3p0.C3P0ProxyConnection
[proguard] Warning: com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter: can't find referenced class org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
[proguard] Warning: com.mysql.jdbc.log.Slf4JLogger: can't find referenced class org.slf4j.LoggerFactory
.
80 lines... with same message : "[proguard] Warning: ......: can't find referenced class ....."
.
[proguard] Warning: org.sqlite.SQLite: can't find referenced class org.ibex.nestedvm.Runtime$CPUState
[proguard] Warning: org.sqlite.SQLite: can't find referenced class org.ibex.nestedvm.Runtime$CPUState
[proguard] Note: com.mysql.jdbc.SQLError calls '(java.sql.SQLException)Class.forName(variable).newInstance()'
[proguard] Note: com.mysql.jdbc.CallableStatement accesses a constructor '<init>(com.mysql.jdbc.MySQLConnection,com.mysql.jdbc.CallableStatement$CallableStatementParamInfo)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.CallableStatement { CallableStatement(com.mysql.jdbc.MySQLConnection,com.mysql.jdbc.CallableStatement$CallableStatementParamInfo); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4CallableStatement { JDBC4CallableStatement(com.mysql.jdbc.MySQLConnection,com.mysql.jdbc.CallableStatement$CallableStatementParamInfo); }'
[proguard] Note: com.mysql.jdbc.DatabaseMetaData accesses a constructor '<init>(com.mysql.jdbc.MySQLConnection,java.lang.String)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.DatabaseMetaData { DatabaseMetaData(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.DatabaseMetaDataUsingInfoSchema { DatabaseMetaDataUsingInfoSchema(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4DatabaseMetaData { JDBC4DatabaseMetaData(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4DatabaseMetaDataUsingInfoSchema { JDBC4DatabaseMetaDataUsingInfoSchema(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4PreparedStatement { JDBC4PreparedStatement(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.PreparedStatement { PreparedStatement(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.StatementImpl { StatementImpl(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Note: com.mysql.jdbc.DatabaseMetaData accesses a constructor '<init>(com.mysql.jdbc.MySQLConnection,java.lang.String)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.DatabaseMetaData { DatabaseMetaData(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.DatabaseMetaDataUsingInfoSchema { DatabaseMetaDataUsingInfoSchema(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4DatabaseMetaData { JDBC4DatabaseMetaData(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4DatabaseMetaDataUsingInfoSchema { JDBC4DatabaseMetaDataUsingInfoSchema(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4PreparedStatement { JDBC4PreparedStatement(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.PreparedStatement { PreparedStatement(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.StatementImpl { StatementImpl(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Note: com.mysql.jdbc.LoadBalancingConnectionProxy accesses a constructor '<init>(com.mysql.jdbc.LoadBalancingConnectionProxy)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4LoadBalancedMySQLConnection { JDBC4LoadBalancedMySQLConnection(com.mysql.jdbc.LoadBalancingConnectionProxy); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.LoadBalancedMySQLConnection { LoadBalancedMySQLConnection(com.mysql.jdbc.LoadBalancingConnectionProxy); }'
[proguard] Note: com.mysql.jdbc.PreparedStatement accesses a constructor '<init>(com.mysql.jdbc.MySQLConnection,java.lang.String)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.DatabaseMetaData { DatabaseMetaData(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.DatabaseMetaDataUsingInfoSchema { DatabaseMetaDataUsingInfoSchema(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4DatabaseMetaData { JDBC4DatabaseMetaData(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4DatabaseMetaDataUsingInfoSchema { JDBC4DatabaseMetaDataUsingInfoSchema(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.JDBC4PreparedStatement { JDBC4PreparedStatement(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.PreparedStatement { PreparedStatement(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.StatementImpl { StatementImpl(com.mysql.jdbc.MySQLConnection,java.lang.String); }'
[proguard] Note: com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection accesses a constructor '<init>(com.mysql.jdbc.Connection)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.ProfilerEventHandlerFactory { ProfilerEventHandlerFactory(com.mysql.jdbc.Connection); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.jdbc2.optional.JDBC4MysqlPooledConnection { JDBC4MysqlPooledConnection(com.mysql.jdbc.Connection); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection { MysqlPooledConnection(com.mysql.jdbc.Connection); }'
[proguard] Note: com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection accesses a constructor '<init>(com.mysql.jdbc.ConnectionImpl)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.ConnectionImpl$10 { ConnectionImpl$10(com.mysql.jdbc.ConnectionImpl); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection { JDBC4SuspendableXAConnection(com.mysql.jdbc.ConnectionImpl); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.jdbc2.optional.SuspendableXAConnection { SuspendableXAConnection(com.mysql.jdbc.ConnectionImpl); }'
[proguard] Note: com.mysql.jdbc.log.LogFactory accesses a constructor '<init>(java.lang.String)' dynamically
[proguard] Maybe this is program method 'com.mysql.jdbc.ConnectionGroup { ConnectionGroup(java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.EscapeTokenizer { EscapeTokenizer(java.lang.String); }'
[proguard] Maybe this is program method 'com.mysql.jdbc.MiniAdmin { MiniAdmin(java.lang.String); }'
.
.
.
1040 lines... with same message : "[proguard] Maybe this is program method....."
.
.
.
[proguard] Maybe this is library method 'sun.util.locale.LocaleSyntaxException { LocaleSyntaxException(java.lang.String); }'
[proguard] Note: there were 1 class casts of dynamically created class instances.
[proguard] You might consider explicitly keeping the mentioned classes and/or
[proguard] their implementations (using '-keep').
[proguard] Note: there were 8 accesses to class members by means of introspection.
[proguard] You should consider explicitly keeping the mentioned class members
[proguard] (using '-keep' or '-keepclassmembers').
[proguard] Warning: there were 50 unresolved references to classes or interfaces.
[proguard] You may need to specify additional library jars (using '-libraryjars').
[proguard] Warning: there were 6 unresolved references to program class members.
[proguard] Your input classes appear to be inconsistent.
[proguard] You may need to recompile them and try again.
[proguard] Alternatively, you may have to specify the option
[proguard] '-dontskipnonpubliclibraryclassmembers'.
BUILD FAILED
C:\ECLIPSE-WORKSPACE\MyProgram\Ant_ProGuard_Build.xml:49: Please correct the above warnings first.
Total time: 7 seconds