Android X and Xamarin.Forms

Hello, I have dependency which needs Android X (Braintree 3.4.0). Is it possible use with Xamarin.Forms app?
Braintree library initialization requires AndroidX.AppCompatActivity, but I have only my FormsAppCompatActivity which is Android.Support.V7.App.

This is blocker for me. Any ideas how I could solve this?

Best Answer

Answers

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    Xamarin's AndroidX wrappers are still in preview. Once those are considered stable, I assume Forms will update their dependencies to use AndroidX instead of the classic support libraries. I have no idea how long it will be until that happens.

    Is there an older version of Braintree that is not dependent upon AndroidX that you can use?

  • IgnasBagdonasIgnasBagdonas LTMember ✭✭

    Actually no, because Braintree started using Android X from v3.0.0 when also introduced 3DS 2 security protocol for payment cards. So I need exactly this protocol for my app. Also 3DS 2 protocol will be enforced after month... So I don't know what to do with my app and 400k users...

  • JoeMankeJoeManke USMember ✭✭✭✭✭

    I'm curious what package you're actually using. A quick search for Braintree on nuget.org isn't showing me anything dependent upon AndroidX.

  • IgnasBagdonasIgnasBagdonas LTMember ✭✭
    edited August 13

    On nuget is only v2 Braintree bindings from Naxam, builded 2 years ago, and which I using until now. I just took latest braintree aar and created bindings by myself. It works with Xamarin.Android and AndroidX preview nugets, but I wondering how to integrate into Xamarin.Forms app. https://mvnrepository.com/artifact/com.braintreepayments.api/braintree/3.4.1

  • IgnasBagdonasIgnasBagdonas LTMember ✭✭

    @Amar_Bait said:
    I just converted my project to AndroidX today, it went well. Just install package Xamarin.AndroidX.Migration (pre) and rebuild your Android project. It will probably throw a bunch of errors saying you're missing some AndroidX packages. Install them (they're pre too) and rebuild again, your project should build fine. You can leave the old support nuget packages, they won't be packaged in your app (they will be used in compilation only if one of your libraries need them). For my part I removed them and the migration nuget and the app worked like a charm, I guess the libraries I use work fine with the AndroidX counterparts.

    Are you sure you're talking about Xamarin.Forms app? How you could remove old support libraries if Xamarin.Forms depend on it? I know that Xamarin.Android works with AndroidX prevs.

  • Amar_BaitAmar_Bait DZMember ✭✭✭✭✭
    edited August 14

    @IgnasBagdonas said:

    @Amar_Bait said:
    I just converted my project to AndroidX today, it went well. Just install package Xamarin.AndroidX.Migration (pre) and rebuild your Android project. It will probably throw a bunch of errors saying you're missing some AndroidX packages. Install them (they're pre too) and rebuild again, your project should build fine. You can leave the old support nuget packages, they won't be packaged in your app (they will be used in compilation only if one of your libraries need them). For my part I removed them and the migration nuget and the app worked like a charm, I guess the libraries I use work fine with the AndroidX counterparts.

    Are you sure you're talking about Xamarin.Forms app? How you could remove old support libraries if Xamarin.Forms depend on it? I know that Xamarin.Android works with AndroidX prevs.

    @IgnasBagdonas said:

    @Amar_Bait said:
    I just converted my project to AndroidX today, it went well. Just install package Xamarin.AndroidX.Migration (pre) and rebuild your Android project. It will probably throw a bunch of errors saying you're missing some AndroidX packages. Install them (they're pre too) and rebuild again, your project should build fine. You can leave the old support nuget packages, they won't be packaged in your app (they will be used in compilation only if one of your libraries need them). For my part I removed them and the migration nuget and the app worked like a charm, I guess the libraries I use work fine with the AndroidX counterparts.

    Are you sure you're talking about Xamarin.Forms app? How you could remove old support libraries if Xamarin.Forms depend on it? I know that Xamarin.Android works with AndroidX prevs.

    Yes I'm sure (and I'm not the 1st one to do it on Xamarin.Forms)

    Support and AndroidX will be switched transparently during Build time. If you inspect your MainActivity (FormsAppCompatActivity) during runtime, you will find it inherits from AndroidX.AppCompat.AppCompatActivity instead of Android.Support.V7.AppCompatActivity. Xamarin team did a good job on this.

  • IgnasBagdonasIgnasBagdonas LTMember ✭✭

    Awesome, ok, I will try then and come back with results! Thanks.

  • IgnasBagdonasIgnasBagdonas LTMember ✭✭

    Yes, @Amar_Bait was right. Successfully converted my project too. Also had to adjust bindings project to accept Java.Lang.Object instead of AndroidX.AppCompatActivity and everything works perfect.

Sign In or Register to comment.