xamarin / AndroidSupportComponents

Xamarin bindings for Android Support libraries - For AndroidX see https://github.com/xamarin/AndroidX
MIT License
146 stars 56 forks source link

Xamarin.Android Designer throws java.lang.ClassNotFoundException when using CoordinatorLayout #140

Open tbalcom opened 5 years ago

tbalcom commented 5 years ago

Xamarin.Android Version (eg: 6.0):

9.1.4.2

Operating System & Version (eg: Mac OSX 10.11):

Windows 10 1809

Support Libraries Version (eg: 23.3.0):

28.0.0

Describe your Issue:

Updating Support libraries from 27.0.2.1 to 28.0.0 broke the Xamarin.Android designer ability to render layouts with a CoordinatorLayout.

Steps to Reproduce (with link to sample solution if possible):

Reference Xamarin.Android.Support.Design 28.0.0 and use CoordinatorLayout in a layout then look at the layout using the Xamarin.Android Designer. The same layout renders correctly while referencing Xamarin.Android.Support.Design 27.0.2.1.

The following layout reproduces the error:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
</android.support.design.widget.CoordinatorLayout>

Include any relevant Exception Stack traces, build logs, adb logs:

Clicking the "Show Error" button in the designer displays:

mono.android.LibraryClassLoader.loadAndConvertClass(LibraryClassLoader.java:89) mono.android.LibraryClassLoader.findClass(LibraryClassLoader.java:57) java.lang.ClassLoader.loadClass(ClassLoader.java:424) java.lang.ClassLoader.loadClass(ClassLoader.java:357) android.support.design.widget.CoordinatorLayout.setupForInsets(CoordinatorLayout.java:3213) android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:226) android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:201) sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

moljac commented 5 years ago

I had similar issues with BottomNavigationView samples.

Classic workarounds like deleting bin/ and ob/ sometimes helped.

If possible please submit minimal sample, so we can speed up investigation.

Ruud-cb commented 5 years ago

Same here but different "solution" I had to target Android 9 (P) because a dependency FFImageLoading was asking me to change to that target framework (showed as warning). It did work for a while but apparently at some point the designer noticed the change and made it unable to load any layout file. When I change back to Android 8.1 as targeting platform, I get my designer back. It now shows a warning at the bottom: "This project contains resources that were not compiled successfully, rendering might be affected". This didn't show up when I was targeting Android 9.

The layouts that were complaining with this error: android.support.design.widget.TextInputLayout => I was testing with this one, when I removed this from the layout, the warning disappeared but the remaining elements (ImageView and Button) did not show up, so it was still a death end, android.support.v4.widget.DrawerLayout android.support.design.widget.NavigationView

I am targeting the following nuget packages directly. This due complaining of version conflicts when I tried to install Xamarin.FFImageLoading, it has v 27.0.2.1 locked. So after installing these packages manually, I could install that package.

tbalcom commented 5 years ago

This is still a problem with Visual Studio 2017 15.9.5/Xamarin.Android 9.1.5.0. Deleting bin & obj folders changes nothing. Upgrading Android Support packages from 27.0.2.1 to 28.0.0.0 triggers the problem. The problem is most likely not specific to CoordinatorLayout. It seems to be triggered by many Support widgets (Toolbar, TextInputLayout, CoordinatorLayout, etc.). The same project can render layouts without any support widgets fine.

It's pretty simple to reproduce:

  1. Create a new Android project using the Visual Studio 2017 "Single View App" template with Minimum Android version set to: Android 5.0 Lollipop
  2. Build the project. The Android designer correctly renders activity_main as expected.
  3. Change the Target Framework to Android 9.0 (Pie).
  4. Rebuild the project. The Android designer is still correctly rendering activity_main.
  5. Update Xamarin.Android.Support.Design from 27.0.2.1 to 28.0.0.0 using the NuGet GUI.
  6. Rebuild the project. The Android designer now fails to render activity_main.
  7. Downgrade Xamarin.Android.Support.Design from 28.0.0.0 to 27.0.2.1 using the NuGet GUI.
  8. Rebuild the project. The Android designer correctly renders activity_main again.
Ruud-cb commented 5 years ago

Just a little hint for @tbalcom 's answer: I am targeting android 8.1 in combination with Xamarin.Android.Support.Design 28.0.0.0, so it seems that the combination of Android Pie and v28.0.0.0 creates problems. Targeting android 8.1 it only gives a warning I mentioned earlier.

So this way at least can develop against the new support design version, just have to increase the target once a fix is in place.

moljac commented 5 years ago

@tbalcom I tried to reproduce your steps on Mac with Internal Preview (VS4Mac) and no issues. I will try to reproduce with VS2017 on Windows on Monday. I see that the templates do differ.

Ruud-cb commented 5 years ago

@moljac keep in mind you should do the clean build, remove obj,bin folder things and so on. Because as I remember it, at first it looked oke, after some time it produced errors.

DearXxGitHub commented 5 years ago

I had the same problem on Windows

RedFolder commented 5 years ago

I have the same problem on Windows. All Visual Studio updates have been applied. Dropping target API to 8.1 solves the designer issue.

hunter-digital commented 5 years ago

Can confirm this issue. Designer became broken on updating to support 28 and targeting Pie.

