dotnet / android

.NET for Android provides open-source bindings of the Android SDK for use with .NET managed languages such as C#
MIT License
1.93k stars 527 forks source link

.NET Maui - running basic template project has a runtime error #9427

Open vsfeedback opened 3 days ago

vsfeedback commented 3 days ago

This issue has been moved from a ticket on Developer Community.


After some issues with an attempted Maui upgrade to an existing Xamarin project, in an attempt to understand Maui a little better I decided to just make a brand new Maui project from the basic templates that are found in Visual Studio. I chose the ".NET MAUI Multi-Project App" option, and then when asked what project types to include, chose only iOS and Android.

This template does not build successfully right out of the box, though. I'll describe below the modifications that were made to get past the build stage of this process, in case it is relevant.

Upon creation, it loads in a solution with only one iOS project and one Android project, nothing else. If you try to build this you will get two errors saying it cannot find a dll file somewhere in a /obj folder in the main project, which is created with the template but not included in the solution when you initially start. So I added the project, built THAT, and the errors went away.

After that, I received an error stating (filepath truncated) "Assets file '~\MauiTestApp\MauiTestApp.iOS\obj\project.assets.json' doesn't have a target for 'net8.0-ios/ios-arm64'"

After Googling for a solution to this I found a hint saying to add this to the iOS project's csproj:

<PropertyGroup Condition="$(TargetFramework.Contains('-ios'))">
    <RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
</PropertyGroup>

After adding this, it did build successfully. However, this is where I cannot progress. When I try to run the Android version in an Android emulator (Pixel 5, Android 13.0 - API 33), at runtime while the app is loading up, this occurs:

android error.PNG

Text of the error for searching purposes: Java.Lang.NoClassDefFoundError: 'Failed resolution of: Landroidx/startup/R$string;'

I have googled for similar issues and have not had much luck in finding any clear solutions. As mentioned, the only modifications I have made are what were necessary to get it running. Can anyone give me a hint as to what I might be missing?

PC is running on Windows 10, version 10.0.19045

Visual studio information (and installed tools as that is included in the 'About' window): Microsoft Visual Studio Professional 2022 Version 17.11.5 VisualStudio.17.Release/17.11.5+35327.3 Microsoft .NET Framework Version 4.8.09037

Installed Version: Professional

Visual C++ 2022 00483-00100-36538-AA059 Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0

ASA Service Provider 1.0

ASP.NET and Web Tools 17.11.231.19466

Azure App Service Tools v3.0.0 17.11.231.19466

Azure Data Lake Tools for Visual Studio 2.6.5000.0

Azure Functions and Web Jobs Tools 17.11.231.19466

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0

C# Tools 4.11.0-3.24460.3+5649376e0e5f5db3743a94a62b073f2cce4be5d9

Common Azure Tools 1.10

Extensibility Message Bus 1.4.39 (main@e8108eb)

Microsoft Azure Hive Query Language Service 2.6.5000.0

Microsoft Azure Stream Analytics Language Service 2.6.5000.0

Microsoft JVM Debugger 1.0

Mono Debugging for Visual Studio 17.11.3 (ba13144)

NuGet Package Manager 6.11.1

Oracle Developer Tools for Visual Studio 21.11.0.0

Razor (ASP.NET Core) 17.11.3.2442001+68650a7d94261bc56a1f4bc522c2ee35314b1abb

SQL Server Data Tools 17.11.47.0

ToolWindowHostedEditor 1.0

TypeScript Tools 17.0.30715.2002

Visual Basic Tools 4.11.0-3.24460.3+5649376e0e5f5db3743a94a62b073f2cce4be5d9

Visual F# Tools 17.11.0-beta.24421.7+af2f522de602281d4ef5a7b71507c428e814c5c1

Visual Studio IntelliCode 2.2

VisualStudio.DeviceLog 1.0

VisualStudio.Mac 1.0

VSPackage Extension 1.0

Xamarin 17.11.0.98 (d17-11@86652fe)

