Commit 0fff1a67 authored by Skylot's avatar Skylot

core: fix warning from dx library

parent d95d268e
...@@ -121,7 +121,8 @@ public class InputFile { ...@@ -121,7 +121,8 @@ public class InputFile {
byte[] ba = j2d.convert(jarFile.getAbsolutePath()); byte[] ba = j2d.convert(jarFile.getAbsolutePath());
if (ba.length == 0) { if (ba.length == 0) {
throw new JadxException(j2d.isError() ? j2d.getDxErrors() : "Empty dx output"); throw new JadxException(j2d.isError() ? j2d.getDxErrors() : "Empty dx output");
} else if (j2d.isError()) { }
if (j2d.isError()) {
LOG.warn("dx message: {}", j2d.getDxErrors()); LOG.warn("dx message: {}", j2d.getDxErrors());
} }
return new Dex(ba); return new Dex(ba);
......
...@@ -5,6 +5,7 @@ import jadx.core.utils.exceptions.JadxException; ...@@ -5,6 +5,7 @@ import jadx.core.utils.exceptions.JadxException;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.PrintStream; import java.io.PrintStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import com.android.dx.command.DxConsole; import com.android.dx.command.DxConsole;
import com.android.dx.command.dexer.Main; import com.android.dx.command.dexer.Main;
...@@ -23,6 +24,8 @@ public class JavaToDex { ...@@ -23,6 +24,8 @@ public class JavaToDex {
optimize = true; optimize = true;
localInfo = true; localInfo = true;
coreLibrary = true; coreLibrary = true;
debug = true;
} }
} }
...@@ -40,6 +43,7 @@ public class JavaToDex { ...@@ -40,6 +43,7 @@ public class JavaToDex {
try { try {
System.setOut(new PrintStream(baos, true, CHARSET_NAME)); System.setOut(new PrintStream(baos, true, CHARSET_NAME));
DxArgs args = new DxArgs("-", new String[]{javaFile}); DxArgs args = new DxArgs("-", new String[]{javaFile});
resetOutDexVar();
Main.run(args); Main.run(args);
baos.close(); baos.close();
} catch (Throwable e) { } catch (Throwable e) {
...@@ -56,11 +60,21 @@ public class JavaToDex { ...@@ -56,11 +60,21 @@ public class JavaToDex {
return baos.toByteArray(); return baos.toByteArray();
} }
private void resetOutDexVar() throws JadxException {
try {
Field outputDex = Main.class.getDeclaredField("outputDex");
outputDex.setAccessible(true);
outputDex.set(null, null);
} catch (Exception e) {
throw new JadxException("Failed to reset outputDex field", e);
}
}
public String getDxErrors() { public String getDxErrors() {
return dxErrors; return dxErrors;
} }
public boolean isError() { public boolean isError() {
return dxErrors != null && dxErrors.length() > 0; return dxErrors != null && !dxErrors.isEmpty();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment