2016-11-01 1 views
9

ich ProGuard in meinem Gradle Skript zu verwenden Ich versuche mein Code jedes Mal zu verschleiern ich bauen, aber ich in den folgenden Fehler leite:Gradle: Weder Weg noch baseDir kann null oder eine leere Zeichenfolge sein

FAILURE: Build failed with an exception. 

* What went wrong: 
Neither path nor baseDir may be null or empty string. path='null' basedir='/Users/hassansyyid/Workspace/Random/Launcher/launcher' 

* Try: 
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. 

BUILD FAILED 

Total time: 1.888 secs 

Hier mein build.gradle ist:

import proguard.gradle.ProGuardTask 

apply plugin: 'com.github.johnrengelman.shadow' 

buildscript { 
    repositories { 
     mavenCentral() 
    } 

    dependencies { 
     classpath 'net.sf.proguard:proguard-gradle:5.3.1' 
    } 
} 

jar { 
    manifest { 
     attributes("Main-Class": "com.skcraft.launcher.Launcher") 
    } 
} 

dependencies { 
    compile 'org.projectlombok:lombok:1.12.2' 
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0' 
    compile 'commons-lang:commons-lang:2.6' 
    compile 'commons-io:commons-io:1.2' 
    compile 'com.google.guava:guava:15.0' 
    compile 'com.beust:jcommander:1.32' 
    compile 'com.miglayout:miglayout:3.7.4' 
    compile 'com.google.code.findbugs:jsr305:3.0.0' 
} 

processResources { 
    filesMatching('**/*.properties') { 
     filter { 
      it.replace('${project.version}', project.version) 
     } 
    } 
} 

task obfuscate(type: proguard.gradle.ProGuardTask) { 
    configuration 'proguard.txt' 

    injars "${buildDir}/libs/launcher-${version}.jar" 
    outjars "${buildDir}/libs/launcher-${version}-obf.jar" 

    libraryjars configurations.compile.find { it.name.startsWith("lombok") } 
    libraryjars configurations.compile.find { it.name.startsWith("jackson-databind") } 
    libraryjars configurations.compile.find { it.name.startsWith("jackson-core") } 
    libraryjars configurations.compile.find { it.name.startsWith("jackson-annotation") } 
    libraryjars configurations.compile.find { it.name.startsWith("crypto") } 
    libraryjars configurations.compile.find { it.name.startsWith("guava") } 
    libraryjars configurations.compile.find { it.name.startsWith("jcommander") } 
    libraryjars configurations.compile.find { it.name.startsWith("miglayout") } 
    libraryjars configurations.compile.find { it.name.startsWith("jsr305") } 
    libraryjars configurations.compile.find { it.name.startsWith("commons-io") } 
    libraryjars configurations.compile.find { it.name.startsWith("commons-lang") } 
} 

shadowJar { 
    dependencies { 
     exclude(dependency('org.projectlombok:lombok')) 
    } 
} 

build.dependsOn(shadowJar) 
build.dependsOn(obfuscate) 

die einzige Information, die ich über das Thema herausgefunden, dass es auf die obfuscate Aufgabe zusammenhängt. Ich bestätigte dies, indem ich build.dependsOn(obfuscate) auskommentierte und der Build erfolgreich war.

Ich habe den Fehler gesucht, konnte aber keine nützlichen Informationen finden. Außerdem laufe ich Gradle 3.1, den neuesten Gradle Build.

Mein proguard.txt:

# Include java runtime classes 
-libraryjars <java.home>/lib/rt.jar 

# Output a source map file 
-printmapping proguard.map 

# Keep filenames and line numbers 
-keepattributes SourceFile, LineNumberTable 

# Disable certain proguard optimizations which remove stackframes (same as Android defaults) 
-optimizations !method/inlining/* 

-keep public class * { 
    public protected *; 
} 

-keepclassmembernames class * { 
    java.lang.Class class$(java.lang.String); 
    java.lang.Class class$(java.lang.String, boolean); 
} 

-keepclasseswithmembernames class * { 
    native <methods>; 
} 

-keepclassmembers enum * { 
    public static **[] values(); 
    public static ** valueOf(java.lang.String); 
} 

-keepclassmembers class * implements java.io.Serializable { 
    static final long serialVersionUID; 
    private static final java.io.ObjectStreamField[] serialPersistentFields; 
    private void writeObject(java.io.ObjectOutputStream); 
    private void readObject(java.io.ObjectInputStream); 
    java.lang.Object writeReplace(); 
    java.lang.Object readResolve(); 
} 

Vielen Dank im Voraus für jede Hilfe!

+0

Können Sie Ihre proguard.txt Datei schreiben? Ich glaube, der Fehler ist da drin. –

+0

@ sub6resources: Hinzugefügt die proguard.txt –

+0

Hmm, es ist nicht da. Hast du eine Idee wo der Pfad und BaseDir sein könnte? –

Antwort

7

Das Problem scheint die Art zu sein, wie Sie die Bibliotheksgläser in der ProGuard-Aufgabe deklarieren. Gemäß der Dokumentation unter the ProGuard homepage muss eine Dateisammlung für die libraryjars Einstellung festgelegt werden.

Class paths are specified as Gradle file collections, which means they can be specified as simple strings, with files(Object), etc.

ich Ihre gradle Datei aktualisiert und konnte erfolgreich den Build ausführen:

import proguard.gradle.ProGuardTask 

apply plugin: 'com.github.johnrengelman.shadow' 
apply plugin: 'java' 

buildscript { 
    repositories { 
    mavenCentral() 
    jcenter() 
    } 

    dependencies { 
    classpath group: 'net.sf.proguard', name: 'proguard-gradle', version: '5.3.1' 
    classpath group: 'com.github.jengelman.gradle.plugins', name: 'shadow', version: '1.2.4' 
    } 
} 

repositories { 
    mavenCentral() 
    jcenter() 
} 

jar { 
    manifest { attributes("Main-Class": "com.skcraft.launcher.Launcher") } 
} 

dependencies { 
    compile 'org.projectlombok:lombok:1.12.2' 
    compile 'com.fasterxml.jackson.core:jackson-databind:2.3.0' 
    compile 'commons-lang:commons-lang:2.6' 
    compile 'commons-io:commons-io:1.2' 
    compile 'com.google.guava:guava:15.0' 
    compile 'com.beust:jcommander:1.32' 
    compile 'com.miglayout:miglayout:3.7.4' 
    compile 'com.google.code.findbugs:jsr305:3.0.0' 
} 

processResources { 
    filesMatching('**/*.properties') { 
    filter { 
     it.replace('${project.version}', project.version) 
    } 
    } 
} 

task obfuscate(type: proguard.gradle.ProGuardTask) { 
    configuration 'proguard.txt' 

    injars jar 
    outjars "${buildDir}/libs/launcher-${version}-obf.jar" 

    libraryjars files(configurations.compile.collect()) 
} 

shadowJar { 
    dependencies { 
    exclude(dependency('org.projectlombok:lombok')) 
    } 
} 

build.dependsOn(shadowJar) 
build.dependsOn(obfuscate) 


task wrapper(type: Wrapper) { gradleVersion = "3.1" } 
Verwandte Themen