Xamarin Designer 17.11.3.11 (remotes/origin/d17-11@cdbb0a4fdd)

Xamarin Templates 17.9.0 (38e87ba)

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support. Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d

Xamarin.iOS and Xamarin.Mac SDK 16.4.0.23 (9defd91b3)


Original Comments

Feedback Bot on 10/17/2024, 06:16 PM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

kr-124 commented 3 days ago

Hi, I'm the original poster of the question on the community forum. If you need additional info just let me know

jonathanpeppers commented 3 days ago

This template:

Image

Runs for me with VS 17.12 Preview 3 and .NET 9 RC 2:

Image

I just clicked the play button, do I need to do anything else?

Does the problem go way if you do this on the *.Droid project and try again:

Image

kr-124 commented 3 days ago

Jonathan,

That is the wrong template. It is this one that I had the issue with, and that I need to work with:

Image

jonathanpeppers commented 3 days ago

Sorry, that is the one I used, but I took the wrong screenshot, it looks like:

Image

kr-124 commented 3 days ago

No problem. But to answer your question, yes cleaning the .Droid project did not change anything.

Also, as a quick little test, I did check it just now with the Blazor template you used to see if that would work, but the same issue still occurred. So, perhaps it is something on my end that needs to be updated or removed. Maybe something I have installed in VS 2022? And I just updated VS 2022 to the latest release yesterday.

Other than looking at the console output, which I'll post here, what else can I do as far as troubleshooting this?

Here is what's in the output window after I tried it with the Blazor template, it appears to be the same in the other one as well... I scanned through it and nothing stood out much upon the initial look. I do notice that the error text I showed in the post mentions AndroidX and there's a few lines in the output referring to AndroidX. I do not know enough about AndroidX in regards to this project to know the relevancy of this, but maybe that could be helpful.

(sorry for the lengthy wall of text)

