Is it possible to create a library in Xamarin.Android?

I'm considering to rebuild this library from scratch (at least the Java sections):

https://github.com/mancj/MaterialSearchBar

I have some background in Java and I think I could manage it, but generally, when I have created projects for Xamarin.Android, I don't remember I have an option to build a DLL because this projects contains:

  • Animations.
  • Layouts.
  • Drawables.
  • Styles.
  • Values.

All of them are XMLs and I need to access some IDs that when I bound a library in the past none of them is accessible from the Additional folder; therefore, I'd rather re-create it by myself, but I'd like to know if it's possible to create the DLL without a Binding library project and how to create it in VS?

Thanks.

Best Answer

  • FedericoNavarreteFedericoNavarrete SV ✭✭
    edited July 2 Accepted Answer

    @LucasZhang said:
    If you want to create a dll file without an existing library , It will be very complex to finish . So I suggest you to use the third party library .

    I was able to recreate the library, there is an option for creating Libraries with Visual Studio without binding, it's called Class Library:

    Visual Studio for Mac:

    Visual Studio for Windows:

    To be honest, there is few documentation about this topic and somehow you need to have some significant knowledge of Xamarin.Android, Android and Java/Kotlin to build it, but I got it and this is my result:

    https://github.com/FANMixco/Xamarin-SearchBar

    I have all functionalities working from the original library and it's already published in NuGet too:

    https://www.nuget.org/packages/Xamarin-MaterialSearchBar

    I'm open to new suggestions or commits from other developers.

    Finally, regarding your suggestion I got some issues using the controls when I ran the code, I got a warning because I'm compiling to Android Pie and these controls were created for older versions of Android.

Answers

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    I don't think that you can implement it. And in Xamarin.Android you can use FloatingSearchView from Nuget .

  • FedericoNavarreteFedericoNavarrete SVMember ✭✭

    @LucasZhang said:
    I don't think that you can implement it. And in Xamarin.Android you can use FloatingSearchView from Nuget .

    Hi Lukas, thanks for your answer, I'll check it, but why shouldn't I be able to implement it? Could you elaborate better your answer? As I said I can translate the Java code to C#, what I need is a project that is capable of creating DLLs with the XMLs codes.

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    If you want to create a dll file without an existing library , It will be very complex to finish . So I suggest you to use the third party library .

  • FedericoNavarreteFedericoNavarrete SVMember ✭✭

    @LucasZhang said:
    If you want to create a dll file without an existing library , It will be very complex to finish . So I suggest you to use the third party library .

    Hi Lukas, I agree I'm going to test the library that you propose tonight, but at the same time I would like to know how to create my own libraries maybe in the future I will need to do it

    I already tried to bind that library and I needed to migrate one class from Scratch and it's the missing part that I don't have the Custom Adapter.

    Personally, the code of the library that I shared is not so complex (based on my experience with C# and Java), maybe a little bit long, but not impossible since I can re-use all XMLs and I just need to migrate 2 to 5 classes more (extra ones because of the lack of support of C# 8 by Xamarin at this point of time):

    • MaterialSearchBar.java
    • SimpleOnSearchActionListener.java
    • DefaultSuggestionsAdapter.java

    Also, I already already translate one: SuggestionsAdapter: https://stackoverflow.com/a/56778629/2889347. But thanks again for your idea, I'm going to see if it supports the CustomAdapter that is the most important part in my work.

  • FedericoNavarreteFedericoNavarrete SVMember ✭✭
    edited July 2 Accepted Answer

    @LucasZhang said:
    If you want to create a dll file without an existing library , It will be very complex to finish . So I suggest you to use the third party library .

    I was able to recreate the library, there is an option for creating Libraries with Visual Studio without binding, it's called Class Library:

    Visual Studio for Mac:

    Visual Studio for Windows:

    To be honest, there is few documentation about this topic and somehow you need to have some significant knowledge of Xamarin.Android, Android and Java/Kotlin to build it, but I got it and this is my result:

    https://github.com/FANMixco/Xamarin-SearchBar

    I have all functionalities working from the original library and it's already published in NuGet too:

    https://www.nuget.org/packages/Xamarin-MaterialSearchBar

    I'm open to new suggestions or commits from other developers.

    Finally, regarding your suggestion I got some issues using the controls when I ran the code, I got a warning because I'm compiling to Android Pie and these controls were created for older versions of Android.

Sign In or Register to comment.