I am creating an Android plugin to be used by Unity. However, I get a DLLNotFoundException when I try calling the plugin from Unity. Here are the steps I took:
Android Studio
I have generated an AAR plugin from the hello_cloudxr_c sample Android project which uses CloudXR version 3.2. This can be downloaded here: hello_cloudxr_c on GitHub. The only modifications I did to this to generate the AAR were in build.gradle (:app) where I changed the first line to apply plugin: ‘com.android.library’ and commented out applicationId “com.nvidia.ar.hellocloudxr” in the defaultConfig block.
I changed the path of -DARCORE_INCLUDE from ${project.rootDir}/…/…/libraries/include" to ${project.rootDir}/libraries/include"
I changed the path of -DGLM_INCLUDE from ${project.rootDir}/…/…/libraries/glm" to ${project.rootDir}/libraries/glm"
minSdkVersion is set to 25 and targetSDKVersion is 28.
In jni_interface.cc, I added a small function called getSomeNumber() which returns an integer.
extern "C" {
int getSomeNumber() {
return 2345;
}
}
I will call this from Unity as a simple test.
After doing a clean build, app-debug.aar is created in app/build/outputs/aar. If I change the file extension to .zip, uncompress it and look in app-debug/jni/arm64-v8a, I see that only libc++_shared.so, libhello_cloudxr_native.so and liboboe.so are present. The CloudXR library isn’t there. I manually copy libCloudXRClient.so, libgrid.so, libGsAudioWebRTC.so and libPoco.so into the jniLibs folder in Android Studio. When I build again, all the required .so files are present in the AAR.
Unity
I have created a Unity project which has a scene containing a single button. The AAR file is copied into the Plugins folder. I have written a script called CXRConnect.cs which references the plugin and calls the getSomeNumber() function when the button is pressed.
public class CXRConnect : MonoBehaviour
{
public Button button;
public Text textObject;
private const string LIBRARY_NAME = "libhello_cloudxr_native";
[DllImport(LIBRARY_NAME)]
private static extern int getSomeNumber();
void Start()
{
Button btn = button.GetComponent<Button>();
btn.onClick.AddListener(CallCPPLibrary);
}
void CallCPPLibrary()
{
int num = getSomeNumber();
Debug.Log("CXR Some Num: "+num);
textObject.text = num.ToString();
}
}
In the Unity project settings:
Minimum API Level is set to Android 10.0 (API level 29)
Target API Level is set to Automatic (highest installed)
Scripting Backend is IL2CPP
Api Compatibility Level is .NET Standard 2.0
ARMv7 and ARM64 are ticked in Target Architectures
I am running the build on a Samsung Galaxy Note20 Ultra. When the app is running on the device and I press the button in the Unity scene, there is an error in Logcat in Android Studio which reads:
2022-07-06 10:59:42.240 3203-18112/? E/Unity: DllNotFoundException: Unable to load DLL 'hello_cloudxr_native': The specified module could not be found.
at CXRConnect.getSomeNumber () [0x00000] in <00000000000000000000000000000000>:0
at CXRConnect.CallCPPLibrary () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00000] in <00000000000000000000000000000000>:0
at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData p
Have any of you encountered this issue? What could be the possible cause and how should I fix it? I have checked the contents of the plugin and all the required libraries are in there.
Related
Researched this issue many times but didn't found solution of it. Working with xamarin forms version 5.0.0.2012, on win 10 os (saw many solutions for mac or linux but didn't found any for windows), using PCSC library version 5.0.0. Trying to invoke context.Establish method while debugging on Android 8.0:
public SimpleReader(ISCardContext context, bool releaseContextOnDispose = false)
{
if (context == null)
{
context = (ISCardContext) new SCardContext();
context.Establish(SCardScope.System);
releaseContextOnDispose = true;
}
this._context = context;
this._reader = (ISCardReader) new SCardReader(context);
this._releaseContextOnDispose = releaseContextOnDispose;
this._disconnectReaderOnDispose = true;
}
When, exception occur with message below:
System.DllNotFoundException: libpcsclite.so.1 assembly:<unknown assembly> type:<unknown type> member:(null)
at (wrapper managed-to-native) PCSC.Interop.Linux.LinuxNativeMethods.SCardEstablishContext(intptr,intptr,intptr,intptr&)
at PCSC.Interop.Linux.PCSCliteLinux.EstablishContext (PCSC.SCardScope dwScope, System.IntPtr pvReserved1, System.IntPtr pvReserved2, System.IntPtr& phContext) [0x00006] in C:\Users\danm\src\pcsc-sharp\src\PCSC\Interop\Linux\PCSCliteLinux.cs:39
at PCSC.SCardContext.Establish (PCSC.SCardScope scope) [0x00020] in C:\Users\danm\src\pcsc-sharp\src\PCSC\SCardContext.cs:81
at App1xx.Services.SimpleReader.SimpleReader..ctor (PCSC.ISCardContext context, System.Boolean releaseContextOnDispose) [0x00023] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:59
at App1xx.Services.SimpleReader.SimpleReader..ctor () [0x00000] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:70
at App1xx.Services.UaIdRLib.IdCardReader.connect () [0x00002] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\UaIdRLib\IdCardReader.cs:371
at App1xx.Views.AboutPage.OnButtonClicked (System.Object sender, System.EventArgs args) [0x0000f] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Views\AboutPage.xaml.cs:22
at Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:187
at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x0001f] in D:\a\1\s\Xamarin.Forms.Core\ButtonElement.cs:61
at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Button.cs:173
at Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick (Xamarin.Forms.VisualElement element, Xamarin.Forms.IButtonController buttonController, Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\ButtonElementManager.cs:25
at Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick (Android.Views.View v) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\FastRenderers\ButtonRenderer.cs:72
at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.Views.View.cs:2252
at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.68(intptr,intptr,intptr)
Does anyone faced with this issue?
The PCSC library does not appear to explicitly support Android. In my experience, nugets that work with Xamarin.Android have explicit dependencies set for the platform, but this one does not.
The library tries to use P/Invoke wrappers around native code. You can see that there are implementations for a number of operating systems here, but I don't see any references to Android. The stack trace shows that the code is deciding to use the Linux wrapper, which makes sense. It's looking for the libpcsclite.so.1 native "C/C++" library, but it's not finding it. That library has a home page that does not reference Android.
The PCSC nuget docs state:
pcsc-sharp does not contain any device drivers. A PC/SC compliant
reader + driver is mandatory.
That's the libpcsclite.so.1 . Either your Android device doesn't provide it, or if it does, it's not in a location that your Android app can find it. My Android device (running Android 9) does not have that library in any of /system/*lib* directories, which means that at least for my device someone would need to compile that native library for the CPU (usually arm64) for the device. If you can either compile the native code yourself or find someone who has, AND the native code supports the reader on your Android device, then you could get the whole thing to work.
I don't have any experience with PCSC myself - just some experience with Xamarin and native libraries.
I making a game with Unity and I want to add some ADs. I added AdMob and when it shows AD game is crashing. Now I added appodeal and it crashes every time I start app on my android phone, but in playmode in Unity all OK.
In console I got this error:
Failed to parse Packages/manifest.json.
Exception:System.MethodAccessException: Method EDMInternal.MiniJSON.Json.Deserialize(string)' is inaccessible from methodGoogle.PackageManifestModifier.ReadManifest()'
at (wrapper managed-to-native) System.Object.__icall_wrapper_mono_throw_method_access(intptr,intptr)
at Google.PackageManifestModifier.ReadManifest () [0x00039] in Z:\tmp\tmp.SU4iki1OHB\third_party\unity\unity_jar_resolver\source\PackageManagerResolver\src\PackageManifestModifier.cs:89
UnityEngine.Debug:LogError(Object)
Google.Logger:Log(String, LogLevel) (at /Users/smiles/dev/src/unity-jar-resolver/source/VersionHandlerImpl/src/Logger.cs:136)
Google.PackageManifestModifier:ReadManifest() (at Z:/tmp/tmp.SU4iki1OHB/third_party/unity/unity_jar_resolver/source/PackageManagerResolver/src/PackageManifestModifier.cs:91)
Google.PackageManagerResolver:UpdateManifest(ManifestModificationMode, Boolean, Boolean, IEnumerable`1) (at Z:/tmp/tmp.SU4iki1OHB/third_party/unity/unity_jar_resolver/source/PackageManagerResolver/src/PackageManagerResolver.cs:329)
Google.PackageManagerResolver:CheckRegistries() (at Z:/tmp/tmp.SU4iki1OHB/third_party/unity/unity_jar_resolver/source/PackageManagerResolver/src/PackageManagerResolver.cs:117)
Google.PackageManagerResolver:m__0() (at Z:/tmp/tmp.SU4iki1OHB/third_party/unity/unity_jar_resolver/source/PackageManagerResolver/src/PackageManagerResolver.cs:78)
Google.RunOnMainThread:ExecuteNext() (at /Users/smiles/dev/src/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:486)
Google.RunOnMainThread:m__B() (at /Users/smiles/dev/src/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:536)
Google.RunOnMainThread:RunAction(Action) (at /Users/smiles/dev/src/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:343)
Google.RunOnMainThread:ExecuteAllUnnested(Boolean) (at /Users/smiles/dev/src/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:530)
Google.RunOnMainThread:ExecuteAll() (at /Users/smiles/dev/src/unity-jar-resolver/source/VersionHandlerImpl/src/RunOnMainThread.cs:512)
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
Also I got these warnings:
Cannot add menu item 'Assets/External Dependency Manager/Android Resolver/Display Libraries' for method 'PlayServicesResolver.MenuDisplayLibraries' because a menu item with the same name already exists.
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
Cannot add menu item 'Window/Google/Game Package Registry/Settings' for method 'PackageManagerResolver.ShowSettingsAlias' because a menu item with the same name already exists.
UnityEditor.EditorApplication:Internal_CallUpdateFunctions()
And 17 warnings like these.
I use this code to show AD in appodeal:
private void Initialize(bool isTesting)
{
Appodeal.setTesting(isTesting);
Appodeal.muteVideosIfCallsMuted(true);
Appodeal.initialize(APP_KEY, Appodeal.INTERSTITIAL | Appodeal.NON_SKIPPABLE_VIDEO);
}
public void ShowInterstitial()
{
if (Appodeal.isLoaded(Appodeal.INTERSTITIAL))
{
Appodeal.show(Appodeal.INTERSTITIAL);
}
}
I don't know what I can do. Help me please.
I know this is a pretty old question, but maybe my solution would be helpful in case someone will face same problem. In my case I had two different versions of ExternalDependencyManager in the project. I checked Assets/ExternalDependencyManager/Editor folder and there were duplicated libraries v1.2.152 and v1.2.150. I removed all files with v1.2.150 version and error had gone.
Everytime I try to open the Player settings, it will show only blank. And the error below will be shown in the console.
I have tried to follow this link: https://answers.unity.com/questions/1320634/unable-to-list-target-platforms-when-i-try-to-buil.html
But still didn't work.
CommandInvokationFailure: Failed to update Android SDK package list.
/Applications/Unity/Hub/Editor/2019.2.0b1/PlaybackEngines/AndroidPlayer/SDK/tools/bin/sdkmanager --list
stderr[
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
at com.android.repository.api.SchemaModule$SchemaModuleVersion.(SchemaModule.java:156)
at com.android.repository.api.SchemaModule.(SchemaModule.java:75)
at com.android.sdklib.repository.AndroidSdkHandler.(AndroidSdkHandler.java:81)
at com.android.sdklib.tool.SdkManagerCli.main(SdkManagerCli.java:103)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 4 more
]
stdout[
]
exit code: 1
UnityEditor.Android.Command.WaitForProgramToRun (UnityEditor.Utils.Program p, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.Command+WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg) (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.Android.SDKManager.UpdatePackagesList () (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.Android.SDKManager.HighestVersionInstalled (UnityEditor.Android.SDKManager+Component tool) (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.Android.AndroidPlatformIconProvider.GetCurrentSetAndroidSDKVersion () (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.Android.AndroidPlatformIconProvider.UpdateSDKVersion () (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.Android.AndroidPlatformIconProvider.get_targetSDKSupportsAdaptiveIcons () (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.Android.PlayerSettingsEditorExtension.IconSectionGUI () (at <4e05d4950c734693b0d63f05223d7a90>:0)
UnityEditor.PlayerSettingsEditor.IconSectionGUI (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.Modules.ISettingEditorExtension settingsExtension, System.Int32 sectionIndex) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs:803)
UnityEditor.PlayerSettingsEditor.OnInspectorGUI () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Inspector/PlayerSettingsEditor/PlayerSettingsEditor.cs:573)
UnityEditor.AssetSettingsProvider.OnGUI (System.String searchContext) (at /Users/builduser/buildslave/unity/build/Editor/Mono/Settings/Providers/AssetSettingsProvider.cs:94)
UnityEditor.SettingsWindow.DrawControls () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Settings/SettingsWindow.cs:322)
UnityEditor.SettingsWindow.DrawSettingsPanel () (at /Users/builduser/buildslave/unity/build/Editor/Mono/Settings/SettingsWindow.cs:313)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize) (at /Users/builduser/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:281)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Before, I can see some options so that I can try to build.
I was having this issue as well. Nothing worked until I did this:
Go Unity > Preferences, select External Tools, deselect everything
Close the Editor
Open the Editor, re-enable everything you deselected
Hit Play to force a refresh
Then build again and it'll work
I got the same error and fixed it in a different way.
Possible fix here Failed to update Android SDK Package List
I got the same error after importing the firebase SDK into Unity 2021.3.3f1. It turned out my system variable JAVA_HOME was not pointing to the Java used by Unity (which apparantly only caused a problem in combination with firebase).
To solve it I had to
change Windows 10 -> Settings -> System -> Edit System variables
Change the value of "JAVA_HOME" to my Unity Java version: "F:\Programs\Unity\2021.3.3f1\Editor\Data\PlaybackEngines\AndroidPlayer\OpenJDK"
Reboot my Computer (for the JAVA_HOME change to take effect)
In Unity: Click on Assets -> External Dependency Manager -> Android -> Resolve
Not sure if the last step was necessary. I tried a lot of things (including "regenerating project files" - from Unitys settings)
I am trying to use Xamarin Forms Previewer in my Project with MVVM Prism and Unity Container and I am getting this error:
Here is the extracted stack for reference:
Xamarin.VisualStudio.ActivationManager|Error|0| The renderer
encountered an error while rendering this file:
System.ArgumentNullException: Value cannot be null. Parameter name:
instance
at Microsoft.Practices.Unity.UnityContainer.RegisterInstance
(System.Type t, System.String name, System.Object instance,
Microsoft.Practices.Unity.LifetimeManager lifetime) in :0
at
Microsoft.Practices.Unity.UnityContainerExtensions.RegisterInstance[TInterface]
(Microsoft.Practices.Unity.IUnityContainer container, TInterface
instance) in :0
at SellerNS.Bootstrapper.RegisterTypes () in
C:\Users\myrepo\Bootstrapper.cs:48
at Prism.Unity.UnityBootstrapper.Run () in :0
at Prism.Bootstrapper.Run (Xamarin.Forms.Application app) in :0
at SellerNS.App..ctor () in C:\Users\myrepo\Seller\App.xaml.cs:20
at at offset 12 in file:line:column :0:0
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj,
System.Object[] parameters) in
/Users/builder/data/lanes/4009/3a62f1ea/source/mono/mcs/class/corlib/System.Reflection/MonoMethod.cs:661
I am using:
Visual Studio 2015 - 14.0.25424.00
Update 3 JDK 1.8.0_121
Xamarin 4.3.0.789-cycle9
Prism.Forms 6.0.1
Prism.Unity 6.1.1
Unity 4.0.1
Any idea how to fix it?
I was getting a similar error with the Xamarin Forms Previewer when using Prism and it was resolved by adding a empty default constructor in App.xaml.cs as indicated here: https://github.com/PrismLibrary/Prism/issues/1037
So adding public App() : this(null) { } to App.xaml.cs worked for me.
Also, once I made the suggested change above, I had to clean the whole solution, rebuild it and then restart Visual Studio before launching the Xamarin.Forms Previewer again to get it all working as required.
have been working on a project intended for iOS deployment. Until recently, we have been building and deploying to our client via webplayer. However, I am now attempting to shift to releasing builds on iOS . But, no matter what I try, when I go to compile the project I receive the following error messages:
Cross compilation job Mono.WebBrowser.dll failed.
UnityEngine.UnityException: Failed AOT cross compiler: /Applications/Unity_45/Unity.app/Contents/PlaybackEngines/iOSSupport/Tools/OSX/mono-xcompiler --aot=full,asmonly,nodebug,static,outfile="Mono.WebBrowser.dll.s" "Mono.WebBrowser.dll" current dir : /Users/admin/Desktop/UI_gg_current/Temp/StagingArea/Data/Managed
Env: Apple_PubSub_Socket_Render = '/tmp/launch-7SV8Ex/Render'
LOGNAME = 'admin'
PATH = '/usr/bin:/bin:/usr/sbin:/sbin'
TMPDIR = '/var/folders/7c/s32nkpmx0yvgw4mmw_5vhxx40000gn/T/'
MONO_PATH = '/Users/admin/Desktop/UI_gg_current/Temp/StagingArea/Data/Managed'
SSH_AUTH_SOCK = '/tmp/launch-wpdtRI/Listeners'
USER = 'admin'
GC_DONT_GC = 'yes please'
Apple_Ubiquity_Message = '/tmp/launch-cfnoHv/Apple_Ubiquity_Message'
SHELL = '/bin/bash'
__CF_USER_TEXT_ENCODING = '0x1F5:0:0'
GAC_PATH = '/Users/admin/Desktop/UI_gg_current/Temp/StagingArea/Data/Managed'
HOME = '/Users/admin'
COMMAND_MODE = 'unix2003'
result file exists: False. Timed out: False
stdout:
stderr:
at UnityEditor.MonoProcessUtility.RunMonoProcess (System.Diagnostics.Process process, System.String name, System.String resultingFile) [0x00000] in <filename unknown>:0
at UnityEditor.MonoCrossCompile.CrossCompileAOT (BuildTarget target, System.String crossCompilerAbsolutePath, System.String assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, System.String input, System.String output, System.String additionalOptions) [0x00000] in <filename unknown>:0
at UnityEditor.MonoCrossCompile+JobCompileAOT.ThreadPoolCallback (System.Object threadContext) [0x00000] in <filename unknown>:0
UnityEditor.HostView:OnGUI()
and
Error building Player: UnityException: Cross compilation failed.
I am using Unity 4.5. To date I have : deleted third party dlls (including xml.linq.dll) , removed any instance of Lambda search operators (=>), and deleted the temp folder because I have seen these approaches used in similar situations (I know some aspects of Linq are not supported in iOS cross compile).
I have looked at similar issues such as this one: http://answers.unity3d.com/questions/439367/cross-compilation-failed-csharpdll.html. But, I am so perplexed, because it isn't the CSharp assembly causing my problem (which means it isn't one of my scripts?) I am not sure why it would even be including a WebBrowser.dll for an iOS build. Any help is greatly appreciated, as I feel I have searched far and wide for a resolution with no luck.
See the resolution that for this question here.