Start debugging Android application ... am start -D -a "android.intent.action.MAIN" -c "android.intent.category.LAUNCHER" -n "com.companyname.testing2/crc64e3a0a74b4988ce03.MainActivity" Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.companyname.testing2/crc64e3a0a74b4988ce03.MainActivity } Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Private.CoreLib.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/Testing2.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/Mono.Android.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Runtime.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/Java.Interop.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Runtime.InteropServices.dll [External] Resolved pending breakpoint for 'Android.Runtime.JNIEnvInit.RegisterJniNatives(System.IntPtr, System.Int32, System.IntPtr, System.IntPtr, System.Int32)' to /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNIEnvInit.cs:57 [0x00000]. Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Collections.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/Mono.Android.Runtime.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Threading.dll [External] [nyname.testing2] Late-enabling -Xcheck:jni [nyname.testing2] Unexpected CPU variant for x86: x86_64. [nyname.testing2] Known variants: atom, sandybridge, silvermont, kabylake, default [CompatibilityChangeReporter] Compat change id reported: 171979766; UID 10173; state: ENABLED [System.out] Sending WAIT chunk [System.out] Debugger has connected [System.out] waiting for debugger to settle... [System.out] waiting for debugger to settle... [System.out] waiting for debugger to settle... [System.out] waiting for debugger to settle... [System.out] waiting for debugger to settle... [System.out] waiting for debugger to settle... [System.out] debugger has settled (1390) [nativeloader] Configuring classloader-namespace for other apk /system_ext/framework/androidx.window.extensions.jar. target_sdk_version=34, uses_libraries=ALL, library_path=/data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64:/data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.apk!/lib/x86_64, permitted_path=/data:/mnt/expand:/data/user/0/com.companyname.testing2 [nativeloader] Configuring classloader-namespace for other apk /system_ext/framework/androidx.window.sidecar.jar. target_sdk_version=34, uses_libraries=ALL, library_path=/data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64:/data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.apk!/lib/x86_64, permitted_path=/data:/mnt/expand:/data/user/0/com.companyname.testing2 [ziparchive] Unable to open '/data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.dm': No such file or directory [ziparchive] Unable to open '/data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.dm': No such file or directory [nativeloader] Configuring classloader-namespace for other apk /data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.apk. target_sdk_version=34, uses_libraries=, library_path=/data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64:/data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.apk!/lib/x86_64, permitted_path=/data:/mnt/expand:/data/user/0/com.companyname.testing2 [GraphicsEnvironment] ANGLE Developer option for 'com.companyname.testing2' set to: 'default' [GraphicsEnvironment] ANGLE GameManagerService for com.companyname.testing2: false [GraphicsEnvironment] Neither updatable production driver nor prerelease driver is supported. [NetworkSecurityConfig] No Network Security Config specified, using platform default [NetworkSecurityConfig] No Network Security Config specified, using platform default [debug-app-helper] Checking if libmonodroid was unpacked to /data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64/libmonodroid.so [debug-app-helper] Native libs extracted to /data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64, assuming application/android:extractNativeLibs == true [debug-app-helper] Setting up for DSO lookup in app data directories [debug-app-helper] Added filesystem DSO lookup location: /data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64 [debug-app-helper] Using runtime path: /data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64 [debug-app-helper] checking directory: /data/user/0/com.companyname.testing2/files/.__override__/lib [debug-app-helper] directory does not exist: /data/user/0/com.companyname.testing2/files/.__override__/lib [debug-app-helper] Checking whether Mono runtime exists at: /data/user/0/com.companyname.testing2/files/.override/libmonosgen-2.0.so [debug-app-helper] Checking whether Mono runtime exists at: /data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64/libmonosgen-2.0.so [debug-app-helper] Mono runtime found at: /data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64/libmonosgen-2.0.so [nyname.testing2] Attempt to remove non-JNI local reference, dumping thread [DOTNET] JNI_OnLoad: JNI_OnLoad in pal_jni.c [DOTNET] GetOptionalClassGRef: optional class com/android/org/conscrypt/OpenSSLEngineImpl was not found [monodroid] Creating public update directory: /data/user/0/com.companyname.testing2/files/.__override__ [nyname.testing2] Attempt to remove non-JNI local reference, dumping thread [monodroid-debug] Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=10.0.2.2:57356,embedding=1,timeout=1729277015 [monodroid-assembly] open_from_bundles: failed to load assembly Testing2.dll [monodroid-gc] GREF GC Threshold: 46080 [monodroid-assembly] open_from_bundles: failed to load assembly Mono.Android.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.dll [monodroid-assembly] open_from_bundles: failed to load assembly Java.Interop.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.InteropServices.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Collections.dll [monodroid-assembly] open_from_bundles: failed to load assembly Mono.Android.Runtime.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Threading.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Threading.Thread.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Diagnostics.StackTrace.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Threading.Thread.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Diagnostics.StackTrace.dll [External] [nyname.testing2] Attempt to remove non-JNI local reference, dumping thread Loaded assembly: data-0x76fadb2e1060 [External] Loaded assembly: data-0x76fadb2f1070 [External] Loaded assembly: data-0x76fb88e82650 [External] [monodroid-assembly] open_from_bundles: failed to load assembly netstandard.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/netstandard.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly System.Linq.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Linq.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.MobileTapContracts.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.MobileTapContracts.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Collections.Concurrent.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Collections.Concurrent.dll [External] Resolved pending breakpoint for 'Xamarin.HotReload.HotReloadAgent.BreakpointSendToIde(System.String)' to D:\a_work\1\s\HotReload\Source\Xamarin.HotReload.Agent\HotReloadAgent.cs:425 [0x00000]. [monodroid-assembly] open_from_bundles: failed to load assembly System.Text.Json.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Text.Json.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly System.Text.Encodings.Web.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Text.Encodings.Web.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly System.ComponentModel.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.ComponentModel.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Controls.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.MobileTapContracts.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.MobileTapContracts.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/Microsoft.Maui.Controls.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.VisualStudio.DesignTools.TapContract.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.ObjectModel.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.ObjectModel.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/Microsoft.Maui.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Graphics.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Maui.Essentials.dll [monodroid-assembly] open_from_bundles: failed to load assembly Microsoft.Extensions.Logging.Abstractions.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/Microsoft.Maui.Graphics.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/Microsoft.Maui.Essentials.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/Microsoft.Extensions.Logging.Abstractions.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.Loader.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Runtime.Loader.dll [External] Resolved pending breakpoint for 'Xamarin.HotReload.HotReloadAgent.BreakpointCheckpoint()' to D:\a_work\1\s\HotReload\Source\Xamarin.HotReload.Agent\HotReloadAgent.cs:420 [0x00000]. [monodroid-assembly] open_from_bundles: failed to load assembly System.Memory.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Memory.dll [External] [monodroid-assembly] open_from_bundles: failed to load assembly System.Reflection.Emit.Lightweight.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Reflection.Emit.ILGeneration.dll [monodroid-assembly] open_from_bundles: failed to load assembly System.Reflection.Primitives.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Reflection.Emit.Lightweight.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Reflection.Emit.ILGeneration.dll [External] Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Reflection.Primitives.dll [External] [AndroidRuntime] Shutting down VM Java.Lang.NoClassDefFoundError: 'Failed resolution of: Landroidx/startup/R$string;'

