NativeScript / android

NativeScript for Android using v8
https://docs.nativescript.org/guide/android-marshalling
Apache License 2.0
523 stars 134 forks source link

"Error: java.lang.NoSuchMethodError: no static method" when calling a non-static method on an instance #1708

Open sebj54 opened 2 years ago

sebj54 commented 2 years ago

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

✔ Component nativescript has 8.2.3 version and is up to date.
✔ Component @nativescript/core has 8.2.1 version and is up to date.
✔ Component @nativescript/ios has 8.2.3 version and is up to date.
✔ Component @nativescript/android has 8.2.2 version and is up to date.

Describe the bug

This problem happens with the @triniwiz/nativescript-stripe module (see https://github.com/triniwiz/nativescript-plugins/issues/110).

When calling this method:

this.stripe.confirmSetupIntent(activity, new StripeSetupIntentParams(paymentMethodId, clientSecret).native);

This error is thrown:

Error: java.lang.NoSuchMethodError: no static method "Lcom/stripe/android/Stripe;.confirmSetupIntent(Landroidx/activity/ComponentActivity;Lcom/stripe/android/model/ConfirmSetupIntentParams;)V"

I used java.util.Arrays.toString(this.stripe.getClass().getMethods())) to get this method's signature:

public final void com.stripe.android.Stripe.confirmSetupIntent(androidx.activity.ComponentActivity,com.stripe.android.model.ConfirmSetupIntentParams)

It looks totally the same (to me). There are also methods with the same name:

public final void com.stripe.android.Stripe.confirmSetupIntent(androidx.fragment.app.Fragment,com.stripe.android.model.ConfirmSetupIntentParams)

public final void com.stripe.android.Stripe.confirmSetupIntent(androidx.activity.ComponentActivity,com.stripe.android.model.ConfirmSetupIntentParams,java.lang.String)

public final void com.stripe.android.Stripe.confirmSetupIntent(androidx.fragment.app.Fragment,com.stripe.android.model.ConfirmSetupIntentParams,java.lang.String)

public static void com.stripe.android.Stripe.confirmSetupIntent$default(com.stripe.android.Stripe,androidx.activity.ComponentActivity,com.stripe.android.model.ConfirmSetupIntentParams,java.lang.String,int,java.lang.Object)

public static void com.stripe.android.Stripe.confirmSetupIntent$default(com.stripe.android.Stripe,androidx.fragment.app.Fragment,com.stripe.android.model.ConfirmSetupIntentParams,java.lang.String,int,java.lang.Object)

public final com.stripe.android.model.SetupIntent com.stripe.android.Stripe.confirmSetupIntentSynchronous(com.stripe.android.model.ConfirmSetupIntentParams) throws com.stripe.android.exception.AuthenticationException,com.stripe.android.core.exception.InvalidRequestException,com.stripe.android.core.exception.APIConnectionException,com.stripe.android.core.exception.APIException

public final com.stripe.android.model.SetupIntent com.stripe.android.Stripe.confirmSetupIntentSynchronous(com.stripe.android.model.ConfirmSetupIntentParams,java.lang.String) throws com.stripe.android.exception.AuthenticationException,com.stripe.android.core.exception.InvalidRequestException,com.stripe.android.core.exception.APIConnectionException,com.stripe.android.core.exception.APIException

public static com.stripe.android.model.SetupIntent com.stripe.android.Stripe.confirmSetupIntentSynchronous$default(com.stripe.android.Stripe,com.stripe.android.model.ConfirmSetupIntentParams,java.lang.String,int,java.lang.Object) throws com.stripe.android.exception.AuthenticationException,com.stripe.android.core.exception.InvalidRequestException,com.stripe.android.core.exception.APIConnectionException,com.stripe.android.core.exception.APIException

To Reproduce

Here is the include.gradle file of this plugin:

android {
    defaultConfig {
      minSdkVersion 21
    }
  packagingOptions {
    pickFirst 'META-INF/stripe_release.kotlin_module'
  }
}
dependencies {
  implementation('com.stripe:stripe-android:19.0.0'){
    transitive = true
  }
  implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'
  implementation "androidx.lifecycle:lifecycle-livedata:2.2.0"
  implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
}

Maybe adding the plugin to a new project is enough (I can provide a sample project if you think this issue belongs here). Then call:

const publishableKey = 'pk_test_xxxxxxxxxxxxxxxxxxxxxxxx'
const stripe = new Stripe(publishableKey)
stripe.confirmSetupIntent('pm_xxxxxxxxxxxxxxxxxxxxxxxx', 'secret_xxxxxxxxxxxxxxxxxxxxxxxx')e

I don't know if it will work with these fake IDs, but I think it should return an API error if the method gets called.

Let me know if you need extra information.

triniwiz commented 1 year ago

This signature public final void com.stripe.android.Stripe.confirmSetupIntent(androidx.activity.ComponentActivity,com.stripe.android.model.ConfirmSetupIntentParams,java.lang.String) requires 3 but you passed 2 that’s why the error said it doesn’t have a signature like this Error: java.lang.NoSuchMethodError: no static method "Lcom/stripe/android/Stripe;.confirmSetupIntent(Landroidx/activity/ComponentActivity;Lcom/stripe/android/model/ConfirmSetupIntentParams;)V" you’re missing a string

sebj54 commented 1 year ago

Thank you, I'll give it another try soon. I'll let you know in this issue.