Xamarin.forms: [Android] Java.Lang.ClassNotFoundException when using ToolbarPlacement="Bottom"

Created on 29 Mar 2019  路  11Comments  路  Source: xamarin/Xamarin.Forms

Description

I want to change my Xamarin Forms application to show the TabbedPage toolbar at the bottom. As per the instructions, I have added the following:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:android="clr-namespace:Xamarin.Forms.PlatformConfiguration.AndroidSpecific;assembly=Xamarin.Forms.Core" android:TabbedPage.ToolbarPlacement="Bottom" x:Class="<snipped>" Title="{Binding Path=Title, Mode=OneWay}">

Debug builds work fine and the toolbar is now at the bottom of the screen (nice). However, when I make a release build, my application crashes as soon as I open the TabbedPage. I get this crash report in App Center:

java.lang.ClassNotFoundException: Didn't find class "android.support.design.internal.BaselineLayout" on path: DexPathList[[zip file "/data/app/<snipped>-kdiAi7dHgpX2ykU4wTrlqw==/base.apk"],nativeLibraryDirectories=[/data/app/<snipped>-kdiAi7dHgpX2ykU4wTrlqw==/lib/arm, /data/app/<snipped>-kdiAi7dHgpX2ykU4wTrlqw==/base.apk!/lib/armeabi-v7a, /system/lib, /system/vendor/lib]] dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125) java.lang.ClassLoader.loadClass(ClassLoader.java:379) java.lang.ClassLoader.loadClass(ClassLoader.java:312) android.view.LayoutInflater.createView(LayoutInflater.java:606) android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:790) android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730) android.view.LayoutInflater.rInflate(LayoutInflater.java:863) android.view.LayoutInflater.inflate(LayoutInflater.java:489) android.view.LayoutInflater.inflate(LayoutInflater.java:423) android.support.design.internal.BottomNavigationItemView.<init>(BottomNavigationItemView.java:87) android.support.design.internal.BottomNavigationItemView.<init>(BottomNavigationItemView.java:72) android.support.design.internal.BottomNavigationItemView.<init>(BottomNavigationItemView.java:68) android.support.design.internal.BottomNavigationMenuView.getNewItem(BottomNavigationMenuView.java:322) android.support.design.internal.BottomNavigationMenuView.buildMenuView(BottomNavigationMenuView.java:275) android.support.design.internal.BottomNavigationPresenter.updateMenuView(BottomNavigationPresenter.java:62) android.support.v7.view.menu.MenuBuilder.dispatchPresenterUpdate(MenuBuilder.java:291) android.support.v7.view.menu.MenuBuilder.onItemsChanged(MenuBuilder.java:1051) android.support.v7.view.menu.MenuBuilder.startDispatchingItemsChanged(MenuBuilder.java:1078) android.support.design.internal.BottomNavigationMenu.addInternal(BottomNavigationMenu.java:56) android.support.v7.view.menu.MenuBuilder.add(MenuBuilder.java:475) md58432a647068b097f9637064b8985a5e0.FragmentContainer.n_onCreateView(Native Method) md58432a647068b097f9637064b8985a5e0.FragmentContainer.onCreateView(FragmentContainer.java:33) android.support.v4.app.Fragment.performCreateView(Fragment.java:2261) android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1419) android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1750) android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1819) android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797) android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2590) android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2377) android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2332) android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2239) android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:700) android.os.Handler.handleCallback(Handler.java:790) android.os.Handler.dispatchMessage(Handler.java:99) android.os.Looper.loop(Looper.java:164) android.app.ActivityThread.main(ActivityThread.java:6626) java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:811)

I have tried to add a method to my MainActivity, like so:

void LinkerPleaseInclude() { var ignore = new BaselineLayout(this); }

It makes no difference. The app crashes with the same error. Cleaning, removing bin and obj folders makes no difference either.

Steps to Reproduce

  1. Set ToolbarPlacement to Bottom
  2. Run a release build.
  3. Navigate to the TabbedPage.

Expected Behavior

The page loads correctly showing the toolbar at the bottom of the screen.

Actual Behavior

The app crashes.

