Scorr / RetroUnity

Unity frontend for the libretro API.
GNU General Public License v3.0
41 stars 23 forks source link

Feature/android build #22

Open humbertodias opened 4 years ago

humbertodias commented 4 years ago
  1. Core downloader sets the core file as native and arm7 1-core-as-native-plugin

  2. Then the shared library will be available globally inside the APK 2-apk-plugin-arm

  3. Enabling SD Card permission 3-unity-android-sdcard-permission

  4. Rom inside Assets/StreamingAssets 4-rom-inside-streamingassets

  5. Only for the first time you play, the permission will be asked 4-android-sdcard-permission

  6. Playable 5-android-running

  7. APK demo https://drive.google.com/file/d/144tQuoYxkcMtt7cj5X-HiPV021aKnc9f/view?usp=sharing

saintmikie commented 3 years ago

Hi @humbertodias

Thank you for this, the APK works great, but I have tried to put together the Unity project and no matter what I do I get errors when I run my version on the Android device, around the dlopen within the LoadLibrary().

Works perfectly in windows build.

I have tried Mono and IL2CPP but always get either dlopen failed library "snes9x_libretro_android.so file" not found when using Mono or Undefined symbol UnityShaderCompilerExtEvent when using IL2CPP.

Compiling for Android 4.4 upwards, tried on several different devices.

I check if the file exists using WWW in unity and I get a true response and even checked the APK file and all .so files are there.

`var www = new UnityWebRequest(fileName);

        if (!string.IsNullOrEmpty(www.error))
        {
            Debug.LogError("Cant read file");
        }
        else
        {
            Debug.Log("Core has been Found...");
        }`

Fails at the below.

`Debug.Log("So Path : " + fileName);

        IntPtr retVal = dlopen (fileName, RTLD_NOW);
        var errPtr = dlerror ();
        if (errPtr != IntPtr.Zero) {
            Debug.LogError ("In the LoadLibrary Method :- " + Marshal.PtrToStringAnsi (errPtr));
        }
        return retVal;`

I have tried the following versions of unity.

2019.4.9f1 2018.4.7f1 2019.3.3f1 2017.1.0f3 2020.1.5

Just wondering if I am missing something in the UNITY settings / project.

Any advice would be much appreciated,

Thanks

Mike

nickos64252 commented 2 years ago

Hello,

this is a very interesting project.

I tried to follow your instruction but I end with a white screen on the virtual TV.

On Windows, it works normally.

I put the cores .so in Plugins and assigned them with Arm7, enabled External SD Card (and I have the screen with the first boot of the app), and put the games in the StreamingAssets folder.

If I monitor errors, I get something about "no local sync point found": 4-27 14:57:53.356: E/Layer(936): [Surface(name=AppWindowToken{129ba6 token=Token{7a67101 ActivityRecord{29726e8 u0 com.scorr.retrounity/com.unity3d.player.UnityPlayerActivity t3797}}})/@0xab168a9 - animation-leash#0] No local sync point found, barrierLayer : [com.sec.android.app.launcher/com.sec.android.app.launcher.activities.LauncherActivity$_2372#0] 04-27 14:57:55.539: E/Unity(25704): at RetroUnity.LibretroWrapper+Wrapper.Init () [0x00000] in <901ff39b303e448898ca5eb888ab221c>:0 04-27 14:57:55.539: E/Unity(25704): at RetroUnity.GameManager.LoadRom (System.String romPath) [0x0003a] in <901ff39b303e448898ca5eb888ab221c>:0 04-27 14:57:55.539: E/Unity(25704): at RetroUnity.GameManager.Awake () [0x00016] in <901ff39b303e448898ca5eb888ab221c>:0

I tried on Unity 2109.4 and 2021.3.

PS : It lloks like the core is not loaded by ldopen. I tried to set the core to v7 or v8, the target to v7 or v8,, all using the v7 or v8 versions of the core.

Any ideas ?

Thank you

Nicolas

saintmikie commented 2 years ago

Hi @nickos64252

I am looking at this project again after a while, I will let you know if I get anything similar.

I have been trying to get it to work for VR on Quest2 but just testing on Samsung Phones at the min, but still getting the errors.

These are the 2 errors I get.

1) Mono I get :- dlopen failed library "snes9x_libretro_android.so file" not found

