Can Google cloud services work with Unity? - c#

I am trying to include Google speech api in my unity app.
I have followed all the steps in the api documentation for c# https://cloud.google.com/speech-to-text/docs/quickstart-client-libraries#client-libraries-install-csharp . I installed this package "Install-Package Google.Cloud.Speech.V1 -Pre" through NuGet package manager but no google references are being shown. This results to the error "The type or namespace name 'Google' could not be found (are you missing a using directive or an assembly reference?)". I checked these possible duplicates but to no avail "The type or namespace name 'Google' could not be found", "The type or namespace could not be found". Switching platform within unity from android to windows shows the google references but without resolving the error.
using Google.Cloud.Speech.V1;
using System;
namespace GoogleCloudSamples
{
public class SpeechGoogle
{
public static void Main(string[] args)
{
var speech = SpeechClient.Create();
var response = speech.Recognize(new RecognitionConfig()
{
Encoding = RecognitionConfig.Types.AudioEncoding.Linear16,
SampleRateHertz = 16000,
LanguageCode = "en",
}, RecognitionAudio.FromFile("audio.raw"));
foreach (var result in response.Results)
{
foreach (var alternative in result.Alternatives)
{
Console.WriteLine(alternative.Transcript);
}
}
}
}
}
The error occurs from the first code line "using Google.Cloud.Speech.V1;". Is it possible that unity cannot support google cloud services or am I missing a step?

No, we don't support Unity (or Xamarin) in any of the Google Cloud Client Libraries.
Our supported platforms documentation. It's possible that the REST-based libraries can work on Unity, but we don't support that, and in particular the auth aspects are very likely to fail or require custom code.
To be clear, we'd like to support more platforms, but there's a pretty significant human cost involved in doing so, particularly for gRPC-based libraries where there's a native code component, and also particularly in terms of testing across a whole bunch of client platforms and Unity versions.

Related

Unity + Firebase: Unable to load DLL 'FirebaseCppApp-10_3_0'

