xamarin / AndroidSupportComponents

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

No virtual method addOnTabSelectedListener when updating from Support library 27.0.2 to 28.0.0 #124

Closed sgong-pdftron closed 6 years ago

sgong-pdftron commented 6 years ago

Xamarin.Android Version (eg: 6.0):

9.0

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

Windows 10

Support Libraries Version (eg: 23.3.0):

Upgrade from 27.0.2 -> 28.0.0

Describe your Issue:

When bind an Android library zip from Java to Xamarin, getting the following error:

Java.Lang.NoSuchMethodError: No virtual method addOnTabSelectedListener(Landroid/support/design/widget/TabLayout$BaseOnTabSelectedListener;)V in class Landroid/support/design/widget/TabLayout; or its super classes (declaration of 'android.support.design.widget.TabLayout' appears in /data/app/com.pdftron.pdf.viewer-1/base.apk)

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

  1. Create an Android library project that uses TabLayout target 27 with support library 27.0.2
  2. Bind the resulting .aar to Xamarin, adds dependency to Xamarin support library 27.0.2.1, then use the binding class with TabLayout, everything works fine
  3. Now update the original Android library project to target 28 with support library 28.0.0
  4. Update the binding project to depend on Xamarin support library 28.0.0-preview5
  5. Run the same application, now the TabLayout no longer works and throws runtime exception

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

11-05 17:37:26.641 D/AndroidRuntime(23006): Shutting down VM Unhandled Exception:

Java.Lang.NoSuchMethodError: No virtual method addOnTabSelectedListener(Landroid/support/design/widget/TabLayout$BaseOnTabSelectedListener;)V in class Landroid/support/design/widget/TabLayout; or its super classes (declaration of 'android.support.design.widget.TabLayout' appears in /data/app/com.pdftron.pdf.viewer-1/base.apk)

VS bug #725480

newky2k commented 6 years ago

Assigned to @Redth

Redth commented 6 years ago

This should be addressed in the next preview.

Unfortunately IOnTabSelectedListener's methos were moved to a new base interface (IBaseOnTabSelectedListener) which isn't ABI compatible from a .NET standpoint. We basically changed the bindings so that IBaseOnTabSelectedListener is still the old name, and the new 'parent' type has a new name. This should bring us back to compatibility.

This will go out in either -preview6 or preview7

sgong-pdftron commented 6 years ago

Thank you very much @Redth Do you mind sharing when the preview with this fix will be available?

Redth commented 6 years ago

Should be sometime today or tomorrow.

sgong-pdftron commented 6 years ago

Hi @Redth

I tried today's preview6. However The binding project is unable to build due to the following error:

1>Build FAILED. 1> 1>"D:\TrunkXamarin2\PDFNetXamarin\lib\android\Native\Tools\binding\PDFViewCtrlTools.csproj" (Build;BuiltProjectOutputGroup;BuiltProjectOutputGroupDependencies;DebugSymbolsProjectOutputGroup;DebugSymbolsProjectOutputGroupDependencies;DocumentationProjectOutputGroup;DocumentationProjectOutputGroupDependencies;SatelliteDllsProjectOutputGroup;SatelliteDllsProjectOutputGroupDependencies;SGenFilesOutputGroup;SGenFilesOutputGroupDependencies target) (1) -> 1>(_VerifyXamarinAndroidSupportVersions target) -> 1> D:\TrunkXamarin2\PDFNetXamarin\projectSrc\PDFNetAndroidXamarin\packages\Xamarin.Android.Support.Annotations.28.0.0-preview6\build\monoandroid90\Xamarin.Android.Support.Annotations.targets(14,3): error MSB4044: The "VerifyVersionsTask" task was not given a value for the required parameter "AndroidSdkBuildToolsVersion". 1> 1> 0 Warning(s) 1> 1 Error(s) 1>

Is there any configuration change needed to be able to use the new version? Thanks!

Redth commented 6 years ago

@sgong-pdftron are you able to provide us with your solution that is showing this error?

Thanks

sgong-pdftron commented 6 years ago

@Redth Here is a sample project: http://pdftron.s3.amazonaws.com/custom/external/xamarin/to-xamarin.zip

Steps:

  1. open solution in "projectSrc\PDFNetAndroidXamarin\PDFNetAndroidXamarin.sln"
  2. clean solution, then build "PDFViewCtrlTools" project
  3. the error from my previous post will show up. i.e. The "VerifyVersionsTask" task was not given a value for the required parameter "AndroidSdkBuildToolsVersion".

Hope this helps! Thanks!

sgong-pdftron commented 6 years ago

@Redth just wanted to check in to see if there is anything I can do to fix this error? Thanks!

sgong-pdftron commented 6 years ago

@moljac just wanted to check in to see if there is anything I can do to fix this error? Thanks!

Redth commented 6 years ago

Would you be able to share your solution with us which exhibits this issue? For some reason the msbuild property expected is not being set.

sgong-pdftron commented 6 years ago

@Redth Yes, I posted my solution in this comments: https://github.com/xamarin/AndroidSupportComponents/issues/124#issuecomment-437524874

Were you able to run?

sgong-pdftron commented 6 years ago

Or for some reason you are not able to see the project I linked? (i.e. link got filtered on your end or something?)

Redth commented 6 years ago

Hey @sgong-pdftron so it looks to be a bug in xamarin-android.

The msbuild property AndroidSdkBuildToolsVersion is not set for Xamarin.Android binding projects.

You can work around this for now by manually setting the property in your binding .csproj:

<PropertyGroup>
  <AndroidSdkBuildToolsVersion Condition="'$(AndroidSdkBuildToolsVersion)' == ''">28.0.3</AndroidSdkBuildToolsVersion>
</PropertyGroup>

Please make sure you actually specify the version of build tools that you have installed in the SDK manager, and given that you're working on Support Library 28.x, this should probably be a 28.x version of the build tools to match.

You can track the upstream issue here: https://github.com/xamarin/xamarin-android/issues/2452

sgong-pdftron commented 6 years ago

@Redth your workaround works!! Thank you very much!