How to setup Android Gamepad?

I already check this post

In this we can find a good repository for to check if the Gamepad is working.
I already download the example and works fine with Windows, but I cannot make this work on Android.

I also check this post but it never show any example…But it looks like you can use a gamepad on the Android Platform.

Finally I check the documentation

I don’t understand how to setup the Gamepad on Android.
Works fine on Windows, but there’s no input on Android.

I make a copy of the repository Gamepad Tester found on the Examples.

We need to setup support for Gamepad on Android and Android TV devices.

I also found this very interesting I already setup a project.
I can use the Gamepad on Android but via Html5 version while the native it doesn’t work.
I’m not sure if we need more setup to enable the gamepad on the Android platform.
maybe the manifest need some specific permissions ?

I also record what I mean. The gamepd result is this one.
Defold on Windows is ok.
Defold on hmtl5 on Windows web browser is ok.

Defold on native android gamepad doesn’t work.
Defold on html5 via android web browser the gamepad works fine.

That’s why I’m confusing…From what I read on the manual it should work on native. android.
I’m using the Defold Version 1.6.1.

html worked as set up, maybe android needs some sort of extra controller-bridge or the controller might need to be connected directly to the phone, looks like you were going through the PC.

The only way I can use the controller on the phone is via Bluetooth.
When I connect via cable the controller is used by the PC.
When I disconnect the controller it works with Bluetooth…the gamepad is connected to the phone.
I just try to not make a long video…I was also thinking if on Android the gamepad doesn’t work with Bluetooth. I will try to test if connected with a cable works on Android.

Well I found an USB adapter to use the gamepad via USB…nothing happens, I’m sure it works fine because outside the defold build the gamepad works fine. What could be the issue?
Maybe I should test old defold versions.

First you need to check that your gamepad has bindings set in the gamepad settings file:

What kind of gamepad is it?

If there is a binding for your gamepad then make sure it has platform set to “android”. If there is not binding then you need to create one. There are instructions here:

You can also try to add an input binding for raw gamepad input and verify that you get any data from the gamepad:

No it’s not working…I also try with a Bluetooth keyboard, looks like it have the same issue.
I check again the Bluetooth keyboard it works fine.
So the Bluetooth is not the issue.

:point_up:

I’m not sure about about what ‘kind’ of gamepad means.
I have two gamepads to test.
The first one is the 8bitdo lite. While on windows everything works fine.
Android doesn’t work…the 8bitdo lite I try to test with Bluetooth and Wired on my phone and a tablet.
This is the gamepad
image
Is the same device you can see on the video I also upload.
Other device is Gulikit Pro Controller.
image
The same it doesn’t work…But I’m sure this should work on Android.
I test with other game engine Unity and they were working fine.
Well you can even use the OS Android without any issues.

I was also looking the DefoldActivity.java
I’m not sure were you read the input for this devices.
I think something is missing. Like I show on the video if I build the Html5 version I can use the Gamepad…I was also trying to develop for the Android TV and Fire TV but looks like other user wasn’t able to use Defold there. I think the main activity need a review.

When I connect the gamepad the Android log cat show

WARNING:INPUT: No gamepad map found for gamepad 1 (GuliKit Controller AW). The raw gamepad map will be used.

I try to use this. But nothings show the log cat

if action_id == hash("raw") then
        pprint(action.gamepad_buttons)
        pprint(action.gamepad_axis)
        pprint(action.gamepad_hats)
    end

I cannot find how to use the Raw

You need to add an input binding for Raw:

Screenshot 2023-11-08 at 08.43.58

I’m going to dig up a Bluetooth controller and verify that it works in Defold on Android. I’ll come back to you here during the day.

It works for me. This is what I did:

  1. Connect gamepad via Bluetooth. I connected a PS5 controller:

  1. Verified that it was detected as a gamepad using Gamepad Tester app:

  1. Opened Pixel Line Platformer sample game in Defold. This game has gamepad input configured:

