Skip to content

Commit

Permalink
Allow verbose and debug dx output
Browse files Browse the repository at this point in the history
  • Loading branch information
ThexXTURBOXx committed Dec 16, 2023
1 parent 3946a9d commit 9c9580b
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions dex-tools/src/main/java/com/googlecode/dex2jar/tools/Jar2Dex.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.googlecode.dex2jar.tools;

import com.android.dx.command.Main;
import java.io.File;
import java.lang.reflect.Method;
import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;

@BaseCmd.Syntax(cmd = "d2j-jar2dex", syntax = "[options] <dir>", desc = "Convert jar to dex by invoking dx.")
public class Jar2Dex extends BaseCmd {
Expand All @@ -20,6 +21,12 @@ public static void main(String... args) {
@Opt(opt = "s", longOpt = "sdk", description = "set minSdkVersion")
private int minSdkVersion = 13;

@Opt(opt = "d", longOpt = "debug", description = "debug output")
private boolean debug = false;

@Opt(opt = "v", longOpt = "verbose", description = "verbose output")
private boolean verbose = false;

@Opt(opt = "o", longOpt = "output", description = "output .dex file, default is $current_dir/[jar-name]-jar2dex"
+ ".dex", argName = "out-dex-file")
private Path output;
Expand Down Expand Up @@ -73,15 +80,18 @@ protected void doCommandLine() throws Exception {

System.out.println("jar2dex " + realJar + " -> " + output);

Class<?> c = Class.forName("com.android.dx.command.Main");
Method m = c.getMethod("main", String[].class);

String[] ps = new String[]{"--dex", "--no-strict",
List<String> ps = Arrays.asList(
"--dex", "--no-strict",
"--output=" + output.toAbsolutePath(),
"--min-sdk-version=" + minSdkVersion,
realJar.toAbsolutePath().toString()};
System.out.println("call com.android.dx.command.Main.main" + Arrays.toString(ps));
m.invoke(null, (Object) ps);
"--min-sdk-version=" + minSdkVersion
);
if (verbose) ps.add("--verbose");
if (debug) ps.add("--debug");
ps.add(realJar.toAbsolutePath().toString());

System.out.println("call com.android.dx.command.Main.main" + ps);

Main.main(ps.toArray(new String[0]));
} finally {
if (tmp != null) {
Files.deleteIfExists(tmp);
Expand Down

0 comments on commit 9c9580b

Please sign in to comment.