Getting controllers to work on Android

Getting controllers to work on Android
0

#1

Hi everyone,

I am trying to get controllers to work on android. So far I have modified the build.gradle file to the following:

apply plugin: 'com.android.library'

android {
    compileSdkVersion PROP_COMPILE_SDK_VERSION.toInteger()
    buildToolsVersion PROP_BUILD_TOOLS_VERSION

    defaultConfig {
        minSdkVersion PROP_MIN_SDK_VERSION
        targetSdkVersion PROP_TARGET_SDK_VERSION
        versionCode 1
        versionName "1.0"
    }

    sourceSets.main {
        aidl.srcDir "../java/src"
        java.srcDirs = ["../java/src", '../ControllerManualAdapter/src']
        manifest.srcFile "AndroidManifest.xml"
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: '../java/libs', include: ['*.jar'])
    implementation fileTree(dir: '../ControllerManualAdapter/libs', include: ['*.jar'])
}

And I modified our main app activity to extend GameControllerActivity. This setup allows me to build an apk, however, once I try to send input from the controller the app crashes throwing this error:

E/zygote: No implementation found for void org.cocos2dx.lib.GameControllerAdapter.nativeControllerConnected(java.lang.String, int) (tried Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerConnected and Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerConnected__Ljava_lang_String_2I)
E/AndroidRuntime: FATAL EXCEPTION: GLThread 1098
                  Process: com.exceptionullgames.punchout, PID: 23019
                  java.lang.UnsatisfiedLinkError: No implementation found for void org.cocos2dx.lib.GameControllerAdapter.nativeControllerConnected(java.lang.String, int) (tried Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerConnected and Java_org_cocos2dx_lib_GameControllerAdapter_nativeControllerConnected__Ljava_lang_String_2I)
                      at org.cocos2dx.lib.GameControllerAdapter.nativeControllerConnected(Native Method)
                      at org.cocos2dx.lib.GameControllerAdapter.access$000(GameControllerAdapter.java:29)
                      at org.cocos2dx.lib.GameControllerAdapter$1.run(GameControllerAdapter.java:59)
                      at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1500)
                      at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1270)

Any help would be greater appreciated.


#2

I think controllers are supported on Android still. There used to be a test you could try to see if your controller was working. iOS still has it I think but that doesn’t help on Android.

Maybe look in the cpp-tests source files?


#3

https://github.com/cocos2d/cocos2d-x/pull/15854 seemed to fix the issue.