1/* 2 * Copyright 2012, Google LLC 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google LLC nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31buildscript { 32 repositories { 33 mavenCentral() 34 } 35 dependencies { 36 classpath depends.proguard_gradle 37 } 38} 39 40sourceSets { 41 main { 42 java { 43 srcDirs "${project.rootDir}/third_party/baksmali/src/main/java" 44 } 45 } 46} 47 48dependencies { 49 implementation project(':util') 50 api project(':dexlib2') 51 implementation depends.guava 52 implementation depends.jcommander 53 54 testImplementation depends.junit 55 testImplementation project(':smali') 56 testImplementation depends.antlr_runtime 57} 58 59processResources.inputs.property('version', version) 60processResources.expand('version': version) 61 62// Build a separate jar that contains all dependencies 63task fatJar(type: Jar) { 64 dependsOn ':dexlib2:jar' 65 dependsOn ':util:jar' 66 from sourceSets.main.output 67 from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } } 68 69 duplicatesStrategy = 'exclude' 70 archiveClassifier = 'fat' 71 72 manifest { 73 attributes('Main-Class': 'com.android.tools.smali.baksmali.Main') 74 } 75 76 doLast { 77 if (!System.getProperty('os.name').toLowerCase().contains('windows')) { 78 ant.symlink(link: file("${destinationDirectory.get()}/baksmali.jar"), resource: archivePath, overwrite: true) 79 } 80 } 81} 82tasks.getByPath('build').dependsOn(fatJar) 83 84publish { 85 publishing { 86 publications { 87 mavenJava(MavenPublication) { 88 pom { 89 description = 'baksmali is a disassembler for dalvik bytecode' 90 scm { 91 url = 'https://github.com/google/smali/tree/master/baksmali' 92 } 93 } 94 } 95 } 96 } 97} 98 99task proguard(type: proguard.gradle.ProGuardTask, dependsOn: fatJar) { 100 def outFile = fatJar.destinationDirectory.file( 101 "${fatJar.archiveBaseName.get()}-${fatJar.archiveVersion.get()}-small.${fatJar.archiveExtension.get()}") 102 103 injars fatJar 104 outjars outFile 105 106 if (JavaVersion.current().isJava9Compatible()) { 107 libraryjars(System.getProperty("java.home") + "/jmods") 108 } else { 109 libraryjars(System.getProperty("java.home") + "/lib/rt.jar") 110 } 111 112 dontobfuscate 113 dontoptimize 114 115 keep 'public class com.android.tools.smali.baksmali.Main { public static void main(java.lang.String[]); }' 116 keep 'public class com.android.tools.smali.util.jcommander.ColonParameterSplitter' 117 keep 'class com.beust.jcommander.** { *; }' 118 keepclassmembers 'enum * { public static **[] values(); public static ** valueOf(java.lang.String); }' 119 120 dontwarn 'com.google.common.**' 121 dontnote 'com.google.common.**' 122} 123 124tasks.getByPath(':release').dependsOn(proguard) 125 126task fastbuild(dependsOn: build) { 127} 128 129task fb(dependsOn: fastbuild) { 130} 131 132tasks.getByPath('javadoc').onlyIf({ 133 !gradle.taskGraph.hasTask(fastbuild) 134}) 135 136tasks.getByPath('test').onlyIf({ 137 !gradle.taskGraph.hasTask(fastbuild) 138}) 139