简体   繁体   English

使用ProGuard后,InvocationTargetException

[英]InvocationTargetException after using ProGuard

I obfuscate my jar with ProGuard using Eclipse Ant script. 我使用Eclipse Ant脚本用ProGuard混淆了我的jar。

I use configuration file almost identical from this answer . 我使用的配置文件与此答案几乎相同。 I have just added more references to proper libraries using -libraryjars option and omit two warnings using -dontnote 我刚刚使用-libraryjars选项添加了对适当库的更多引用,并使用-dontnote省略了两个警告

After that I include generated jar into fat jar with those libraries. 之后,我将这些库包含在生成的jar中。 It works okay if above mentioned .cfg is used. 如果使用上述.cfg,它可以正常工作。

But not much obfuscation is done. 但是并没有做太多的混淆。 In examples for typical application it is said to use 典型应用示例中,据说可以使用

-keep public class mypackage.MyMain {
    public static void main(java.lang.String[]);
}

So this is changed 所以这改变了

-keep public class * {
    public protected *;
}

After regenerating new fat jar it throws Exception: 重新生成新的胖子之后,它会引发异常:

    Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoa
der.java:58)
Caused by: java.lang.NullPointerException
        at mypackage.a.d.a.a(SourceFile:11)
        at mypackage.a.d.a.a(SourceFile:44)
        at mypackage.MyMain.main(SourceFile:61)
        ... 5 more

How can I fix it? 我该如何解决? Please, give me some advice how to investigate more on this issue. 请给我一些建议,以便您对这个问题进行更多调查。

I was able to solve this specific problem with inspecting the obfuscated jar with JD Java Decompiler. 通过使用JD Java Decompiler检查混淆的jar,我能够解决此特定问题。

In there way a line: 这样一行:

String path = JarEclipse.class.getResource("MyClass.class").toString();

which caused NullPointerException because getResource returns null, because MyClass.class was renamed. 导致NullPointerException原因是getResource返回null,因为MyClass.class已重命名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM