Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[android] Version 0.2.4 requires targetSdkVersion = 31 #812

Closed
tomparkp opened this issue Feb 16, 2022 · 31 comments
Closed

[android] Version 0.2.4 requires targetSdkVersion = 31 #812

tomparkp opened this issue Feb 16, 2022 · 31 comments
Labels
android question Further information is requested

Comments

@tomparkp
Copy link

tomparkp commented Feb 16, 2022

Describe the bug
The latest version of the library (0.2.4) appears to break the build process for RN Android projects due to requiring a higher minCompileSdk than is specified in standard React Native projects.

To Reproduce
Steps to reproduce the behavior:

  1. Create a new React Native project via npx react-native init
  2. Install the library via yarn add @stripe/stripe-react-native
  3. Run the android build via yarn run android
  4. See error

Execution failed for task ':app:checkDebugAarMetadata'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.activity:activity-compose:1.4.0.
AAR metadata file: /Users/tom/.gradle/caches/transforms-3/6105d9693b6d1b89f331872365193f55/transformed/jetified-activity-compose-1.4.0/META-INF/com/android/build/gradle/aar-metadata.properties.

Expected behavior
The app builds successfully when using the library with fresh RN projects.

Screenshots
N/A

Desktop (please complete the following information):

  • macOS Monterey 12.1

Smartphone (please complete the following information):

  • Android Emulator, any

Additional context
N/A

@charliecruzan-stripe
Copy link
Collaborator

charliecruzan-stripe commented Feb 16, 2022

You're right- this is due to a bump in the stripe-android dependency. The fix for your project is to edit your android/build.gradle file:

    ext {
        buildToolsVersion = "30.0.3"
        minSdkVersion = 21
-      compileSdkVersion = 30
-      targetSdkVersion = 30
+      compileSdkVersion = 31
+      targetSdkVersion = 31
        ndkVersion = "21.4.7075529"
    }

This change is required to support Android 12 APIs

@charliecruzan-stripe charliecruzan-stripe added the question Further information is requested label Feb 16, 2022
@tomparkp
Copy link
Author

tomparkp commented Feb 16, 2022

Unfortunately in our case this breaks other dependencies. I recall seeing somewhere on a facebook/react-native issue a recommendation against changing the SDK target because the one targeted by RN might be relied on by internal and external dependencies.

So while this may not be a bug, I suspect this will be a recurring question as long as the default RN target remains at 30. For our project I think I'll have to leave it pinned at 0.2.3 for the time being.

@charliecruzan-stripe charliecruzan-stripe changed the title Version 0.2.4 incompatible with RN Android SDK target [android] Version 0.2.4 requires targetSdkVersion = 31 Feb 16, 2022
@charliecruzan-stripe
Copy link
Collaborator

I see, that makes sense. Sorry about the unforeseen break there. Luckily React Native 68 looks like it will target sdkVersion 31

@tomparkp
Copy link
Author

tomparkp commented Feb 16, 2022

Thats good, I'm content to leave this here for anyone else that stumbles on it and will make a point to close this once React Native 68 is released.

@lbinscheck
Copy link
Contributor

We have the same problem in our project after updating to 0.2.4

Waiting for RN 68 will take forever for Expo users. Is there another option to just waiting?

@charliecruzan-stripe
Copy link
Collaborator