I am using Unity 2021.3.11f1 to implement Firebase 10.3.0 Analytics + Crashlytics for an Android Game.
After a few tests without anything showing up in the Google Dashboard, I figured something was wrong with the Firebase initializing.
As soon as I launch the game on my Android device, this is one of the first things seen in logcat:
01-05 15:51:45.078 32211 2657 E Unity : DllNotFoundException: Unable to load DLL 'FirebaseCppApp-10_3_0'. Tried the load the following dynamic libraries: Unable to load dynamic library 'FirebaseCppApp-10_3_0' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "FirebaseCppApp-10_3_0" not found
01-05 15:51:45.078 32211 2657 E Unity : at Firebase.AppUtilPINVOKE+SWIGExceptionHelper.SWIGRegisterExceptionCallbacks_AppUtil (Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate applicationDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate arithmeticDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate divideByZeroDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate indexOutOfRangeDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate invalidCastDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate invalidOperationDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+ExceptionDelegate ioDelegate, Firebase.AppUtilPINVOKE+SWIGExceptionHelper+E
Here is what my Android Libraries with dependencies looks like:
(NB: At this point I tried installing Firebase 9.6.0 instead, that's why it doesn't say 10.3.0 here)
([rootProject] + (rootProject.subprojects as List)).each { project ->
project.repositories {
def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
maven {
url "https://maven.google.com"
}
maven {
url (unityProjectPath + "/Assets/Firebase/m2repository") // Assets/Firebase/Editor/AnalyticsDependencies.xml:18, Assets/Firebase/Editor/AppDependencies.xml:22, Assets/Firebase/Editor/CrashlyticsDependencies.xml:20
}
mavenLocal()
mavenCentral()
}
}
dependencies {
implementation 'com.google.android.gms:play-services-base:18.1.0' // Assets/Firebase/Editor/AppDependencies.xml:17
implementation 'com.google.android.play:asset-delivery:2.0.0' // Assets/GooglePlayPlugins/com.google.play.assetdelivery/Editor/Dependencies.xml:3
implementation 'com.google.android.play:core-common:2.0.0' // Assets/GooglePlayPlugins/com.google.play.core/Editor/Dependencies.xml:3
implementation 'com.google.firebase:firebase-analytics:21.1.1' // Assets/Firebase/Editor/CrashlyticsDependencies.xml:15
implementation 'com.google.firebase:firebase-analytics-unity:9.6.0' // Assets/Firebase/Editor/AnalyticsDependencies.xml:18
implementation 'com.google.firebase:firebase-app-unity:9.6.0' // Assets/Firebase/Editor/AppDependencies.xml:22
implementation 'com.google.firebase:firebase-common:20.1.2' // Assets/Firebase/Editor/AppDependencies.xml:13
implementation 'com.google.firebase:firebase-crashlytics-ndk:18.2.13' // Assets/Firebase/Editor/CrashlyticsDependencies.xml:13
implementation 'com.google.firebase:firebase-crashlytics-unity:9.6.0' // Assets/Firebase/Editor/CrashlyticsDependencies.xml:20
}
android {
packagingOptions {
exclude ('/lib/armeabi/*' + '*')
exclude ('/lib/armeabi-v7a/*' + '*')
exclude ('/lib/mips/*' + '*')
exclude ('/lib/mips64/*' + '*')
exclude ('/lib/x86/*' + '*')
exclude ('/lib/x86_64/*' + '*')
}
I run the usual 'CheckAndFixDependencies' and do not get any errors during this. I've also managed to get this working before in another project without problems, but no matter what I do it seems like the 'Core' app of firebase won't start due to not being able to find the DLL.
I tried both Firebase SDK 10.3.0 and 9.6.0 with the same results.
When I find the DLL that it claims to be missing in Unity (Assets/Firebase/Plugins/x86_64/FirebaseCppApp-9_6_0.dll) it stands as being included in every platform, Editor as well as standalone.
I've forced countless amounts of dependency resolves, without luck.
I tried disabling the target architecture ARMv7 (Because I saw someone suggesting it in another post about this). No help either unfortunately.
I'm currently testing with apk so I don't have to work through aab atm, but I really doubt that should cause Firebase issues.
Am I missing something extremely obvious / being blind here?
I have the same issue. I will try many tries but it isn't work.
At the end of the second day, I have tried create a new empty project and add it from
https://developers.google.com/unity/archive#firebase_app_core
in package manager as tarball tgz files:
external dependency tgz
firebase app (core) tgz
for me its firebase analytics for you its another firebase tgz
Those tgz must be the same version in my case first install 10.3 it isn't work.
Second i download 9.6 tgz files. And it's working.
But I have a new error in the console: Database URL not set in the Firebase config.
It's solved in firebase account you need to create realtime database, and downloaded the new google-services.json. Then in Unity remove old google-services.json and clean Assets\StreamingAssets folder. Import new google-services.json. And it worked.
Then I tried in my work project. I remove all firebase sdk folders and did the same. And its works fine!

.NET Core WPF-Application Build Error with dynamic typecast

I'm currently trying to create a plugin with GUI (WPF) for Solidworks using the Solidworks API. I created the project with visual Studio 2019 using .net-core 3.1. This API mostly uses functions with returntype dynamic. I used this code before for a console application (also using .net-core 3.1) wihtout getting any building-errors.
using SW = SldWorks;
using System.Windows;
namespace dfdfdf
{
public partial class App : Application
{
private void App_Startup(object sender, StartupEventArgs e)
{
//Connect to SW
SW.SldWorks SolidWorksApp = null;
SW.ModelDoc2 swDoc;
SolidWorksApp = new SldWorks.SldWorks();
//Connect to Document --> Build Error
swDoc = SolidWorksApp.ActiveDoc;
}
}
}
Now with the WPF project I get the following error:
The error is only shown when "only build" is selected on the error list
CS2066 (Cannot implicitly convert type ‘type1’ to ‘type2’. An explicit conversion exists (are you missing a cast?))
"ActiveDoc" has a dynamic as return-value and using the explicit conversion works fine:
swDoc = (SW.ModelDoc2) SolidWorksApp.ActiveDoc;
but I'm wondering why this causes an error in a WPF application but not in a console application. As far as I understand it I shouldn't get a build errors at all when casting a dynamic since the type-conversion is done on runtime and not on buildtime.
For the COM-References i activated the option "embedded interoptypes", is there any other option I missed that causes this behaviour?
If .core needs the explicit casts I'm fine with that. I just hope one of you guys can tell me why there is a difference between wpf and console applications regarding this.
Thanks!
Check this video, but I would strongly recommend against .NET Core/.NET5-6 for SOLIDWORKS add-ins due to many compatibility issues. Use.NET Framework instead for add-ins and it is OK to use .NET Core for stand-alone applications.

Xamarin.Forms Error CS0246 'Foundation' could not be found

I've created an APP(Xamarin.forms) in Visual Studio 2017.
I want to add wifi connection function into my iOS project (using NEHotspotConfigurationManager) and compile the following code on Mac:
bool success = await UIApplication.SharedApplication.OpenUrlAsync(
NSUrl.FromString(UIApplication.OpenSettingsUrlString), options: new UIApplicationOpenUrlOptions());
var config = new NEHotspotConfiguration(ssid, password, isWep: false);
config.JoinOnce = false;
var tcs = new TaskCompletionSource<NSError>();
NEHotspotConfigurationManager.SharedManager.ApplyConfiguration(config, err => tcs.SetResult(err));
var error = await tcs.Task;
if (error != null)
{
var alert = new UIAlertController
{
Title = "Error",
Message = error.Description
};
alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
PresentViewController(alert, true, null);
return;
}
Even though I can see "Add reference 'Xamarin.iOS.dll'" when I have a right-click on the red words, but it still appears three errors about Foundation, UIKit, and NetworkExtension not being found after I compiled the project.
Error CS0246 The type or namespace name 'Foundation' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'UIKit' could not be found (are you missing a using directive or an assembly reference?)
Error CS0246 The type or namespace name 'NetworkExtension' could not be found (are you missing a using directive or an assembly reference?)
I check the 'Xamarin.iOS' in the reference list in iOS project(Modbusbutton3.iOS) with the version 0.0.0.0
enter image description here
However, the reference 'Xamarin.iOS' in the project(Modbusbutton3) is blank. I don't know whether it's related to my problem
enter image description here
I found that the reference 'Xamarin.iOS' in the project(Modbusbutton3) showed a red error with
"Assembly not found for framework .NET Protable Subset (.NET Framework 4.5, Windows 8, Windows Phone 8.1, Windows Phone Silverlight 8)"
enter image description here
What should I do with this problem?
The problem with what you are trying to do is that, you need to understand that there is a separation of concerns/abstraction. The Core project is referenced by the Android & iOS projects, but the Android & iOS projects are not referenced by the Core project. Schematically,
Core-->Android & Core-->iOS but
Core<-x-Android, Core<-x-iOS
This is by design, and even though you can make it do what you are trying, you shouldn't.
We know that the iOS & Android SDKs are very different. So in order to perform wifi connection functionality (NEHotspotConfigurationManager), you have to perform different functions underneath. And the code that you shared is the correct way of retrieving the path/file name natively ONLY for iOS.
In order to make it work, there's also many other ways of doing this as shown in the official Microsoft docs here.

How to use library which include Xamarin.iOS in Unity?

I created dll which include Xamarin.iOS by Visual Studio 2017.
using JavaScriptCore;
using Foundation;
namespace JSCore
{
public static class MyClass
{
public static int Test()
{
JSContext jsContext = new JSContext();
jsContext[new NSString("arg1")] = JSValue.From(2, jsContext);
jsContext[new NSString("arg2")] = JSValue.From(2, jsContext);
var jsResult = jsContext.EvaluateScript("arg1 + arg2;");
return jsResult.ToInt32();
}
}
}
I want to use this library in Unity.
I put this dll in Unity Plugins folder and write script (call MyClass.Test()).
In Editor, there is no error. But when I build project, some error appeared.
IL2CPP error for method 'System.Void ObjCRuntime.Runtime::set_UseAutoreleasePoolInThreadPool(System.Boolean)' in assembly '/Users/[MyName]/Documents/JavaScriptRuntimeTest/Temp/StagingArea/Data/Managed/Xamarin.iOS.dll'
Additional information: Build a development build for more information. Object reference not set to an instance of an object.
I read error sentence. I think this is the version error about System.dll.
Xamarin.iOS reference System.dll 2.0.5.0.
Unity's API Compatibility Level is .NET Standard 2.0.
How to avoid this error ?
Unity's Mono runtime isn't compatible with Xamarin, so the only possibility to use your library is to remove the IOS part.

Visual Studio Team Services API Example Throwing System.Net.Http Error

I'm trying to write an application that communicates with Visual Studio Team Services, using the Nuget packages listed here.
The example code is directly from Microsoft's official documentation, on same same page the packages are listed, under "Pattern for use". My test code is in a console application, set to version 4.7 of the .net framework (compiled by Visual Studio 2017 15.2(26430.16) Release, but I don't think that matters). The code is identical to Microsoft's example, other than changing the connection url, project, and repo name.
The only Nuget package directly installed (about 30 others are installed as dependencies) is Microsoft.TeamFoundationServer.ExtendedClient.
Install-Package Microsoft.TeamFoundationServer.ExtendedClient
using System;
using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;
namespace vssApiTest
{
class Program
{
const String c_collectionUri = "https://[[redacted]].visualstudio.com/DefaultCollection";
const String c_projectName = "Inspections";
const String c_repoName = "Src";
static void Main(string[] args)
{
// Interactively ask the user for credentials, caching them so the user isn't constantly prompted
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();
// Connect to VSTS
VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);
// Get a GitHttpClient to talk to the Git endpoints
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();
// Get data about a specific repository
var repo = gitClient.GetRepositoryAsync(c_projectName, c_repoName).Result;
}
}
}
On the line VssConnection connection = new VssConnection(new Uri(c_collectionUri), creds);, a TypeLoadException is thrown (at run-time) with the message:
Inheritance security rules violated by type:
'System.Net.Http.WebRequestHandler'. Derived types must either match
the security accessibility of the base type or be less accessible.
None of the Google search variants I've tried on this error message have returned anything helpful.
Am I doing something wrong, is the example code I'm following wrong, or is there some other issue going on?
The problem was due to a bug introduced in version 4.1.0 of the System.Net.Http Nuget package, as discussed here.
The solution was to update that Nuget package to the latest version (4.3.2 at this time, it may have been fixed in earlier versions also).

Categories

Resources