Unity error with Firebase RealTime Database - c#

I have been using Unity for a year now and have decided to make a simple chat app. I decided to use Google's Firebase to store my user and chat data. I plan to have the app on android(iOS in the future). My problem is with Unity not being able to generate a Firebase Android File. I searched the error up and it took me to this website. I did the recommend solution and created the realtime database and re installed the json and plist files. It did not work. I still get the following error.
Generation of the Firebase Android resource file google-services.xml from /Users/Family/Desktop/கலைமாறன்/Unity/STEMastery/Assets/../Assets/Firebase Data/google-services.json failed.
If you have not included a valid Firebase Android resources in your app it will fail to initialize.
"python" "/Users/Family/Desktop/கலைமாறன்/Unity/STEMastery/Library/PackageCache/com.google.firebase.app#7.2.0/Firebase/Editor/generate_xml_from_google_services_json.py" -i "/Users/Family/Desktop/கலைமாறன்/Unity/STEMastery/Assets/../Assets/Firebase Data/google-services.json" -o "/Users/Family/Desktop/கலைமாறன்/Unity/STEMastery/Assets/../Assets/Plugins/Android/FirebaseApp.androidlib/res/values/google-services.xml" -p "com.maranstudios.stemastery.maran" ...
I also checked the external tools. Under android it says JDK installed with Unity, Android SDK tools installed with Unity, Android NDK Installed with Unity and Gradle Installed with Unity. I also donwloaded the android studio so I can build to android.
I have also tried to restarted unity, visual studio and even my computer, but that did not help.
Unity runs the program perfectly well on my iMac and can access my RealTime Database in the unity editor. But when I run it on my phone 2 errors pop up.
DllNotFound Exception: Firebase CppApp ...
It can not find the default reference.
2's Explanation:
I have this line of code.
DatabaseReference reference = FirebaseDatabase.DefaultInstance.RootReference;
I then check in another script if t hat is null. It becomes null on my phone, but works fine on my mac.
I am using macOS Mojave (Version 10.14.4).
My unity version is Unity 2020.3.4f1.
My phone uses android 10.
I have tried everything that I can think of to deal with this error. I believe that by fixing this error, my app will work properly on my phone. I have tried to give all the information needed to help you understand my issues. If I am still missing any, please ask and I will respond as soon as possible.
EDIT :
I tried a couple new things. I upgraded to unity 2020.7, but that did not work. I also tried to create a new project from scratch using Unity 2019, but I am still getting that same error. Could it be that Firebase just doesn't work on my mac or is that this a bug in Unity that has somehow existed over several versions? I really could use some help figuring out to integrate Firebase. Any help is appreciated.

This is a known issue with developers who have non-ascii usernames. See this issue and this issue. It might be worth opening a new issue and highlighting that it's blocking active development right now (note for future readers, the first issue is closed but the second is open as I write. If 690 is also closed with a milestone associated, this means that the issue has been fixed).
For potential workarounds, the best known workaround would be to use a username without any extended non-ascii characters. I know that this can be problematic or disruptive.
You may try disabling persistence in the Editor before making any database calls. This might prevent Firebase from trying to read your local data folder, avoiding the issue:
var database = FirebaseDatabase.DefaultInstance;
if (Application.isEditor) {
database.SetPersistenceEnabled(false);
}
var reference = database.RootReference;
You only have to do this once for your game (so maybe immediately after CheckAndFixDependenciesAsync), but putting it right before database access should makes my example code safer.

Related

Compilation error when creating new project in Unity

