Unable to instantiate application. java.lang.ClassNotFoundException: Didn't find class MyApplication

In my application when I do a completely clean build (fully deleted bin and obj folders) My application often crashes (~95% of builds) on launch with the message "Unfortunately, MyApp has stopped". The message I can see in the logs is AndroidRuntime java.lang.RuntimeException: Unable to instantiate application md563d86d3b4ee6b5d12237bf06ae53c0c1.MyApplication: java.lang.ClassNotFoundException: Didn't find class "md563d86d3b4ee6b5d12237bf06ae53c0c1.MyApplication" on path: DexPathList. I have seen other people encounter this error but none of the solutions I have found in the forums and online seem to resolve my problem. I do not have Multi Dex enabled so their is only one dex file. In my solution attempt, turning on Multi Dex did not resolve the problem I am encountering. The application used to work fine prior to upgrading to to the latest stable Xamarin version. Unfortunately, I did not keep a record of what the previous versions I was but it was at least 1.5 years old.

During my investigations I find after building my app I get two classes created in the obj folders. For example with the above crash, the build created:
..\obj\Debug\android\bin\classes\md529a8003c3c31c6cbd5c7d8e69ed8db67\MyApplication.class
..\obj\Debug\android\bin\classes\md563d86d3b4ee6b5d12237bf06ae53c0c1\MyApplication.class

Additionally we get the ApplicationRegistration.class, ..\obj\Debug\android\bin\classes\mono\android\app\ApplicationRegistration.class making reference to MyApp.Mobile.Droid.Application.MyApplication, MyApp.Android, Version=2.1.0.20356, Culture=neutral, PublicKeyToken=null 6md529a8003c3c31c6cbd5c7d8e69ed8db67/MyApplication_". I noticed here its using "_md529a8003c3c31c6cbd5c7d8e69ed8db67. However in the classes.dex and classes.zip files I can only see references to md563d86d3b4ee6b5d12237bf06ae53c0c1/MyApplication.class.

This seems to be the root of my problem as different parts of the built application are using different application classes. I cannot figure out how to resolve this issue.

System Information
VS 2017 15.5.1
Xamarin 4.8.0.753
Xamarin Designer 4.8.183
Xamarin.Android SDK 8.1.0.24
Xamarin.iOS and Xamarin.Mac SDK 11.6.1.2

Application File
[Application(Debuggable = true, Icon = "@drawable/Icon", Label = "@string/ApplicationName")]
public class MyApplication : Android.App.Application
{
public MyApplication(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
}
}

Best Answer

Answers

  • Same issue here... :( :/ :'(

  • TheMojoTheMojo USMember

    I did a complete reinstall of my system and have tried now on VS 2017 Pro. I can get a build to work about 25% of the time if a do a clean before building. Still something very strange is happening on most builds. Glad to hear someone else is experiencing the same issue and its not related to my applications setup.

  • Meanwhile, I'm building and publishing with VS2015 with no problems.

  • JonDouglasJonDouglas USXamarin Team, University, Developer Group Leader Xamurai

    @TesifonteLazcano

    Can you share your version information in:

    Help -> About Visual Studio?

  • Microsoft Visual Studio Community 2017
    Version 15.5.2
    VisualStudio.15.Release/15.5.2+27130.2010
    Microsoft .NET Framework
    Version 4.7.02556

    Installed Version: Community

    Visual Basic 2017 00369-60000-00001-AA342
    Microsoft Visual Basic 2017

    Visual C# 2017 00369-60000-00001-AA342
    Microsoft Visual C# 2017

    Visual F# 4.1 00369-60000-00001-AA342
    Microsoft Visual F# 4.1

    Application Insights Tools for Visual Studio Package 8.10.01106.1
    Application Insights Tools for Visual Studio

    ASP.NET and Web Tools 2017 15.0.31125.0
    ASP.NET and Web Tools 2017

    ASP.NET Core Razor Language Services 1.0
    Provides languages services for ASP.NET Core Razor.

    ASP.NET Web Frameworks and Tools 2012 4.0.20601.0

    ASP.NET Web Frameworks and Tools 2017 5.2.51007.0

    Azure App Service Tools v3.0.0 15.0.31106.0
    Azure App Service Tools v3.0.0

    Common Azure Tools 1.10
    Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

    JavaScript Language Service 2.0
    JavaScript Language Service

    JavaScript Project System 2.0
    JavaScript Project System

    Merq 1.1.17-rc (cba4571)
    Command Bus, Event Stream and Async Manager for Visual Studio extensions.

    Microsoft Azure Tools 2.9
    Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.51120.3

    Microsoft Continuous Delivery Tools for Visual Studio 0.3
    Simplifying the configuration of continuous build integration and continuous build delivery from within the Visual Studio IDE.

    Microsoft JVM Debugger 1.0
    Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

    Microsoft MI-Based Debugger 1.0
    Provides support for connecting Visual Studio to MI compatible debuggers

    Microsoft Visual Studio Tools for Containers 1.1
    Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

    Mono Debugging for Visual Studio 4.8.4-pre (3fe64e3)
    Support for debugging Mono processes with Visual Studio.

    Node.js Tools 1.4.11025.7
    Adds support for developing and debugging Node.js apps in Visual Studio

    NuGet Package Manager 4.5.0
    NuGet Package Manager in Visual Studio.

    SQL Server Data Tools 15.1.61710.120
    Microsoft SQL Server Data Tools

    TypeScript Tools 15.5.11025.1
    TypeScript Tools for Microsoft Visual Studio

    Visual Studio Code Debug Adapter Host Package 1.0
    Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

    VisualStudio.Mac 1.0
    Mac Extension for Visual Studio

    Xamarin 4.8.0.753 (6575bd113)
    Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

    Xamarin Designer 4.8.188 (c5813fa34)
    Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

    Xamarin.Android SDK 8.1.0.25 (HEAD/d8c6e504f)
    Xamarin.Android Reference Assemblies and MSBuild support.

    Xamarin.iOS and Xamarin.Mac SDK 11.6.1.2 (6857dfc)
    Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

  • @JonDouglas
    I was using an incremental assembly version, now I am using fixed assembly version and works fine in VS2017 Version 15.5.2

    Hope this help...

    Regards

Sign In or Register to comment.