2016-10-07 27 views
1

我试图让ProGuard工作,经过大约4小时的随机尝试,尝试让这个惊人的软件工作。ProGuard SimException

我的项目使用LibGDX和Kryo​​Net。这是我当前的ProGuard配置:

-verbose 
-dontobfuscate 

-dontwarn android.support.** 
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication 
-dontwarn com.badlogic.gdx.utils.GdxBuild 
-dontwarn com.badlogic.gdx.jnigen.BuildTarget* 
-dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild 

-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* { 
    <init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration); 
} 

# Kryo 
-dontwarn sun.reflect.** 
-dontwarn java.beans.** 
-dontwarn sun.nio.ch.** 
-dontwarn sun.misc.** 

-keep class com.esotericsoftware.kryo.** {*;} 
-keep class com.esotericsoftware.** {*;} 

-keep class java.beans.** { *; } 
-keep class sun.reflect.** { *; } 
-keep class sun.nio.ch.** { *; } 

这不会编译。它会抛出以下错误的多个:Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type float using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.

我发现一些关于此错误的信息:Compile with Proguard gives SimException: "local variable type mismatch"

给出的解决方案是从ANT编辑一些main-rules.xml文件,但我使用Gradle。评论发布了修复Gradle:添加project.tasks.withType(com.android.build.gradle.tasks.Dex) { additionalParameters=['--no-locals'] }。但显然Dex类被删除,所以这不再起作用。

我读到这是ProGuard中的一个错误,而混淆应该修复它。但是当我删除-dontobfuscate行时,我的应用程序不再启动:java.lang.UnsatisfiedLinkError: No implementation found for void com.a.a.c.a.k.g() (tried Java_com_a_a_c_a_k_g and Java_com_a_a_c_a_k_g__)

有谁知道如何解决这些问题?

回答

1

该问题可能与ProGuard的特定优化有关。 您可以像禁用它:

-optimizations !code/allocation/variable 

此外,您还可以删除LocalVariableTable和LocalVariableTypeTable属性这似乎不正确更新(并在应用中不需要了)。为此,您将需要启用,虽然模糊,然后使用类似:

-keepattributes !LocalVariable*,** 

此规则将保留所有的属性,但所以LocalVariable相关的。

# Keep names - Native method names. Keep all native class/method names. 
-keepclasseswithmembers,includedescriptorclasses class * { 
    native <methods>; 
} 
+0

当使用添加剂,编译成功,但经过一段时间的应用程序崩溃:NullPointerException异常:试图调用虚拟方法com.badlogic

与libGDX混淆问题可能是由于此规则来解决.gdx.scenes.scene2d.ui.Label $ LabelStyle com.badlogic.gdx.scenes.scene2d.ui.Label.getStyle()'null对象引用 – kwantuM

+0

这很可能是由混淆造成的(或者我完全错了吗? ) – kwantuM

+0

没关系,让它工作! – kwantuM