[AndroidRuntime] FATAL EXCEPTION: main [AndroidRuntime] Process: com.companyname.testing2, PID: 23316 [AndroidRuntime] java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/startup/R$string; [AndroidRuntime] at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:216) [AndroidRuntime] at androidx.startup.AppInitializer.discoverAndInitialize(AppInitializer.java:206) [AndroidRuntime] at androidx.startup.InitializationProvider.onCreate(InitializationProvider.java:45) [AndroidRuntime] at android.content.ContentProvider.attachInfo(ContentProvider.java:2451) [AndroidRuntime] at android.content.ContentProvider.attachInfo(ContentProvider.java:2421) [AndroidRuntime] at android.app.ActivityThread.installProvider(ActivityThread.java:7462) [AndroidRuntime] at android.app.ActivityThread.installContentProviders(ActivityThread.java:6973) [AndroidRuntime] at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6744) [AndroidRuntime] at android.app.ActivityThread.-$$Nest$mhandleBindApplication(Unknown Source:0) [AndroidRuntime] at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2133) [AndroidRuntime] at android.os.Handler.dispatchMessage(Handler.java:106) [AndroidRuntime] at android.os.Looper.loopOnce(Looper.java:201) [AndroidRuntime] at android.os.Looper.loop(Looper.java:288) [AndroidRuntime] at android.app.ActivityThread.main(ActivityThread.java:7872) [AndroidRuntime] at java.lang.reflect.Method.invoke(Native Method) [AndroidRuntime] at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) [AndroidRuntime] at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) [AndroidRuntime] Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.startup.R$string" on path: DexPathList[[zip file "/data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.apk"],nativeLibraryDirectories=[/data/app/xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/lib/x86_64, /data/app/~~xcLqUJzKLOfQ3wqLAKVjxA==/com.companyname.testing2-5tQMFbFKdXpUaXZK7MMzdQ==/base.apk!/lib/x86_64, /system/lib64, /system_ext/lib64]] [AndroidRuntime] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:259) [AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:379) [AndroidRuntime] at java.lang.ClassLoader.loadClass(ClassLoader.java:312) [AndroidRuntime] ... 17 more [monodroid-assembly] open_from_bundles: failed to load assembly System.Console.dll Loaded assembly: /data/data/com.companyname.testing2/files/.override/System.Console.dll [External]

jonathanpeppers commented 3 days ago

Can you save a .binlog of a Rebuild? https://aka.ms/binlog

dotnet-policy-service[bot] commented 20 hours ago

Hi @vsfeedback. We have added the "need-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.