WuDi-ZhanShen / Android-Gyroscope-MC

用陀螺仪玩安卓MC!Play Android MC with your phone's Gyro !
24 stars 1 forks source link

app_process showed "Aborted" when executing by adb command #2

Open huynhtanloc2612 opened 1 year ago

huynhtanloc2612 commented 1 year ago

Hi @WuDi-ZhanShen Thank you for creating and sharing this project. It is very impresive. I have cloned, built and launched app successfully on my Samsung phone with Android 12 version (No root). Screenshot_20230802-213829_MC Gyro

However, I saw nothing after running the adb command to start it. adb shell sh /storage/emulated/0/Android/data/com.tile.tuoluoyi/files/starter.sh

I tried to remove > /dev/null 2>&1 & in the command of app_process to see if there is any message and saw only "Aborted" Hope I could get your feedback and advices for this. Thank you!

huynhtanloc2612 commented 1 year ago

Hi @WuDi-ZhanShen , After spending some time to debug, I've found that the dex file of /storage/emulated/0/Android/data/com.tile.tuoluoyi/files/GyroNative.dex had issue (I have not known the cause yet). I instead used dex file from "build" folder of ./app/build/intermediates/dex/debug/mergeProjectDexDebug/5/classes.dex and pushed it to device folder /data/local/tmp and ran below command and it worked successfully (I could play Minecraft PE game with gyroscope by using you app) adb shell CLASSPATH="/data/local/tmp/classes.dex" app_process -Djava.library.path="/data/local/tmp/" / com.tile.tuoluoyi.GamePadNative Hope above could help you know about this issue.

huynhtanloc2612 commented 1 year ago

Hi @WuDi-ZhanShen , I have unzip a apk and seen that only classes4.dex file is the correct .dex file. So I changed if condition in unzipFiles() method the with classes4.dex instead of classes.dex and the project work as expected. It means that I can run the command of adb shell sh /storage/emulated/0/Android/data/com.tile.tuoluoyi/files/starter.sh.

                if (entry.getName().equals("classes4.dex")){
                    InputStream inputStream = zipFile.getInputStream(entry);
                    FileOutputStream fos = new FileOutputStream(file2);
                    byte[] buffer = new byte[1024];
                    int len;
                    while ((len = inputStream.read(buffer)) > 0) {
                        fos.write(buffer, 0, len);
                    }
                    fos.close();
                    break;
                }
WuDi-ZhanShen commented 1 year ago

Hi @WuDi-ZhanShen , I have unzip a apk and seen that only classes4.dex file is the correct .dex file. So I changed if condition in unzipFiles() method the with classes4.dex instead of classes.dex and the project work as expected. It means that I can run the command of adb shell sh /storage/emulated/0/Android/data/com.tile.tuoluoyi/files/starter.sh.

                if (entry.getName().equals("classes4.dex")){
                    InputStream inputStream = zipFile.getInputStream(entry);
                    FileOutputStream fos = new FileOutputStream(file2);
                    byte[] buffer = new byte[1024];
                    int len;
                    while ((len = inputStream.read(buffer)) > 0) {
                        fos.write(buffer, 0, len);
                    }
                    fos.close();
                    break;
                }

If you add "multiDexEnabled false" into the build.gradle(:app) file, the app-release.apk will contain only one classes.dex. I hope that will help you.

huynhtanloc2612 commented 1 year ago

If you add "multiDexEnabled false" into the build.gradle(:app) file, the app-release.apk will contain only one classes.dex. I hope that will help you.

It works. Thank you very much @WuDi-ZhanShen

BTW, I am wondering where I can get the values for variable of description[] for the gamepad or all other uhid devices like keyboard, mouse...? And is there the list of all uhid devices? For example, I also want to check if the usbc-to-hbmi dongle which connects to TV/monitor is an uhid device or not. If so, what are its description[] values...(I searched on the internet but cannot find such information). Hope you can give me some advices. Thanks.

WuDi-ZhanShen commented 1 year ago

If you add "multiDexEnabled false" into the build.gradle(:app) file, the app-release.apk will contain only one classes.dex. I hope that will help you.

It works. Thank you very much @WuDi-ZhanShen

BTW, I am wondering where I can get the values for variable of description[] for the gamepad or all other uhid devices like keyboard, mouse...? And is there the list of all uhid devices? For example, I also want to check if the usbc-to-hbmi dongle which connects to TV/monitor is an uhid device or not. If so, what are its description[] values...(I searched on the internet but cannot find such information). Hope you can give me some advices. Thanks.

The HDMI converter you mentioned doesn't belong to hid devices. Hid means human input device such as keyboard, mouse, koystick, touchscreen, gamepad. And "uhid" is a Linux API which allows us to simulate hid devices using hid descriptions.

However, I didn't use the "uhid" as the primary work mode but the"uinput", which is also a Linux api to simulate input devices but has better performance in this situation of using gyro in MC.

If you want to get some more hid descriptions such as keyboard, mouse, gamepad, you can check my project named "uhid-purejava", or check this website: https://www.usbzh.com/article/detail-525.html . And you can go deeper into the source code of Linux kernel to find out any information you want about uhid.