I'm totally new in Unity and C#, and it's the first time I download Unity.
The problem I'm facing is: Evertime I try to create a totally new project or open an official example project should contain no error, the Unity will say that there are compilation errors in my project, just like the screenshot below:
Error pop-up
This situation will happen in any different version of Unity, I have tried these versions: 2021.3.14, 2020.3.42, 2020.3.25, 2019.4.40.
And the error messages in console of each version are different, in 2021.3.14:
Error message in console
(This kind of disorderly code should be Chinese I think, the reason maybe the Chinese encoded question in Unity. But I don't know why, because the Unity Hub and Unity I installed are all from UK website)
In 2020.3.42 and 2020.3.25:
Error message in console
And in 2019.4.40 the error message is just like the error message in 2020 version, just the "Compiler version 3.5.0-dev" changes to "Compiler version 2.9.1" (I don't have the screenshot cause I have deleted the 2019 version).
Here I'll explain the process I download and install Unity:
I just have an anaconda preinstalled in my computer(which is related to the Unity), and for the first time, I also have the Visual Studio2019 installed in my computer(But I try to uninstall VS2019 before install Unity later, it doesn't work). And I download and install the Unity Hub from official website, then install the Unity 2021.3.14 in Unity Hub. That's all the process, I didn't change anything else in the system about Unity. (There is actually one another thing I have done, but I don't think it's a reason. I download the ml-agents plugin in github, and created a new anaconda environment for it, with just python3.6 and pytorch and ml-agents installed. Then I try to add ml-agents in Unity's packages even it's in compilation error state.)
Here is some info about my computer:
UK computer with Windows11, with anaconda, some jdk and SQL installed.
And here is the list of things I have tried, all from internet:
Change the "Api Compatibility Level*" in Edit->Project Settings->Player->Other Settings->Configuration
Download different version of Unity(as mentioned above)
Delete some packages that may cause this problem
Reimport all the assets of the project
Delete the Unity_lic.ulf file in the directory: C:\ProgramData\Unity and let Unity reload it
Somebody says this may be caused by some antivirus program, so I removed all the antivirus program on my computer (except virus defense program of win11, cause I don't know how to close it and I think it is better to not close it), and completely remove all the Unity files on my computer (probably, I don't know), the remove steps are:
(1) Delete the Unity Editor and Unity Hub files directly
(2) Delete temporary file related to Unity:
C:\ProgramData\Unity
C:\Users\Username\AppData\Local\Unity
C:\Users\Username\AppData\Local\unityhub-updater
C:\Users\Username\AppData\LocalLow\Unity
C:\Users\Username\AppData\Roaming\Unity
C:\Users\Username\AppData\Roaming\UnityHub
(3) Remove all the Unity related folders in windows registry(to ensure the thing I'm saying, to open this, press win+R, then type"regedit"):
HKEY_CURRENT_USER\Software\Unity
HKEY_CURRENT_USER\Software\UnityTechnologie
And reinstall the whole Unity in a totally different directory, to avoid the Unity influenced by the folder path name(like too long, or contains Chinese character), I create a new folder F:\Unity, and create four folder"Download", "Editor", "Hub", "Project" to hold download tem files, Unity Editor, Unity Hub and project file respectively. Then I download and install Unity Hub, then install Unity Editor in Unity Hub, create new project, and everything don't change...
P.S. I also download a Unity use the same process as me on the computer of my roommate. His computer is also win11, with anaconda and Visual Studio preinstalled. And everything went right, it just took me several minutes to successfully create a new project.
Can someone tell me what kind of things can influence the download process of Unity (Like other programming environment or IDE)? And how can I fix this problem?
You tried every possible solution maybe it's time to reinstall a clean windows.

This error is preventing me from building my UWP app on a new Xamarin Form project

I'm beginning my first Xamarin project. I started with setting up an android project and I have gotten it working with the emulator.
But after following the instructions of this video
(https://www.youtube.com/watch?v=mbIvG8ripcw&t=590s&ab_channel=GeraldVersluis)
I get the following error when I try to build:
Expected "!$([System.String]::new('%(ReferenceCopyLocalPaths.Identity)').EndsWith('System.Runtime.dll'))" to evaluate to a boolean instead of "!$([System.String]::new('E:\(PATH TO APP FOLDER)\Notes App\NotesApp\NotesApp\bin\Debug\netstandard2.0\NotesApp.dll').EndsWith('System.Runtime.dll'))", in condition "'$(_CoreFrameworkPackageId)' != ''
AND !$([System.String]::new('%(ReferenceCopyLocalPaths.Identity)').EndsWith('System.Runtime.dll'))
AND '%(ReferenceCopyLocalPaths.NuGetPackageId)' == '$(_CoreFrameworkPackageId)'". NotesApp.UWP
^^ The error code I get for this is MSB4100
I also keep having the Nuget packages Xamarin.Forms and the Microsoft.NETCore.UniversalWindowsPlatform go missing from the references of my project even though they are installed within it. After restarting VS multiple times and toggling on/off settings that alters the project/solution heavily they pop back into existance.
These packages when they go missing give me 10s and I even saw once, 200 errors and they all disappear after turning on and then off again, for example "Compile with .NET Native tool chain" in the build settings.
But the big error above still remains.
========================================
All Nuget packages are up to date and VS is up to date (and I used the repair tool).
I've removed the UWP project and created a new one, and I get the same result.
If anyone can help me solve this and let me know if I've made a silly mistake it would be appreciated. I would like to master this.
If you need any more info let me know, thanks.
Update 1
I've reinstalled my nuget packages and restarted VS and this is my screen. Note I have the package on screen installed but not showing up in my references. Plus some warnings that go away when they feel like it.
Update 2
I created a brand new xamarin android and uwp project template, did not touch a thing, and I tried to build and deploy the uwp project and I get this error
I created a project that was not buring by many layers of folders, in my C drive and not my external exFAT E drive and it now works.
Thanks for your help guys.

Xamarin.Android.Common.Debugging.targets(604,5): error XA0010: No available device

Whenever I try to start the HelloMaui project from VS Code using NET 6.0.100 Preview4 with mono debug extension installed and run it it throws an error Xamarin.Android.Common.Debugging.targets(604,5): error XA0010: No available device. I wonder if anyone had a problem running the sample project?
The same bug has been reported 3 days ago in the official repo https://github.com/dotnet/maui/issues/1197, as MAUI still in an early stage it better to follow on the official repo.
Try to ensure that the emulator is ready before debugging the app (build+deploy), by starting it manually.
Not sure how to do it from vs code but probably will be common for command line:
Navigate to C:\*\Android\android-sdk\emulator
emulator -list-avds
You should see at least one emulator name otherwise you need to install one.
emulator.exe -avd NameOfYourEmulator -partition-size 512 NameOfYourEmulator taken from the previous step.
Docs
https://learn.microsoft.com/en-us/xamarin/android/deploy-test/command-line-emulator
Edit
If the returned list of Android device emulators is empty (from step 2) and you are sure you have at least one emulator previously added/installed then try unloading and reloading the android project.
If you are not sure, you may open Android device manager from visual studio and check the listed devices there, if empty then you need to add at least one.
Related issue Maui-check fails on Android Emulator Setup

Visual Studio Code suddenly lost autocomplete with Unity

I have been programming on Unity with VSCode for the past two months and had very few issues about it. But suddenly, it has stopped the autocomplete, even thought I tried several approaches that I found online.
I have all the extensions needed for the development (C# (1.22), Debugger for Unity(2.7.5), Unity Code Snippets (1.3.0), Unity Tools (1.2.3) and am currently using Unity 2019.3.8f1 on Windows 10.
I have already changed the External Script Editor to work with VSCode but with no luck. I have also tried to delete all .csproj files, to restart computer/internet, all with no luck either
It says on my output panel that it is installing C# dependencies, but it never ends downloading them.
What is the possible cause of this problem ? I have found that many people have this kind of error, but they are always when trying to use VSCode with Unity for their first time. In my case I have been using for a long time and it has suddenly stopped.
Thanks in advance.
C# vscode extensions works by having the actual c# heavy lifting in a separate language server process "omnisharp.exe", and actual typescript extensions is mostly glue. So whenever c# extension gets updated, extensions manually downloads new version of omnisharp.exe.
As far as I know, all language services are turned off while new omnisharp.exe is downloading. Why your download is failing, I can't tell you really without more info, it could be something on your end.
I suggest you first try to uninstall/install c# extensions, as that may help if extension folder got corrupted in any way. If that doesn't help, try setting "omnisharp.path" vscode settings to "1.35.2" or "1.35.1" or similar, to manually target version.

Can't build Unity app using App Bundle for android. File uses reserved file or directory name 'res'

I have to build android app using Unity 2018.4.9f1 with App Bundle (Google play) and I get this error. When building normal apk everything is working fine.
1 exception was raised by workers:
com.android.tools.build.bundletool.exceptions.BundleFileTypesException$FileUsesReservedNameException: File 'root/res/drawable-hdpi/ic_launcher.png' uses reserved file or directory name 'res'.
Tried diffrent unity versions. Tried deleting this file (but looks like it's hidden somewhere or generating during gradle compile)
I'm using Unity 2019.4.0f1 and got stuck in the same error. Here's what I've found on internet and solved.
(you probably got a solution, but it's good for those who will see this post)
Open your project settings > Player > Other Settings, loko for configuration, make sure you ticked this options below:
Player setup
Scripting Backend IL2CPP
Enable ARMv7, ARM64, Split APKs by target architecture
Then in your Build Settings
Build settings setup
Just default values (unity 2019.4 version).
Hope that helps someone :)
[edit 1]
I know this doesn't fix the android bundle app build, I think that's an unity bug, not sure, however this should work fine on google play console (worked for me)

Categories