简体   繁体   中英

Xamarin Forms error: Java.Lang.NoClassDefFoundError: android.support.graphics.drawable.VectorDrawableCompat

When starting debugging of my project on the Android emulator I receive this error:

Java.Lang.NoClassDefFoundError: android.support.graphics.drawable.VectorDrawableCompat

At this code:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        //SQLitePCL.Batteries.Init();
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(bundle);

        string dbPath = FileAccessHelper.GetLocalFilePath("clocker.db3");

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new Clocker.App(dbPath));
    }
}

The error occurs on this row:

base.OnCreate(bundle);

I have tried looking online at the other suggestions but the answers seem related to specific Xamarin studio files which are non-existant in my project (ig the gradle file).

I have checked the contents of 'bundle' and it seems to be null at the time of the error but I'm unsure if this is causing the error.

I'm using Xamarin forms PCL.

This error may occurs with several class if the project path is too long, because it go through the limit of Operational System character length.

Example of Long path:

C:\\Users\\Username\\Documents\\Visual Studio xxxx\\Projects\\Project Name

Example of Good path:

C:\\Projects\\ProjectName

EDIT - Added how the packages should look:

包Pic

The error Java.Lang.NoClassDefFoundError: means that you're missing a class. It tells you which class you're missing as well: android.support.graphics.drawable.VectorDrawableCompat . I've not used Xamarin myself, but their documentation describes how to use Java classes in C# code. Once the package which includes the class android.support.graphics.drawable.VectorDrawableCompat (VectorDrawableCompat.java, which is in android.support.graphics.drawable I think?) is imported, your code should run.

I am not sure if this will help you but look at the way the MainActivity is declared.

Your example has:

  • public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity

But in my code i have:

  • public class MainActivity : Xamarin.Forms.Platform.Android.FormsApplicationActivity

See if that makes a difference to the startup. If you have to use FormsAppCompatActivity then see if changing the Api level to the highest supported level makes a difference.

Do you have any logs from the Output window, Show Xamarin Diagnostics.

I had a similar error. I resolved it to install the latest version of JDK and select the new folder in Visual Studio.

Visual Studio 2015上的Xamarin设置

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM