Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic app crashes with braintree plugin - java.lang.NoSuchMethodError: No static method getFont

I'm currently trying to integrate PayPal into an App build using the Ionic framework setup to run on top of cordova. I'm using [the ionic-native braintree plugin][1] for integration. The App builds and runs fine on my phone, the initialize method also works, however it crashes everytime i call the presentDropInPaymentUI() method. To that it is irrelevant if i do so with or without paymentoptions as a parameter.

The following code is invoked after pressing a button in the app, and crashes it:

public payWithPayPal(): void {
    const BRAINTREE_TOKEN = 'abc';

    const paymentOptions: PaymentUIOptions = {
        amount: '14.99',
        primaryDescription: 'Your product or service (per /item, /month, /week, etc)',
    };


    this.braintree.initialize(BRAINTREE_TOKEN)
        .then(() => console.log("Did it!"))
        .then(() => this.braintree.presentDropInPaymentUI(paymentOptions))
        .then((result:PaymentUIResult) => {
            if (result.userCancelled) {
                console.log("User cancelled payment dialog.");
            } else {
                console.log("User successfully completed payment!");
                console.log("Payment Nonce: " + result.nonce);
                console.log("Payment Result.", result);
            }
        })
        .catch((error: string) => console.error(error));

}

It's pretty much identical to the sample code on Ionics page, i just removed the applepay stuff and added a console output to ensure correct initialization. This is the error i get everytime presentDropInPayMentUI is called:

FATAL EXCEPTION: main
                                                                    Process: de.findlunch.findlunch, PID: 31043
                                                                    java.lang.NoSuchMethodError: No static method getFont(Landroid/content/Context;ILandroid/util/TypedValue;ILandroid/widget/TextView;)Landroid/graphics/Typeface; in class Landroid/support/v4/content/res/ResourcesCompat; or its super classes (declaration of 'android.support.v4.content.res.ResourcesCompat' appears in /data/app/de.appname.appname/base.apk)
                                                                        at android.support.v7.widget.TintTypedArray.getFont(TintTypedArray.java:119)
                                                                        at android.support.v7.widget.AppCompatTextHelper.updateTypefaceAndStyle(AppCompatTextHelper.java:208)
                                                                        at android.support.v7.widget.AppCompatTextHelper.loadFromAttributes(AppCompatTextHelper.java:110)
                                                                        at android.support.v7.widget.AppCompatTextHelperV17.loadFromAttributes(AppCompatTextHelperV17.java:38)
                                                                        at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:81)
                                                                        at android.support.v7.widget.AppCompatTextView.<init>(AppCompatTextView.java:71)
                                                                        at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103)
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflate(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java)
                                                                        at android.view.LayoutInflater.inflate(LayoutInflater.java)
                                                                        at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                        at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                        at com.braintreepayments.api.dropin.DropInActivity.onCreate(DropInActivity.java:88)
                                                                        at android.app.Activity.performCreate(Activity.java)
                                                                        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java)
                                                                        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java)
                                                                        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java)
                                                                        at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                        at android.app.ActivityThread$H.handleMessage(ActivityThread.java)
                                                                        at android.os.Handler.dispatchMessage(Handler.java)
                                                                        at android.os.Looper.loop(Looper.java)
                                                                        at android.app.ActivityThread.main(ActivityThread.java)
                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)

This is what ionic info gives me:

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.0
ionic (Ionic CLI) : 3.19.0

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@ionic/app-scripts : 1.3.12
Cordova Platforms  : android 6.4.0
Ionic Framework    : ionic-angular 3.0.1

System:

Android SDK Tools : 26.1.1
Node              : v6.11.4
npm               : 5.6.0 
OS                : Linux 4.13

Environment Variables:

ANDROID_HOME : /home/leo/Android/Sdk

Misc:

backend : pro

Every search has led me to updating my sdktools/buildtools, however they are the newest version (or at least android studio says so). It also seems that no one had this problem with this specific plugin before. Targetsdk is also set to 26 in my config.xml.

Any help on how to solve this, or what a better way to integrate braintree is would be greatly appreciated!

Also this is my first time asking a question here, so if i made any mistakes feel free to tell me!

like image 544
Loyonyart Avatar asked Jun 21 '26 19:06

Loyonyart


1 Answers

wow I feel badly for not seeing this.

Ok so you are right, the plugin crashes and the reason it does so is thanks to the new Android SDK versions. Essentially there's a pretty big conflict between other plugins you are using, the android.support versions they import, and the android.support version required by the braintree drop-in UI.

I have pushed some changes to my repo that alleviate this: https://github.com/engineerapart/cordova-plugin-braintree

You may also need an after_prepare gradle script. This cannot be included as part of the plugin, because it is a sledgehammer to force all versions of android.support to be equal, but if you need it it should help you.

https://gist.github.com/codinronan/24e93bb7a8717e13279a43882ab5c4f2

Btw that is for cordova-android 7, but to make it work on cordova-android 6.4 you need only update the path it is using on line 48. I'd recommend updating if you can though, app performance is significantly better.

like image 96
RmxPatrick Avatar answered Jun 25 '26 05:06

RmxPatrick