hunter-digital commented 5 years ago

@moljac Is there any status update on this issue? Is there any way that we could participate in the fixing of this issue? Android designer going down on so many of my views is gonna kill my team.

Ruud-cb commented 5 years ago

Guys due installing packages which require me to upgrade to V9 of android I cannot do any designing at this moment. PLEASE address this issue. Is it a Visual Studio issue? Xamarin related? DOes 28.0.1 fix the problem?

moljac commented 5 years ago

@Ruud-cb @hunter-digital @tbalcom @DearXxGitHub @RonPeters can you send me detailed info about Visual Studio Version, Xamarin.Android and Xamarin.Android Designer please?

moljac commented 5 years ago

And please just create small repro sample, put it in a public repo and paste links to the repo[s] here.

Ruud-cb commented 5 years ago

@moljac here are the reproduction steps, installed versions and a example. Hope you can solve the mystery soon! https://github.com/Ruud-cb/Reproduction_Android9_DesignIssue

RedFolder commented 5 years ago

Create a new Xamarin Android project and target Pie 9.0. The application template actually targets 8.1 instead of 9.0, so change it in the Android Manifest tabs and Application tab to target 9.0. Rebuild. The designer works. Now go to Nuget package manager. You'll see that there is the opportunity to update Xamarin.Android.Support.Design from v27 to v28. Install the update and rebuild. Designer no longer works. Downgrade the app target to 8.1. Designer works again.

moljac commented 5 years ago

@Ruud-cb @RonPeters @hunter-digital @DearXxGitHub @tbalcom

Designer team says it was fixed. My tests cause no exception but empty designer surface (nothing is rendered), so I escallated to core Xamarin.Android team. I hope we'll get more insight s soon.

related: https://github.com/xamarin/AndroidSupportComponents/issues/163#issuecomment-477923621

I asked both Designer and Xamarin.Android teams for more information.

tbalcom commented 5 years ago

The issue is fixed in Visual Studio 2019 16.0.0 (with designer 4.17.4.413) but still broken in Visual Studio 2017 15.9.11 (with designer 4.16.30).

alessandro-lion commented 3 years ago

Xamarin.Android Version (eg: 6.0):

9.1.4.2

Operating System & Version (eg: Mac OSX 10.11):

Windows 10 1809

Support Libraries Version (eg: 23.3.0):

28.0.0

Describe your Issue:

Updating Support libraries from 27.0.2.1 to 28.0.0 broke the Xamarin.Android designer ability to render layouts with a CoordinatorLayout.

Steps to Reproduce (with link to sample solution if possible):

Reference Xamarin.Android.Support.Design 28.0.0 and use CoordinatorLayout in a layout then look at the layout using the Xamarin.Android Designer. The same layout renders correctly while referencing Xamarin.Android.Support.Design 27.0.2.1.

The following layout reproduces the error:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
</android.support.design.widget.CoordinatorLayout>

Include any relevant Exception Stack traces, build logs, adb logs:

Clicking the "Show Error" button in the designer displays:

mono.android.LibraryClassLoader.loadAndConvertClass(LibraryClassLoader.java:89) mono.android.LibraryClassLoader.findClass(LibraryClassLoader.java:57) java.lang.ClassLoader.loadClass(ClassLoader.java:424) java.lang.ClassLoader.loadClass(ClassLoader.java:357) android.support.design.widget.CoordinatorLayout.setupForInsets(CoordinatorLayout.java:3213) android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:226) android.support.design.widget.CoordinatorLayout.(CoordinatorLayout.java:201) sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) Regarding "Updating Support libraries from 27.0.2.1 to 28.0.0 broke the Xamarin.Android designer ability to render layouts with a CoordinatorLayout." I can reproduce this as well on latest version, Microsoft Visual Studio Community 2019 Version 16.5.2 on a new Project from template; these are the steps:

Create new project Android App (Xamarin) Tabbed App

Build Solution

Browse the solution Explorer under Resources- Layout - Activity_Main.xml The designer is working.

Go to Application Properties, change Target Framework to Android 10 Open Manage nuGet Packages for the App, Perform all the updates Save and exit Visual Studio Re-Open visual Studio and open the project.

Build - Clean Solution Build - Rebuild App This one is failing with error Severity Code Description Project File Line Source Suppression State Error Could not find 9 Android X assemblies, make sure to install the following NuGet packages:

So I closed visual Studio, opening the .csproj with notepad added the two PackageReference I copied from the error message.

Open Visual studio, use the nuget Dependencies manager on the App to Perform the updates Build - Rebuild Solution Failing with this error

Severity Code Description Project File Line Source Suppression State Warning Could not find 1 Android X assemblies, make sure to install the following NuGet packages:

Again close visual Studio, edit .csproj with notepad to add the PackageReference Open Visual studio, use the nuget Dependencies manager on the App to Perform the updates Build - Clean Solution Build - Clean App Build - Build App

Build Succeeded, Anyway whenever I try to open the editor on Resources\Layout\activity_main.xml I am seeing the message "Could not load control from the Android Support Library. performing a NuGet restore may fix this." The widget at bottom is not shown as result of the error.

You can find the resulting source that will include the "broken" design at https://github.com/alessandro-lion/NewApp