LigbGDX Problems with App42

+1 vote

Hello!

 

I am using App42 Java SDK 2.7 and LibGDX 1.9.8

 

On Desktop everything works fine, but I get the following error on Android:

 

java.lang.NoSuchMethodError: No static method consume(Lorg/apache/http/HttpEntity;)V in class Lorg/apache/http/util/EntityUtils; or its super classes (declaration of 'org.apache.http.util.EntityUtils' appears in /system/framework/org.apache.http.legacy.boot.jar)

at com.shephertz.app42.paas.sdk.java.connection.RESTConnectorAsync.executeGet(RESTConnectorAsync.java:97)

at com.shephertz.app42.paas.sdk.java.game.ScoreBoardService.getTopNRankers(ScoreBoardService.java:998)

at com.company.game..util.OnlineServer.loadLeaderBoard(OnlineServer.java:566)

 

 

Can anyone help me with this problem? I really like App42 and it would be a perfect addition to libGDX!

 

Thanks!

asked Jun 17, 2018 in Android by mistkibl (63 points)

2 Answers

+1 vote
 
Best answer

I got it to run! So, here is the workaround:


Use JarJar https://github.com/shevek/jarjar and rename:
 

rule org.apache.http.** org.apache.myhttp.@1
rule org.json.** org.myjson.@1


apply this to all jar files:

App42_JAVA_SDK_2.7.jar
App42MultiPlayerGamingSDK.jar
commons-logging-1.1.1.jar
httpclient-4.1.jar
httpcore-4.1.jar
json-org.jar

Add the refactored jar files to your project libs folder.

 

For IOS Moe also include in proguad:

-keep class org.apache.commons.logging.impl.NoOpLog { *; }

 

and set:

System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

 

 

answered Jun 19, 2018 by mistkibl (63 points)
edited Jun 20, 2018 by mistkibl
0 votes

Hi Mistkibi,

Greetings from ShepHertz!!!!!!!!

As you are builidng the same project on Android, you are getting such error because Android System itself contains the Apache Http library.

Please finf the soluction below to build the same on Android.

  1. Either Use App42 Android SDK in place of Java.
  2. Remove other Apache librarries when youa re building the same with Android platform.

Let me know if it helps.

 

Thanks

Vishnu Garg

App42 Team

answered Jun 18, 2018 by Vishnu Garg (674 points)
I would really like to use solution number 2. But how do I remove the "other" Apache librarries?
Will you please share the library files you have added along with App42 JAVA SDK.
I have the following jar files in my lib folder:


App42_JAVA_SDK_2.7.jar
App42MultiPlayerGamingSDK.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.1.jar
httpclient-4.1.jar
httpcore-4.1.jar
json-org.jar


And my Gradle looks like this:

buildscript {
    

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'org.multi-os-engine:moe-gradle:1.4.0'
        classpath 'com.google.gms:google-services:4.0.1' // google-services plugin

    }
}

allprojects {
    apply plugin: "eclipse"
    apply plugin: "idea"

    version = '1.0'
    ext {
        appName = "game"
        gdxVersion = '1.9.8'
        roboVMVersion = '2.3.3'
        box2DLightsVersion = '1.4'
        ashleyVersion = '1.7.0'
        aiVersion = '1.8.0'
    }

    repositories {
        mavenLocal()
        mavenCentral()
        maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
        maven { url "https://oss.sonatype.org/content/repositories/releases/" }
        maven { url "https://maven.google.com" }
    }
}

project(":desktop") {
    apply plugin: "java"


    dependencies {
        compile project(":core")
        compile "com.badlogicgames.gdx:gdx-backend-lwjgl:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
        compile "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
        
    }
}

project(":android") {
    apply plugin: "android"

    configurations { natives }

    dependencies {
        compile project(":core")
        compile fileTree(dir: '../libs', include: '*.jar')
        compile "com.badlogicgames.gdx:gdx-backend-android:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-armeabi-v7a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-arm64-v8a"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
        compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
        compile 'com.android.support:multidex:1.0.1'
        compile 'com.google.firebase:firebase-core:16.0.0'
        compile 'com.google.firebase:firebase-ads:15.0.1'
        
    }

    apply plugin: 'com.google.gms.google-services'
}

project(":core") {
    apply plugin: "java"


    dependencies {
        compile group: 'org.json', name: 'json', version: '20180130'
        compile fileTree(dir: '../libs', include: '*.jar')
        compile project(":base")
        //compile group: 'org.json', name: 'json', version: '20180130'
        compile "com.badlogicgames.gdx:gdx:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-box2d:$gdxVersion"
        compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
        compile "com.badlogicgames.box2dlights:box2dlights:$box2DLightsVersion"
        
    }
}

