I’m hiding a specific window using JNA which works fine, but i need to shrink my whole project. I guess there are a lot of things in JNA which i dont need.
Is there a way / tool which removes all the things never called in case of the following main method programatically? I’ve all the JNA classes inside my project, not just the common jar file.
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.WinDef.HWND;
import com.sun.jna.platform.win32.WinUser;
import com.sun.jna.platform.win32.WinUser.WNDENUMPROC;
import com.sun.jna.win32.StdCallLibrary;
public class HideHwnd {
public interface User32 extends StdCallLibrary {
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
boolean EnumWindows(WinUser.WNDENUMPROC lpEnumFunc, Pointer arg);
int GetWindowTextA(HWND hWnd, byte[] lpString, int nMaxCount);
boolean ShowWindow(HWND hWnd, int i);
}
public static void main(String[] args) {
final User32 user32 = User32.INSTANCE;
user32.EnumWindows(new WNDENUMPROC() {
public boolean callback(HWND hWnd, Pointer arg1) {
byte[] windowText = new byte[512];
user32.GetWindowTextA(hWnd, windowText, 512);
String wText = Native.toString(windowText);
if (wText.isEmpty()) {
return true;
}
if (wText.startsWith("window1")){
if (user32.ShowWindow(hWnd, 1))
System.out.println(wText+" is hidden now!");
}
return true;
}
}, null);
}
}
Thanks in advance, Tom
I have had great success with ProGuard, although I have not tried it with any JNA-projects:
The obfuscating can be entirely disabled and ProGuard will scan class-file dependencies and omit unused classes (“classes to keep always” can be specified). ProGuard can be used on external libraries as well and used to build a single JAR with only the “required classes”.