2) IL2CPP I get :- Undefined symbol UnityShaderCompilerExtEvent

Mike

nickos64252 commented 2 years ago

Hi @saintmikie ,

I am doing pretty much the same thing. I want to put it on Quest/Quest 2, but currently trying to make it run an any Android device.

I have the exact same errors, but I have "unable to find libdl" just before.

For now, I guess no ".so" are loaded, but i cannot figure out why. I tried to target older API (guessing Android 10 was blocking something), but, no success.

Nicolas

lazydevyo commented 2 years ago

Hi @saintmikie ,

I am doing pretty much the same thing. I want to put it on Quest/Quest 2, but currently trying to make it run an any Android device.

I have the exact same errors, but I have "unable to find libdl" just before.

For now, I guess no ".so" are loaded, but i cannot figure out why. I tried to target older API (guessing Android 10 was blocking something), but, no success.

Nicolas

You have to include the android liberto cores, the so-called "so" files have to include in your apk. check at the "lib" folder of your apk and "assets" for the "so" files

nickos64252 commented 2 years ago

@lazydevyo

I put the cores "*.so" in the Plugins folder and they are present in the apk lif folder.

But I think libdl is not found and that makes them useless.

saintmikie commented 2 years ago

Hi,

Below is my Lib folder inside the APK.

OPK Lib Folder

saintmikie commented 2 years ago

Hi,

Could it be that they are not in the root of lib.

Mike

nickos64252 commented 2 years ago

"sned9x_libretro_android.so" is there.. but where did you find libdl.so ?

I think I by passed that by changing [DllImport("libdl.so", EntryPoint = "dlopen")] to [DllImport("dl", EntryPoint = "dlopen")] I do not have "unable to find libdl" anymore; but the cores are still not found.

If what you do work, I would like to know your way.

I guess you downloaded libdl.so somewhere else, then added it in Plugins and configured it for Armv7.

Have you changed anything else ?

saintmikie commented 2 years ago

I downloaded the APK above and that works fine on my phone.

libdl.so does not seem to exist in the APK above.

Just comparing builds now.

Mike

saintmikie commented 2 years ago

Got a little bit further but now getting the error below.

It finds the so file, in my case I have tried 2 , snes9X_libretro_android, fuse_libretro_android, I have also made sure I am using the sames version of unity that the Github Project is set too. 2019.4.9f1.

I also use the free asset, InGameDebugConsole for unity.

I can get the windows version working fine.

Screenshot_20220428-224312_RetroUnity

saintmikie commented 2 years ago

Compiled out to IL2CPP and ARM64 and get the following error now.

Screenshot_20220428-232845_RetroUnity

nickos64252 commented 2 years ago

Hello,

I succeeded to make it run and wanted to let you know.

1- libdl I changed all [DllImport("libdl.so" to [DllImport("dl" because I had error with "unable to find libdl.so"

2- core naming I had "Error loading DLL" I changed the core name by adding lib in front. Ex : snes9x_libretro_android-so -> libsnes9x_libretro_android.so (Do not forget to set only for Android platfrom and Armv7) Then added in the LoadCore function : string dllPath = "lib" + dllName + "_android.so";

3- rom path There was a problem with the rom from StreamingAsset, I loaded it directly from another persistent folder

Hope it helps

Nicolas

saintmikie commented 2 years ago

Hi Nicolas,

Well I am pretty positive that mine are now being found but now stuck with the Partial Byte Sequence error.

Both the libdl.so and rom are being found, but fails when reading it, I don't get the file not found anymore.

What version of Unity are you running in, I am using 2019.4.9f1 on Windows.

Maybe my libdl.so is the wrong version or something like that, or I am missing something in unity.

Mike

nickos64252 commented 2 years ago

@saintmikie ,

I tried and succeeded on Unity 2019.4.11 and 2021.3.1

saintmikie commented 2 years ago

OMG, it's working.

Once changing to "dl" I had to remove the libdl from my project and it is now working, I still get the UnityShader error but it is working.

Thank you for the insperation.

Mike