Issue
I have developed an app that uses andEngine GLES2 and andEngine's extension Physics2DBox. The application has other functionality that doesn't just focus on the andEngine aspect. I have proguard enabled in my app. Now when I build a signed version of my app and navigate to where andEngine is used I get the following stack trace:
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)
However, when I use a signed version of the app WITHOUT proguard, it works perfectly. So I know it is a proguard issue.
Currently, my app architecture looks like .
Where you can see that the libraries are modules to my app.
Currently, my proguard looks like this:
-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
With the andEngine GLES2 library and andEngine extension library having the following in their own Gradle files.
consumerProguardFiles 'proguard-rules.pro'
Solution
In your case, it looks like proguard removes the World.class of the box2d extension. Try to add the following to your proguard rules:
-keep class com.badlogic.gdx.physics.box2d.** { *; }
So it will don´t touch your box2d files.
Answered By - Jonny Right
Answer Checked By - Timothy Miller (JavaFixing Admin)