project(":ios-moe") {
    apply plugin: "moe"

    configurations { natives }

    dependencies {
        compile( project(":core")){
            exclude group: 'org.json'
        }
        compile "com.badlogicgames.gdx:gdx-backend-moe:$gdxVersion"
        natives "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-ios"
        natives "com.badlogicgames.gdx:gdx-box2d-platform:$gdxVersion:natives-ios"
        natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-ios"
        
    }
}

tasks.eclipse.doLast {
    delete ".project"
}
And my Android gradle:

android {
    buildToolsVersion "26.0.1"
    compileSdkVersion 26
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
            jniLibs.srcDirs = ['libs']
        }

        instrumentTest.setRoot('tests')
    }
    packagingOptions {
        exclude 'META-INF/robovm/ios/robovm.xml'
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
    }
    defaultConfig {
        applicationId "com.company.game"
        minSdkVersion 14
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


// called every time gradle gets executed, takes the native dependencies of
// the natives configuration, and extracts them to the proper libs/ folders
// so they get packed with the APK.
task copyAndroidNatives() {
    file("libs/armeabi/").mkdirs();
    file("libs/armeabi-v7a/").mkdirs();
    file("libs/arm64-v8a/").mkdirs();
    file("libs/x86_64/").mkdirs();
    file("libs/x86/").mkdirs();

    configurations.natives.files.each { jar ->
        def outputDir = null
        if(jar.name.endsWith("natives-arm64-v8a.jar")) outputDir = file("libs/arm64-v8a")
        if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("libs/armeabi-v7a")        
        if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("libs/armeabi")
        if(jar.name.endsWith("natives-x86_64.jar")) outputDir = file("libs/x86_64")
        if(jar.name.endsWith("natives-x86.jar")) outputDir = file("libs/x86")
        if(outputDir != null) {
            copy {
                from zipTree(jar)
                into outputDir
                include "*.so"
            }
        }
    }
}

task run(type: Exec) {
    def path
    def localProperties = project.file("../local.properties")
    if (localProperties.exists()) {
        Properties properties = new Properties()
        localProperties.withInputStream { instr ->
            properties.load(instr)
        }
        def sdkDir = properties.getProperty('sdk.dir')
        if (sdkDir) {
            path = sdkDir
        } else {
            path = "$System.env.ANDROID_HOME"
        }
    } else {
        path = "$System.env.ANDROID_HOME"
    }

    def adb = path + "/platform-tools/adb"
    commandLine "$adb", 'shell', 'am', 'start', '-n', 'com.company.game/com.company.game.AndroidLauncher'
}

// sets up the Android Eclipse project, using the old Ant based build.
eclipse {
    // need to specify Java source sets explicitly, SpringSource Gradle Eclipse plugin
    // ignores any nodes added in classpath.file.withXml
    sourceSets {
        main {
            java.srcDirs "src", 'gen'
        }
    }

    jdt {
        sourceCompatibility = 1.6
        targetCompatibility = 1.6
    }

    classpath {
        plusConfigurations += [ project.configurations.compile ]        
        containers 'com.android.ide.eclipse.adt.ANDROID_FRAMEWORK', 'com.android.ide.eclipse.adt.LIBRARIES'       
    }

    project {
        name = appName + "-android"
        natures 'com.android.ide.eclipse.adt.AndroidNature'
        buildCommands.clear();
        buildCommand "com.android.ide.eclipse.adt.ResourceManagerBuilder"
        buildCommand "com.android.ide.eclipse.adt.PreCompilerBuilder"
        buildCommand "org.eclipse.jdt.core.javabuilder"
        buildCommand "com.android.ide.eclipse.adt.ApkBuilder"
    }
}

// sets up the Android Idea project, using the old Ant based build.
idea {
    module {
        sourceDirs += file("src");
        scopes = [ COMPILE: [plus:[project.configurations.compile]]]        

        iml {
            withXml {
                def node = it.asNode()
                def builder = NodeBuilder.newInstance();
                builder.current = node;
                builder.component(name: "FacetManager") {
                    facet(type: "android", name: "Android") {
                        configuration {
                            option(name: "UPDATE_PROPERTY_FILES", value:"true")
                        }
                    }
                }
            }
        }
    }
}
Please Remove all the library jar files other than App42_JAVA_SDK_2.7.jar and App42MultiPlayerGamingSDK.jar, and try to build the same.
Unfortunately the error is the same after excluding the jars you said.

java.lang.NoSuchMethodError: No static method consume(Lorg/apache/http/HttpEntity;)V in class Lorg/apache/http/util/EntityUtils; or its super classes (declaration of 'org.apache.http.util.EntityUtils' appears in /system/framework/org.apache.http.legacy.boot.jar)

I googled and found that Apache HTTP client was removed in Android 6.0
(https://developer.android.com/about/versions/marshmallow/android-6.0-changes).

Therefore I also tried:
android {
    useLibrary 'org.apache.http.legacy'
}

But still it does not work. There must be a simple trick to get it working :)
Its due to org.apache.http.legacy.boot.jar file that also contains the same class needed by SDK that has different method.
Please build the same after removing  useLibrary 'org.apache.http.legacy' tag.
I started from scratch, made a new Project. Added only the jars:

App42_JAVA_SDK_2.7.jar
App42MultiPlayerGamingSDK.jar

and compiled on Android. Still the same error:

java.lang.NoSuchMethodError: No static method consume(Lorg/apache/http/HttpEntity;)V in class Lorg/apache/http/util/EntityUtils; or its super classes (declaration of 'org.apache.http.util.EntityUtils' appears in /system/framework/org.apache.http.legacy.boot.jar)
I think I have now tried everything, I think the only way out is to refactor the source code of App42_JAVA_SDK_2.7.jar. So is it available?
We are debugging the same on our side and will share the solution.
Thats awesome thank you very much!
Hi, I am able to make API calls using App42 Java SDK in android, Please find the dropbox basic sample link.
https://www.dropbox.com/s/fqlc11rpy3g8s0z/AppWarp_App42_libgdxSample.zip?dl=0.
Thank you but, as long as your call does not include a function which is specific to apache http client 4.1. it will work. But try to make a call like scoreBoardService.getTopNRankers(gameName, NUM_SCORES). It will use EntityUtils.consume() which is specific to 4.1. and it will crash...
Please use App42 Android SDK to build Android application through libgdx as Android System are conflicting the library used by Java SDK.
You can down load the same from below.
https://github.com/shephertz/App42_ANDROID_SDK.

Please replace the jar file and do initialize  Android SDK in Android launcher.
I got it to run! So, here is the workaround:

Use JarJar https://github.com/shevek/jarjar and rename:

rule org.apache.** org.myapache.@1
rule org.json.** org.myjson.@1

apply this to all jar files:

App42_JAVA_SDK_2.7.jar
App42MultiPlayerGamingSDK.jar
commons-logging-1.1.1.jar
httpclient-4.1.jar
httpcore-4.1.jar
json-org.jar

Add the refactored jar files to your project libs folder.
You can use this solution as well. Let me know in case of more queries are there.
It fails on iOS robovm with the following exceptions when I tried to link user Facebook account.

Loading class 'java.util.logging.ConsoleHandler' failed
java.lang.ClassNotFoundException: java.util.logging.ConsoleHandler
Exception :com.shephertz.app42.paas.sdk.java.App42Exception: java.lang.NullPointerException.

How can I resolve this problem?
I need your urgent assistance please.
Do yourself a favour and switch to something else. Even if you get this mess here to run, in the end, the service does not scale in performance, flexibility and price. I was there years ago, take this advice and search for something else. I am happy with Google-Flexible-Environment and Websockets now.
@mistkibl thank you. It is a pity that Shephertz intentionally refused to fix and refactor the Java sdk to work well on cross-platform frameworks since they are aware of this problem.
I will leave as soon as I found something better that can scale well on the major platforms.
Can you kindly recommend a better baaS that is cross platform oriented which can fit well on Libgdx?
Yes, LibGDX is more or less dead. If your games is a simple 2D game (board, card game) with lots of UI I would strongly recommend Flutter. If you want to make a 3D game or a 2D game with lots of effects and animations take Unity. As Server, you can check out Photon.
Finally I got it to work on iOS robovm using @mistkibl's solution.

Use JarJar https://github.com/shevek/jarjar and rename:

rule org.apache.** org.myapache.@1
rule org.json.** org.myjson.@1

apply this to all jar files:

App42_JAVA_SDK_2.7.jar
App42MultiPlayerGamingSDK.jar
commons-logging-1.1.1.jar
httpclient-4.1.jar
httpcore-4.1.jar
json-org.jar

Add the refactored jar files to your project libs folder
and finally add these to your robovm.xml

<forceLinkClasses>

<pattern>com.shephertz.app42.**</pattern>
<pattern>java.util.logging.ConsoleHandler</pattern>
<pattern>java.util.logging.SimpleFormatter</pattern>
<pattern>org.myapache.**</pattern>
<pattern>org.myjson.**</pattern>

</forceLinkClasses>

Alternatively download the already modified Ap42SDks here https://tonielrosoft.com/modifiedApp42SDKs/WorkingApp42SDKs.zip
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...