Screenshot 2023-11-08 at 09.53.01

  1. Bundle and install the game on my Android phone. Run and play with the connected gamepad!


My recommendation: Do the exact same steps as above, but with the gamepad you have.

1 Like

Well after a lot of testing I was finally able to this work.
From what I understand we need to create a layout for the controller.
For example for the GuliKitController I have to add this on the .gamepads file.

The controller now will work.

driver
{
    device: "GuliKit Controller AW"
    platform: "android"
    dead_zone: 0.2
    map { input: GAMEPAD_LSTICK_LEFT type: GAMEPAD_TYPE_AXIS index: 0 mod { mod: GAMEPAD_MODIFIER_NEGATE } mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_LSTICK_RIGHT type: GAMEPAD_TYPE_AXIS index: 0 mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_LSTICK_DOWN type: GAMEPAD_TYPE_AXIS index: 1 mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_LSTICK_UP type: GAMEPAD_TYPE_AXIS index: 1 mod { mod: GAMEPAD_MODIFIER_NEGATE } mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_LSTICK_CLICK type: GAMEPAD_TYPE_BUTTON index: 17 }
    map { input: GAMEPAD_RSTICK_LEFT type: GAMEPAD_TYPE_AXIS index: 2 mod { mod: GAMEPAD_MODIFIER_NEGATE } mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_RSTICK_RIGHT type: GAMEPAD_TYPE_AXIS index: 2 mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_RSTICK_DOWN type: GAMEPAD_TYPE_AXIS index: 3 mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_RSTICK_UP type: GAMEPAD_TYPE_AXIS index: 3 mod { mod: GAMEPAD_MODIFIER_NEGATE } mod { mod: GAMEPAD_MODIFIER_CLAMP } }
    map { input: GAMEPAD_RSTICK_CLICK type: GAMEPAD_TYPE_BUTTON index: 18 }
    map { input: GAMEPAD_LPAD_LEFT type: GAMEPAD_TYPE_HAT index: 0 hat_mask: 8 }
    map { input: GAMEPAD_LPAD_RIGHT type: GAMEPAD_TYPE_HAT index: 0 hat_mask: 2 }
    map { input: GAMEPAD_LPAD_DOWN type: GAMEPAD_TYPE_HAT index: 0 hat_mask: 4 }
    map { input: GAMEPAD_LPAD_UP type: GAMEPAD_TYPE_HAT index: 0 hat_mask: 1 }
    map { input: GAMEPAD_RPAD_LEFT type: GAMEPAD_TYPE_BUTTON index: 3 }
    map { input: GAMEPAD_RPAD_RIGHT type: GAMEPAD_TYPE_BUTTON index: 1 }
    map { input: GAMEPAD_RPAD_DOWN type: GAMEPAD_TYPE_BUTTON index: 0 }
    map { input: GAMEPAD_RPAD_UP type: GAMEPAD_TYPE_BUTTON index: 6 }
    map { input: GAMEPAD_LTRIGGER type: GAMEPAD_TYPE_AXIS index: 4 }
    map { input: GAMEPAD_LSHOULDER type: GAMEPAD_TYPE_BUTTON index: 4 }
    map { input: GAMEPAD_RTRIGGER type: GAMEPAD_TYPE_AXIS index: 5 }
    map { input: GAMEPAD_RSHOULDER type: GAMEPAD_TYPE_BUTTON index: 5 }
    map { input: GAMEPAD_START type: GAMEPAD_TYPE_BUTTON index: 15 }
    map { input: GAMEPAD_BACK type: GAMEPAD_TYPE_BUTTON index: 16 }
    map { input: GAMEPAD_GUIDE type: GAMEPAD_TYPE_BUTTON index: 19 }
}

We can do the same thing for other controller and it’s fully supported.
Now the thing is how to support the Android/Fire TV devices. Cannot find examples with the Raw…actually on other post says it probably needs a custom plugin.
But this should be a nice help to setup specific controllers.

This means you have to manually setup every game controller.
Well on android this seems very hard to do…I will try to check how the Raw way works.