Basic Information

  • Version with issue: Xamarin.Forms 3.6.0.264807
  • Last known good version: N/A
  • IDE: Visual Studio 2019 RC.4
  • Platform Target Frameworks:

    • Android: 8.1

  • Android Support Library Version: 27.0.2.1
  • Nuget Packages:

    • DLToolkit.Forms.Controls.FlowListView 2.0.11

    • IdentityModel.OidcClient 2.9.0

    • Microsoft.AppCenter.Analytics 1.14.0

    • Microsoft.AppCenter.Crashes 1.14.0

    • Refractored.FloatingActionButtonForms 2.1.0

    • Xam.Plugin.Connectivity 3.2.0

    • Xam.Plugin.Geolocator 4.5.0.6

    • Xam.Plugin.Media 4.0.1.5

    • Xamarin.Controls.SignaturePad.Forms 3.0.0

    • System.Memory 4.5.2

    • Xamarin.Android.Arch.Core.Common 1.0.0.1

    • Xamarin.Android.Arch.Lifecycle.Common 1.0.3.1

    • Xamarin.Android.Arch.Lifecycle.Runtime 1.0.3.1

    • Xamarin.Android.Support.Animated.Vector.Drawable 27.0.2.1

    • Xamarin.Android.Support.Annotations 27.0.2.1

    • Xamarin.Android.Support.Compat 27.0.2.1

    • Xamarin.Android.Support.Core.UI 27.0.2.1

    • Xamarin.Android.Support.Core.Utils 27.0.2.1

    • Xamarin.Android.Support.Design 27.0.2.1

    • Xamarin.Android.Support.Fragment 27.0.2.1

    • Xamarin.Android.Support.Media.Compat 27.0.2.1

    • Xamarin.Android.Support.Transition 27.0.2.1

    • Xamarin.Android.Support.v4 27.0.2.1

    • Xamarin.Android.Support.v7.AppCompat 27.0.2.1

    • Xamarin.Android.Support.v7.CardView 27.0.2.1

    • Xamarin.Android.Support.v7.MediaRouter 27.0.2.1

    • Xamarin.Android.Support.v7.Palette 27.0.2.1

    • Xamarin.Android.Support.v7.RecyclerView 27.0.2.1

    • Xamarin.Android.Support.Vector.Drawable 27.0.2.1

    • Xamarin.Forms 3.6.0.264807

  • Affected Devices: All
2 high Android bug

Most helpful comment

I think similar like
https://github.com/xamarin/Xamarin.Forms/issues/2709

you need add
-keep class android.support.design.internal.BaselineLayout { *; }
-dontwarn android.support.design.internal.BaselineLayout

All 11 comments

Could you please attach a zipped reproduction? Thanks!

For what it's worth, the problem does not occur when building with VS2017.
I will try to make a reproduction later.

Great, we'll keep an eye out for the sample project. Thanks!!

I think similar like
https://github.com/xamarin/Xamarin.Forms/issues/2709

you need add
-keep class android.support.design.internal.BaselineLayout { *; }
-dontwarn android.support.design.internal.BaselineLayout

@PureWeen thoughts?

@cornem Have you tried on the latest stable VS 2019?

Do you have multidex enabled on release? If so can you try proguard and uncheck multidex to see if that works?

What's the API version of the device you are running on?

If you target API 28 and update to support 28 do you still see the same issue?

In my case I got this error after turning on ProGuard when I have ToolbarPlacement="Bottom". As @bill2004158 mentions, adding following lines to proguard config fixed it for me:
-keep class android.support.design.internal.BaselineLayout { *; }
-dontwarn android.support.design.internal.BaselineLayout

I just got hit by the same problem. Bottom Tabbar plus Proguard resulted in the exception mentioned above.

A word of caution to all who would add the proguard.cfg from Visual Studio: the IDE will add a BOM character by default and the java process will exit with code 1.
Either create the cfg from outside Visual Studio or open it in VSCode (or similar) and change the Encoding to UTF-8 (without BOM).

Man, I thought I had general Linker problems for so long and kept putting off linking the app. (Could never reproduce in debug mode.) Who knew it was this class and the bottom tabbar.

馃憤 @bill2004158

This is also happening in VS for mac 8.1.4
I am using D8 and R8 without using multidex

I'm also facing this exact same problem, I have tried using the facebook proguard version(found in a nuget package), adding proguard.cfg. Multidex is also disabled on all configurations.

Was this page helpful?
0 / 5 - 0 ratings