Implement proguard support

This commit is contained in:
Ben Gruver 2012-09-15 22:56:10 -07:00
parent 5cf9fe7c0a
commit c9afead1a9
3 changed files with 83 additions and 22 deletions

View File

@ -1,12 +1,15 @@
configurations {
proguard
}
dependencies { dependencies {
compile project(':util') compile project(':util')
compile project(':dexlib') compile project(':dexlib')
compile 'commons-cli:commons-cli:1.2' compile 'commons-cli:commons-cli:1.2'
compile 'com.google.code.findbugs:jsr305:1.3.9' compile 'com.google.code.findbugs:jsr305:1.3.9'
}
processResources.inputs.properties('version': { -> version}) proguard 'net.sf.proguard:proguard-base:4.8'
processResources.expand('version': { -> version}) }
// We have to do this in taskGraph.whenReady, so that we use the correct // We have to do this in taskGraph.whenReady, so that we use the correct
// version to resolve the project dependencies // version to resolve the project dependencies
@ -19,4 +22,33 @@ gradle.taskGraph.whenReady {
attributes("Main-Class": "org.jf.baksmali.main") attributes("Main-Class": "org.jf.baksmali.main")
} }
} }
proguard {
def outFile = relativePath(buildDir) + '/libs/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension
inputs.file jar.archivePath
outputs.file outFile
args '-injars ' + jar.archivePath
args '-outjars ' + outFile
} }
processResources.inputs.properties('version': { -> version})
processResources.expand('version': { -> version})
}
task proguard(type: JavaExec, dependsOn: jar) {
setStandardOutput(java.lang.System.out);
setErrorOutput(java.lang.System.err);
classpath = files(configurations.proguard.asPath)
main = 'proguard.ProGuard'
args '-libraryjars ' + System.properties['java.home'] + '/lib/rt.jar'
args '-dontobfuscate'
args '-dontoptimize'
args '-keep public class org.jf.baksmali.main { public static void main(java.lang.String[]); }'
args '-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }'
args '-dontwarn com.google.common.base.**'
args '-dontnote com.google.common.base.**'
}
release.dependsOn(proguard)

View File

@ -28,6 +28,8 @@ subprojects {
// use <version>-dev for the jar name, rather than the // use <version>-dev for the jar name, rather than the
// full commit+dirty string // full commit+dirty string
jarVersion = baseVersion + '-dev' jarVersion = baseVersion + '-dev'
} else {
version = baseVersion
} }
jar { jar {

View File

@ -1,7 +1,7 @@
configurations { configurations {
antlr3 antlr3
jflex jflex
proguard
} }
ext.antlrSource = 'src/main/antlr3' ext.antlrSource = 'src/main/antlr3'
@ -28,6 +28,7 @@ dependencies {
antlr3 'org.antlr:antlr:3.2' antlr3 'org.antlr:antlr:3.2'
jflex 'de.jflex:jflex:1.4.3' jflex 'de.jflex:jflex:1.4.3'
proguard 'net.sf.proguard:proguard-base:4.8'
} }
task generateAntlrSource { task generateAntlrSource {
@ -78,9 +79,6 @@ task generateJflexSource {
compileJava.dependsOn generateAntlrSource, generateJflexSource compileJava.dependsOn generateAntlrSource, generateJflexSource
compileTestJava.dependsOn generateTestAntlrSource compileTestJava.dependsOn generateTestAntlrSource
processResources.inputs.properties('version': { -> version})
processResources.expand('version': { -> version})
// We have to do this in taskGraph.whenReady, so that we use the correct // We have to do this in taskGraph.whenReady, so that we use the correct
// version to resolve the project dependencies // version to resolve the project dependencies
gradle.taskGraph.whenReady { gradle.taskGraph.whenReady {
@ -92,4 +90,33 @@ gradle.taskGraph.whenReady {
attributes("Main-Class": "org.jf.smali.main") attributes("Main-Class": "org.jf.smali.main")
} }
} }
processResources.inputs.properties('version': version)
processResources.expand('version': version)
proguard {
def outFile = relativePath(buildDir) + '/libs/' + jar.baseName + '-' + jar.version + '-small' + '.' + jar.extension
inputs.file jar.archivePath
outputs.file outFile
args '-injars ' + jar.archivePath + '(!**/TestStringTemplate*.class)'
args '-outjars ' + outFile
} }
}
task proguard(type: JavaExec, dependsOn: jar) {
setStandardOutput(java.lang.System.out);
setErrorOutput(java.lang.System.err);
classpath = files(configurations.proguard.asPath)
main = 'proguard.ProGuard'
args '-libraryjars ' + System.properties['java.home'] + '/lib/rt.jar'
args '-dontobfuscate'
args '-dontoptimize'
args '-keep public class org.jf.smali.main { public static void main(java.lang.String[]); }'
args '-keepclassmembers enum * { public static **[] values(); public static ** valueOf(java.lang.String); }'
args '-dontwarn com.google.common.base.**'
args '-dontnote com.google.common.base.**'
}
release.dependsOn(proguard)