Another option (for those who prefer not to target Android 12), would be to force the resolution of the stripe-android dependency to v18.1.0 (v18.2.0 introduces this change). However, this could have unintended consequences (since you're forcing a different version of stripe-android than is expected), but I did a quick smoke test of it and it seems to work okay. That is a possibility for the Expo managed workflow, once the next Expo SDK release comes around.

You can do this by adding the following to your android/app/build.gradle:

...
android {
  ...
    defaultConfig {
        ...
        configurations.all {
          resolutionStrategy {
            force 'com.stripe:stripe-android:18.1.0'
          }
        }
    }
}

@lbinscheck
Copy link
Contributor

Thank you @charliecruzan-stripe!
I tried it out and it builds and it worked nicely, except for handleCardAction. It resulted in a crash every time. So I decided to stick with v0.2.3 for now.

@charliecruzan-stripe
Copy link
Collaborator

If you're using the Expo managed workflow, I'm not sure how you applied the patch above...you don't have access to native build files

@lbinscheck
Copy link
Contributor

I don't, using the bare workflow.

@abedolinger
Copy link

We're on React Native 0.64.2, and I was only able to build using the fix from @charliecruzan-stripe in this thread AND the fix here (specifically, the one for flutter): stripe/stripe-android#3173. Upgrading RN is not our top priority at the moment so I guess we are stuck with this for now.

@jkepps
Copy link

jkepps commented Mar 19, 2022

we followed the steps outlined by @charliecruzan-stripe and that solved the build errors, but now we're seeing a crash relating to Klarna when we try to initialize the payment screen on android. any suggestions? everything works as expected on iOS...

Screen Shot 2022-03-18 at 4 27 09 PM

@charliecruzan-stripe
Copy link
Collaborator

Ah, yeah that makes sense. We added in the Klarna payment method, and it must not be available in stripe-android v18.1.0 (the version you are forcing resolution to in order to avoid the targetSdkVersion upgrade). You may want to try @stripe/stripe-react-native@0.3.0 instead of 0.4.0. However, I do want to reiterate that forcing the resolution of stripe-android can break things, and we do not test for that case

@jkepps
Copy link

jkepps commented Mar 21, 2022

thanks for the reply @charliecruzan-stripe

i see... so is the latest release just straight up broken? or rather was there a breaking change introduced that can't be resolved without upgrading to RN 0.68? That seems a little short sided considering RN 0.68 hasn't officially been released, so upgrading isn't really a viable solution just yet.

i'll try @stripe/stripe-react-native@0.3.0 and see if that builds and works properly. As a side, i don't actually care about using Klarna as a payment method, is there any way to just disable that in the payment sheet so it doesn't attempt to load it?

@charliecruzan-stripe
Copy link
Collaborator

No, it's not broken, it just targets Android SDK 31 which was released last year in October. You can update the targeted Android version outside of updating React Native.

is there any way to just disable that in the payment sheet so it doesn't attempt to load it?

It's not about disabling the payment method, it's about not having the code that even references that payment method in your android source. To remove that, you'd need to edit node_modules/@stripe/stripe-react-native directly.

@charliecruzan-stripe
Copy link
Collaborator

RN 0.68 has been out a while now, and Expo's SDK 45 also targets 68, so I'm going to close this issue now

@russmenum
Copy link

@charliecruzan-stripe Is it API 31 or 32 now? ON the main read me, it says 32, but API 31 is not the enforced target until NOV this year.

Here is why I ask. We use/used tipsi-stripe , but could not upgrade/migrate because too many things would break.

With Target API 31 am rebuilding our app, but this is a bit of a mess.

At the resolving dependencies stage to get the old app code to run on the new RN core, and of course, the fresh core can't find tipsi-stripe because have not installed it. I am looking at how much of a pain replacing with @stripe/stripe-react-native would be. But this is going to be enough of a mess to get to 31 then alone 32.

This issue the README links to says the target is 31, but the readme says 32. Is this issue or that readme the correct target for this library?

@charliecruzan-stripe
Copy link
Collaborator

The readme is correct, it's 32. It just points to this issue for workarounds:

Your compileSdkVersion must be 32. See #812 for potential workarounds.

compileSdkVersion shouldn't really affect the run time behavior, but it looks like you're upgrading the targetSdkVersion, which is different (and not required to be 31). See https://medium.com/androiddevelopers/picking-your-compilesdkversion-minsdkversion-targetsdkversion-a098a0341ebd for details on the differences

@russmenum
Copy link

@charliecruzan-stripe, as your linked to source says it is strongly recommended that you always compile with the latest SDK. The debate becomes is whether that is the latest beta or latest stable/current target. Around May it is good to start getting ready for the August and November cut-off. That way you have time to deal with "issues". In practice, anything sooner you break as many things as you fix because many things won't be ready until closer to Sept if they need to make changes.

compileSdkVersion = 30
targetSdkVersion = 30

the best practice is to have these 2 matched with very few exceptions. So if updating compileSdkVersion prevents the app from building, even if you can set targetSdkVersion to a different value; you have issues. Now usually the problem is compileSdkVersion being the current target prevents to app from building.

compileSdkVersion = 30
targetSdkVersion = 31

Basically, our old app can not build using 31; so rebuilding on a new core. But STRIPE it seems is a breaking change here. The current ver of this library won't pod install. I did not test building Android with 32, only 31, before I started to migrate the old app onto this core. And unfortunately, I can not test that at the moment with all the dependencies to resolve.

To be honest, I do not even have 32 or 33 installed, they go through so many revisions and they are "beta" targets right now. Ideally, you wait until they are not their number but their Android OS Ver: I belive 12L and 13.

Is there a reason STRIPE is forcing beta usage?

I opened a case on the "pod error" here seems at least one more person is having it. If it comes to it and other things are not 32 ready we use, what ver should be rolled back to for STRIPE to be 31 compliant? Wondering if that might fix the POD error.

Is the "current" ver of STRIPE intended to be beta, and we actually should be installing the last "stable"?

@charliecruzan-stripe
Copy link
Collaborator

Any pod install errors are iOS specific, so that is separate form the android compile and target SDK versions.

the best practice is to have these 2 matched with very few exceptions.

Can you elaborate on this?

In your example above, you have compileSdkVersion still set to 30, which will not work on the most recent version of Stripe React Native.

Also, Android 12 was released publicly on October 4, 2021, so 32 is not a beta target.

@russmenum
Copy link

@charliecruzan-stripe respectfully anything higher than Google mandated targets is "beta" they release and endlessly update. It takes time for everything to be good and ready.

They roll forward in August and November of each year. Most stable apps are following the minimum target for full library and decency access.

Can you elaborate on this?

In your example above, you have compileSdkVersion still set to 30, which will not work on the most recent version of Stripe React Native.

Yes, and this is the issue with Stripe pre-targeting. The app won't build using compileSdkVersion = 31 only compileSdkVersion = 30. In many cases other dependencies of an app only NOW update to target, to comply with the NOV 2022 deadline. By requiring 32, Stripe may very well be limiting what of the available libraries an app can use at all.

Because today the target is 30 or 31 depending if you are a new or old app.

I will have no clue if this can even build on 32 until I get there, as was stated goal was to build for 31 to be Nov 2022 compliant.

The default install should be one that targets the current google and apple targets, and anything higher should be a beta

@charliecruzan-stripe
Copy link
Collaborator

charliecruzan-stripe commented Sep 12, 2022

"Google mandated targets" isn't exactly specific enough, in my opinion. Google has different enforcements for new apps vs updates to existing apps. New apps must target Android 12 (API level 31) or higher in order to be submitted to Google Play, whereas the Nov 2022 deadline you're referring to is for updates to existing apps. So Google is already enforcing API level 31, and I think calling it "beta" isn't accurate

Also this isn't exactly relevant, as that refers to targetSdkVersion, not compileSdkVersion

@russmenum
Copy link

russmenum commented Sep 12, 2022

@charliecruzan-stripe vocab debate aside the point is 32 is not the current target recommended; and is a breaking requirement for many things. And it is bad practice for targetSdkVersion and ````compileSdkVersion``` to be different.

But since the current ver of Stripe is not targeting google targets what was the last ver that did?

@charliecruzan-stripe
Copy link
Collaborator

This change was listed as a breaking change for v0.18.0. We need to set compileSdkVersion to 32 to use the most recent version of stripe-android and get those features/fixes in, so the best move I think if you do not want to update your compileSdkVersion is to use an older version of @stripe/stripe-react-native

@russmenum
Copy link

russmenum commented Sep 12, 2022

@charliecruzan-stripe and what ver was that? and would it have current patches and features?

@charliecruzan-stripe
Copy link
Collaborator

v0.2.3 can be used in projects that have compileSdkVersion set to 30

v0.17.0 can be used in projects that have compileSdkVersion set to 31

would it have current patches and features?

Unfortunately no, since without bumping compileSdkVersion, you cannot use the latest version of stripe-android

@maxizhukov
Copy link

I still have same error, is there are any chance to fix it Expo managed workflow?

@charliecruzan-stripe
Copy link
Collaborator

Expo's managed workflow controls your compileSdkVersion and the version of stripe-react-native, so as long as you run expo install @stripe/stripe-react-native, it should work. Otherwise that could be an issue with Expo

@jordzawada
Copy link

jordzawada commented Nov 2, 2022

Expo's managed workflow controls your compileSdkVersion and the version of stripe-react-native, so as long as you run expo install @stripe/stripe-react-native, it should work. Otherwise that could be an issue with Expo

I did find a way to force change it a few months ago https://forums.expo.dev/t/managed-eas-build-how-to-edit-build-gradle-via-mods/55004/2
but I changed minSdkVersion to compileSdkVersion. I did it so I could fix random crashes and get actually useful functions. I don't know why expo is using 0.6 when stripe is 13 versions ahead up to 0.19.

Now strangely it is not working for 32, it did work for 30->31. Maybe because I am using app.config.json instead of app.json.

UPDATE: this works https://docs.expo.dev/versions/latest/sdk/build-properties

alexsegura added a commit to coopcycle/coopcycle-app that referenced this issue Nov 16, 2022
r0xsh pushed a commit to coopcycle/coopcycle-app that referenced this issue Nov 18, 2022
@aleqsio
Copy link

aleqsio commented Nov 29, 2022

As a solution for Expo Bare, it's possible to use the build-properties plugin in the following way:

npx expo install expo-build-properties
 "plugins": [
      [
      "@stripe/stripe-react-native",
        {
          "merchantIdentifier": ...,
          "enableGooglePay": ...
        },
        "expo-build-properties",
        {
          "android": {
            "compileSdkVersion": 33,
            "targetSdkVersion": 33,
            "buildToolsVersion": "33.0.0"
          }
        }
      ]
    ]

@sohanpc
Copy link

sohanpc commented Jan 3, 2023

@charliecruzan-stripe here is my configuration and version

"react-native": "0.70.6"

build.gradle

ext {
       buildToolsVersion = "31.0.0"
       minSdkVersion = 21
       compileSdkVersion = 31
       targetSdkVersion = 31

       if (System.properties['os.arch'] == "aarch64") {
           // For M1 Users we need to use the NDK 24 which added support for aarch64
           ndkVersion = "24.0.8215888"
       } else {
           // Otherwise we default to the side-by-side NDK version from AGP.
           ndkVersion = "21.4.7075529"
       }
   }

Now error saying to use compileSdkVersion 32. but compileSdkVersion 32 is not supported in the new react native (0.70.6)

@ayanWappnet
Copy link

Describe the bug

What went wrong:
Execution failed for task ':app:checkDebugAarMetadata'.
A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
31 issues were found when checking AAR metadata:

Expected behavior
The application was supposed to work before downloading the stripe, it was working

react-native info

"react": "17.0.2",
"react-native": "0.66.1",
"@stripe/stripe-react-native": "0.19.0",

build.gradle
ext {
buildToolsVersion = "31.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 31
if (System.properties['os.arch'] == "aarch64") {
// For M1 Users we need to use the NDK 24 which added support for aarch64
ndkVersion = "24.0.8215888"
} else {
// Otherwise we default to the side-by-side NDK version from AGP.
ndkVersion = "21.4.7075529"
}
googlePlayServicesAuthVersion = "19.2.0" // <--- use this version or newer
playServicesVersion = "17.0.0"
supportLibVersion = "28.0.0"
// kotlinVersion = "1.3.72"
}

LBlend pushed a commit to edb-gjengen/dusken-client that referenced this issue Oct 11, 2024
Stripe android lib needs compileSdkVersion = 31
ref stripe/stripe-react-native#812

To not break anything else in the RN space, we need to bump to RN 0.68
LBlend pushed a commit to edb-gjengen/hmgrisen that referenced this issue Oct 11, 2024
Stripe android lib needs compileSdkVersion = 31
ref stripe/stripe-react-native#812

To not break anything else in the RN space, we need to bump to RN 0.68
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android question Further information is requested
Projects
None yet
Development

No branches or pull requests