Android Build gives errors on Android 14, but works with Android 13 and earlier

Hello everyone. This is my first time posting in this forum, so apologies for any mistakes. I’ve been trying to resolve this issue on my own for some time, but I haven’t found any solutions at all and have basically arrived at a dead end. So I would appreciate any assistance.

The basic gist of it is that I am trying to make an Android 14 build of my project, but for some reason I do not understand, it is giving me an error that makes the project not fully playable. I am able to build for Windows and for earlier versions of Android (like Android 13, for example) without any problems. The error message doesn’t pop up, and the devices work as intended. However, it is just for Android 14 builds specifically that I just cannot get it to work.

Here is the error message I keep getting. Sometimes the specific error is different, but they generally lead to the same place. I keep getting Null Reference Exceptions that lead back to Microsoft.CSharp, which just doesn’t make sense to me.

--- App Info ---
App name: Endarth-LWRP
Bundle identifier: com.DefaultCompany.EndarthLWRP
App version: 1.0 (1)
Unity version: 2022.3.44f1
--- Device Info ---
Device name: Galaxy Note20 5G
Device model: samsung SM-N981B
Operation system: Android OS 13 / API-33 (TP1A.220624.014/N981BXXSDHXH1)
System language: Spanish
Device orientation: FaceUp
Connectivity: Local (LAN/Wifi)
--- CPU Info ---
CPU type: ARM64 FP ASIMD AES (8 core(s))
CPU speed: 2730 MHz
System memory size: 7443 MB
Allocated memory: 337,55 MB
Reserved memory: 516,36 MB
Mono used memory: 70,38 MB
--- GPU Info ---
GPU: Mali-G77
Graphic memory size: 2048 MB
Screen size: 1920x1080@60Hz
Screen dpi: 450
[01:37:39.77]  NullReferenceException: Object reference not set to an instance of an object.
Microsoft.CSharp.RuntimeBinder.Semantics.ExpressionTreeRewriter.VisitBoundLambda (Microsoft.CSharp.RuntimeBinder.Semantics.ExprBoundLambda anonmeth) (at <00000000000000000000000000000000>:0)
Microsoft.CSharp.RuntimeBinder.Semantics.ExpressionTreeRewriter.Rewrite (Microsoft.CSharp.RuntimeBinder.Semantics.ExprBoundLambda expr) (at <00000000000000000000000000000000>:0)
Microsoft.CSharp.RuntimeBinder.RuntimeBinder.CreateExpressionTreeFromResult (System.Linq.Expressions.Expression[] parameters, Microsoft.CSharp.RuntimeBinder.Semantics.Scope pScope, Microsoft.CSharp.RuntimeBinder.Semantics.Expr pResult) (at <00000000000000000000000000000000>:0)
Microsoft.CSharp.RuntimeBinder.RuntimeBinder.BindCore (Microsoft.CSharp.RuntimeBinder.ICSharpBinder payload, System.Linq.Expressions.Expression[] parameters, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject& deferredBinding) (at <00000000000000000000000000000000>:0)
Microsoft.CSharp.RuntimeBinder.RuntimeBinder.Bind (Microsoft.CSharp.RuntimeBinder.ICSharpBinder payload, System.Linq.Expressions.Expression[] parameters, System.Dynamic.DynamicMetaObject[] args, System.Dynamic.DynamicMetaObject& deferredBinding) (at <00000000000000000000000000000000>:0)
Microsoft.CSharp.RuntimeBinder.BinderHelper.Bind (Microsoft.CSharp.RuntimeBinder.ICSharpBinder action, Microsoft.CSharp.RuntimeBinder.RuntimeBinder binder, System.Dynamic.DynamicMetaObject[] args, System.Collections.Generic.IEnumerable`1[T] arginfos, System.Dynamic.DynamicMetaObject onBindingError) (at <00000000000000000000000000000000>:0)
Microsoft.CSharp.RuntimeBinder.CSharpBinaryOperationBinder.FallbackBinaryOperation (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject arg, System.Dynamic.DynamicMetaObject errorSuggestion) (at <00000000000000000000000000000000>:0)
System.Dynamic.BinaryOperationBinder.FallbackBinaryOperation (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject arg) (at <00000000000000000000000000000000>:0)
System.Dynamic.DynamicMetaObject.BindBinaryOperation (System.Dynamic.BinaryOperationBinder binder, System.Dynamic.DynamicMetaObject arg) (at <00000000000000000000000000000000>:0)
System.Dynamic.BinaryOperationBinder.Bind (System.Dynamic.DynamicMetaObject target, System.Dynamic.DynamicMetaObject[] args) (at <00000000000000000000000000000000>:0)
System.Dynamic.DynamicMetaObjectBinder.Bind (System.Object[] args, System.Collections.ObjectModel.ReadOnlyCollection`1[T] parameters, System.Linq.Expressions.LabelTarget returnLabel) (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.CallSiteBinder.BindCore[T] (System.Runtime.CompilerServices.CallSite`1[T] site, System.Object[] args) (at <00000000000000000000000000000000>:0)
System.Runtime.CompilerServices.CallSiteOps.Bind[T] (System.Runtime.CompilerServices.CallSiteBinder binder, System.Runtime.CompilerServices.CallSite`1[T] site, System.Object[] args) (at <00000000000000000000000000000000>:0)
System.Reflection.RuntimeMethodInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Exception& exc) (at <00000000000000000000000000000000>:0)
System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at <00000000000000000000000000000000>:0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at <00000000000000000000000000000000>:0)
System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) (at <00000000000000000000000000000000>:0)
System.Linq.Expressions.Interpreter.Interpreter.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) (at <00000000000000000000000000000000>:0)
System.Linq.Expressions.Interpreter.LightLambda.Run3[T0,T1,T2,TRet] (T0 arg0, T1 arg1, T2 arg2) (at <00000000000000000000000000000000>:0)
PreGameplaySelection.<SelectMapID>b__113_0 () (at <00000000000000000000000000000000>:0)
NFCReader.CardOnField (System.Object data) (at <00000000000000000000000000000000>:0)
UILerpPos..ctor () (at <00000000000000000000000000000000>:0)
UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <00000000000000000000000000000000>:0)
UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.UpdateOnStreaming (System.Boolean binaryMode) (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.ReadUpdate () (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.Update () (at <00000000000000000000000000000000>:0)
--- End of stack trace from previous location where exception was thrown ---
System.Linq.Expressions.Interpreter.ExceptionHelpers.UnwrapAndRethrow (System.Reflection.TargetInvocationException exception) (at <00000000000000000000000000000000>:0)
System.Linq.Expressions.Interpreter.MethodInfoCallInstruction.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) (at <00000000000000000000000000000000>:0)
System.Linq.Expressions.Interpreter.Interpreter.Run (System.Linq.Expressions.Interpreter.InterpretedFrame frame) (at <00000000000000000000000000000000>:0)
System.Linq.Expressions.Interpreter.LightLambda.Run3[T0,T1,T2,TRet] (T0 arg0, T1 arg1, T2 arg2) (at <00000000000000000000000000000000>:0)
PreGameplaySelection.<SelectMapID>b__113_0 () (at <00000000000000000000000000000000>:0)
NFCReader.CardOnField (System.Object data) (at <00000000000000000000000000000000>:0)
UILerpPos..ctor () (at <00000000000000000000000000000000>:0)
UnityEngine.Events.InvokableCall`1[T1].Invoke (T1 args0) (at <00000000000000000000000000000000>:0)
UnityEngine.Events.UnityEvent`1[T0].Invoke (T0 arg0) (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.UpdateOnStreaming (System.Boolean binaryMode) (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.ReadUpdate () (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.Update () (at <00000000000000000000000000000000>:0)

I would say the generally accepted approach in such a case is to isolate the condition that the error. You do that by commenting/stubbing out large chunks of code and testing the result.

Start with minimal code that works and keep adding back functionality until you see the error occur.

hey there! Thanks for the reply. I have been certainly doing such, at least as much as I am able to. However, if you look at the actual error logs, you’ll see the problem. Firstly, it’s not telling me which line in the code the error is generating. I’ve been able to stop the error from occurring at several earlier points, but so far I’ve been unable to find where the exact place is because it never identifies the actual line. Secondly, some of the sections mentioned in the error don’t exist in my code, or aren’t connected. For example, the SelectMapID function in my PreGameplaySelection script is never called by SerialPortUtility. Thirdly, the NullReferenceException leads to Microsoft.CSharp library, a library I’ve most definitely not coded, and one that I am not sure I am even able to edit.

I would be very happy if this was such say, a regular error. But like I mentioned before, it seems to be related more with the way Unity generates Android Builds with Android 14 rather than actual code in my project.

Sounds like trouble :slight_smile: I surely don’t know what the issue is only (perhaps) what I might do under the circumstances. It could be a bug in a library, it may be a setting you’ve included or omitted when building for Android. And of course, it could be something else entirely.

Starting a new project and copying the “parts” over while watching for warnings and errors might work. Wish I could be of more help.

Honestly this smells more like a code bug than a build error.

Judging just from stack trace noise, perhaps one of your Linq statements is blowing up, who knows for what reason. Looks like it might be catching and re-throwing an exception? It looks like perhaps some lambda-making mechanism failed, but not really sure. I would start there, see if you can track down which one it might be.

Another thing to check is that if you hook up code to callbacks on that serial port, make sure none of them call Unity methods if they aren’t on the main thread. Apparently you CAN call Debug.Log() off the main thread, even if the docs don’t promise it will work.

Since IL2CPP currently strips out all the line numbers and addresses, you get to do it the hard way with “debug printfs” as we used to call it, or basically logging. Yay IL2CPP!!!

Alternately, make a development build and attach the debugger!

Either way, in the off chance it is a build error, here’s the usual list:

How to troubleshoot build failures:

Obviously, if there is actionable data, clues or information within any of the errors, fix those problems. Each error entry may have more information than can fit in the console log so select each error and read the expanded view below it.

If that gives you nothing worthwhile (look to Google! You’re never the first one!), then…

First, make a blank project with a single blank scene and prove that it builds successfully.

If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

Until you can build a blank project to the target platform, don’t fiddle with anything else.

Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

Most often things that prevent building are third-party libraries such as Firebase.

Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

Android build not building:

Circa July 2022 here have been reports of Unity’s installer failing to install the Android Tools.

Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022 (edited on August 23, 2023 to include Android SDK 33…) (and again for SDK34):

Android Gradle errors and other related stuff:

Hello, thanks for the in depth-reply.

When I said it was a build error, I didn’t mean that the build didn’t work. Everything in my project basically works, it’s just that there’s this single element of the build that specifically doesn’t work on Android 14. The code literally works everywhere else, mind you. If I build for windows, it works. If I build for Android 13, it works. Hell, if I build for Android 14 in Mono it also works (but then when it tries to install in Android 14, it fails). So I’m not sure where to go from this point. I’ve tried putting some logs and what not to help me out but I might just not be skilled enough to know what is breaking my code but only on Android 14 builds.

Here’s another reason why I feel it’s a build error than anything code related. I tried building for Unity 2020 (This was the original version of our project), and it gives me an entirely different error for a different section of the code. Taking into consideration it has the same behavior, building without any problem for anything other than Android 14.

--- App Info ---
App name: Endarth-LWRP
Bundle identifier: com.DefaultCompany.EndarthLWRP
App version: 1.0 (1)
Unity version: 2020.3.33f1

--- Device Info ---
Device name: <unknown>
Device model: samsung SM-N981B
Operation system: Android OS 13 / API-33 (TP1A.220624.014/N981BXXSDHXH1)
System language: Spanish
Device orientation: FaceUp
Connectivity: Local (LAN/Wifi)

--- CPU Info ---
CPU type: ARM64 FP ASIMD AES (8 core(s))
CPU speed: 2730 MHz
System memory size: 7443 MB
Allocated memory: 274,65 MB
Reserved memory: 455,11 MB
Mono used memory: 35,54 MB

--- GPU Info ---
GPU: Mali-G77
Graphic memory size: 2048 MB
Screen size: 1920x1080@60Hz
Screen dpi: 450



[01:54:08.90]  MethodAccessException: Attempt to access method 'System.Collections.Generic.IEnumerable<System.Byte>.GetEnumerator' on type 'System.SByte[]' failed.

System.Linq.Enumerable+<TakeIterator>d__25`1[TSource].MoveNext () (at <00000000000000000000000000000000>:0)
System.Collections.Generic.List`1[T].InsertRange (System.Int32 index, System.Collections.Generic.IEnumerable`1[T] collection) (at <00000000000000000000000000000000>:0)
System.Collections.Generic.List`1[T].AddRange (System.Collections.Generic.IEnumerable`1[T] collection) (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.ReadUpdate () (at <00000000000000000000000000000000>:0)
SerialPortUtility.SerialPortUtilityPro.Update () (at <00000000000000000000000000000000>:0)

Oh my god, you have no idea how much I’ve googled. I’ve literally been working at this for weeks, I’ve searched every single keyword and anything in between for the message but there’s just nothing. At this point I would pay someone to fix this for me, I just don’t know what do to. I usually don’t post to forums because I like solving these issues myself so this is my last desperate attempt to see if I can somehow resolve this.

EDIT:

I do have a development build with a debugger. That’s how I found the code. Perhaps I did not make this clear in my original post, so I would like to further clarify in this section instead. My project builds successfully. It creates an apk which I can both install and play. However, for some reason, this specific error is thrown, causing some of the project’s functionality to be non-functional. It’s the sort of feature that is pivotal for the project, so I can’t really skip it or ignore it. It’s very frustrating, because other than this error the project works, I just can’t figure out why this specific part is failing and only on Android 14 builds.