Android 中 AndEngine GLES2 的 Proguard 问题-JNI 检测到应用程序错误

Proguard issue with AndEngine GLES2 in Android-JNI DETECTED ERROR IN APPLICATION

我开发了一个使用 andEngine GLES2 and andEngine's extension Physics2DBox 的应用程序。该应用程序具有其他功能,而不仅仅是关注 andEngine 方面。我在我的应用程序中启用了混淆器。现在,当我构建我的应用程序的签名版本并导航到使用 andEngine 的位置时,我得到以下堆栈跟踪:

JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception 
java.lang.NoSuchMethodError: no non-static method    
"Lcom/badlogic/gdx/physics/box2d/World;.beginContact(J)V" at long 
com.badlogic.gdx.physics.box2d.World.newWorld(float, float, boolean) (World.java:-2) at void 
com.badlogic.gdx.physics.box2d.World.<init>(com.badlogic.gdx.math.Vector2, boolean 
(World.java:101)
at void org.andengine.extension.physics.box2d.PhysicsWorld.<init 
(com.badlogic.gdx.math.Vector2, boolean, int, int) (PhysicsWorld.java:61) 
at void org.andengine.extension.physics.box2d.PhysicsWorld.<init> . 
(com.badlogic.gdx.math.Vector2, boolean) (PhysicsWorld.java:57)

但是,当我使用没有混淆器的应用程序的签名版本时,它可以完美运行。所以我知道这是一个proguard问题。

目前,我的应用架构看起来像

您在哪里可以看到这些库是我的应用程序的模块。

目前,我的混淆器看起来像这样:

-dontobfuscate

-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.ParametersAreNonnullByDefault

# Proguard configuration for Jackson 2.x (fasterxml package instead of codehaus package)
-keep class com.fasterxml.jackson.databind.ObjectMapper {
      public <methods>;
      protected <methods>;
}
-keep class com.fasterxml.jackson.databind.ObjectWriter {
    public ** writeValueAsString(**);
}
-keepnames class com.fasterxml.jackson.** { *; }
-dontwarn com.fasterxml.jackson.databind.**
-keep public class com.yelp.**

# Retrofit
-dontwarn okio.**
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions

# okhttp
-dontwarn okhttp3.**
#-dontwarn okio.**
#-dontwarn javax.annotation.**
-dontwarn org.conscrypt.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase


-keep class androidx.** { *; }
-keep interface androidx.** { *; }
-keep class android.support.** { *; }
-keep interface android.support.** { *; }



-dontwarn com.google.**
-dontwarn com.bumptech.glide.load.resource.**

-dontwarn org.apache.avalon.framework.logger.Logger
-dontwarn org.apache.log.**
-dontwarn org.apache.log4j.**
-dontwarn javax.servlet.**

-keep class org.apache.http.**  { *; }
-dontwarn org.apache.http.**

-keep class com.github.mikephil.charting.** { *; }
-dontwarn io.realm.**

-dontwarn com.stripe.android.**
-dontwarn org.bouncycastle.**
-dontwarn com.nimbusds.jose.**

-keep class com.stripe.android.** { *; }
-keep class org.bouncycastle.** { *; }
-keep class com.nimbusds.jose.** { *; }

-keep class com.zomato.photofilters.** {*;}
-keepclassmembers  class com.zomato.photofilters.** {*;}
-dontwarn org.xmlpull.v1.**
-dontnote org.xmlpull.v1.**
-keep class org.xmlpull.** { *; }
-keepclassmembers class org.xmlpull.** { *; }

-ignorewarnings

# RULES FOR ANDENGINE STUFF
-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep class Loader {
    public static void main(...);
}
# note that <methods> means any method
-keepclasseswithmembernames,includedescriptorclasses class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}
-optimizations!code/simplification/arithmetic,!field/*,!class/merging/*

# END OF RULES FOR ANDENGINE STUFF

andEngine GLES2 库和 andEngine 扩展库在它们自己的 Gradle 文件中包含以下内容。

consumerProguardFiles 'proguard-rules.pro'

在您的情况下,proguard 似乎删除了 box2d 扩展的 World.class。尝试将以下内容添加到您的混淆器规则中:

-keep class com.badlogic.gdx.physics.box2d.** { *; }

因此它不会触及您的 box2d 文件。