stripe-react-native
stripe-react-native copied to clipboard
Kotlin 2 build error when building Android with Expo 52
I upgraded to v0.45.0. No issues were found on iOS, but the Android compilation failed with an error like this: "node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/utils/Mappers.kt:1043:29 Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The actual metadata version is 2.1.0, but the compiler version 1.9.0 can read versions up to 2.0.0." Currently, I'm using Expo 52, and it seems that it doesn't support upgrading to Kotlin 2.0.0 yet. What other solutions are there?
Originally posted by @ivan-moego in #1732
The Stripe Android SDK requires the Kotlin Gradle plugin version 2.x. When using Expo SDK 52 or React Native version 0.77 and below you will need to make these changes to support it.
Expo
Install expo-build-properties if you do not have it already. Make sure to use version 0.13.3 or later.
npx expo install expo-build-properties
In app.json set kotlinVersion to 2.0.21 or later using the expo-build-properties plugin.
+ "plugins": [
+ [
+ "expo-build-properties",
+ {
+ "android": {
+ "kotlinVersion": "2.0.21"
+ }
+ }
+ ]
+ ]
React Native
In android/build.gradle make the following changes:
- In the
buildscript.extsection addkotlinVersion = '2.0.21'. - In the
buildscript.dependenciessection changeclasspath('org.jetbrains.kotlin:kotlin-gradle-plugin')forclasspath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion").
@@ -6,6 +6,7 @@ buildscript {
minSdkVersion = '24'
compileSdkVersion = '35'
targetSdkVersion = '34'
+ kotlinVersion = '2.0.21'
ndkVersion = "26.1.10909125"
}
@@ -16,7 +17,7 @@ buildscript {
dependencies {
classpath('com.android.tools.build:gradle')
classpath('com.facebook.react:react-native-gradle-plugin')
- classpath('org.jetbrains.kotlin:kotlin-gradle-plugin')
+ classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
}
}
i am getting same error in sdk 53:
A problem occurred configuring project ':stripe_stripe-react-native'.
> Starting in Kotlin 2.0, the Compose Compiler Gradle plugin is required
Hello @aahilalwani25, is there anywhere in your project where you specify a kotlin version lower than 2.0? From my testing it should work fine on sdk 53.
@janicduplessis Yes. I am using kotlin version 1.9.25. I have tried to convert to 2.0.21, and it is building successfully by using ./gradlew clean, but when i try to to EAS build using eas build --platform android --profile development, it is giving me error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all dependencies for configuration ':app:debugCompileClasspath'.
> Could not resolve project :react-native-community_datetimepicker.
Required by:
project :app
> No matching variant of project :react-native-community_datetimepicker was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
> Could not resolve project :shopify_flash-list.
Required by:
project :app
> No matching variant of project :shopify_flash-list was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
> Could not resolve project :stripe_stripe-react-native.
Required by:
project :app
> No matching variant of project :stripe_stripe-react-native was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
> Could not resolve project :react-native-gesture-handler.
Required by:
project :app
> No matching variant of project :react-native-gesture-handler was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
> Could not resolve project :react-native-reanimated.
Required by:
project :app
> No matching variant of project :react-native-reanimated was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
> Could not resolve project :react-native-safe-area-context.
Required by:
project :app
> No matching variant of project :react-native-safe-area-context was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
> Could not resolve project :react-native-screens.
Required by:
project :app
> No matching variant of project :react-native-screens was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
> Could not resolve project :react-native-svg.
Required by:
project :app
> No matching variant of project :react-native-svg was found. The consumer was configured to find a library for use during compile-time, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.AgpVersionAttr' with value '8.8.2', attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug', attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' but:
- No variants exist.
* Try:
> Creating consumable variants is explained in more detail at https://docs.gradle.org/8.10.2/userguide/declaring_dependencies.html#sec:resolvable-consumable-configs.
> Review the variant matching algorithm at https://docs.gradle.org/8.10.2/userguide/variant_attributes.html#sec:abm_algorithm.
>
Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org/.
BUILD FAILED in 1m 47s
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.10.2/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
20 actionable tasks: 20 executed
Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
I am using gradle 8.10.2
@aahilalwani25 Can you try passing --clear-cache to the eas build command? Maybe it is a caching issue.
@aahilalwani25 Can you try passing
--clear-cacheto theeas buildcommand? Maybe it is a caching issue.
@janicduplessis I have figured out the solution. I am not sure about the EAS build but the steps that I have followed:
- run the command
npx expo install --fix - update the package 0.45 to 0.38.6 (
"@stripe/stripe-react-native": "0.38.6"), it does not require kotlin v2.0 support - Then built APK using
npx expo run:android
I am not sure about EAS build, but if anyone who wants to test the google pay by building APK, then this might help. I have used these steps as an option for testing google pay.
PS: I am using free account of EAS, so I don't want to waste my build creds
The Stripe Android SDK requires the Kotlin Gradle plugin version 2.x. When using Expo SDK 52 or React Native version 0.77 and below you will need to make these changes to support it.
Expo
Install expo-build-properties if you do not have it already. Make sure to use version
0.13.3or later.npx expo install expo-build-propertiesIn
app.jsonsetkotlinVersionto2.0.21or later using theexpo-build-propertiesplugin.
- "plugins": [
["expo-build-properties",{"android": {"kotlinVersion": "2.0.21"}}]- ]
React Native
In
android/build.gradlemake the following changes:
- In the
buildscript.extsection addkotlinVersion = '2.0.21'.- In the
buildscript.dependenciessection changeclasspath('org.jetbrains.kotlin:kotlin-gradle-plugin')forclasspath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion").@@ -6,6 +6,7 @@ buildscript { minSdkVersion = '24' compileSdkVersion = '35' targetSdkVersion = '34'
} @@ -16,7 +17,7 @@ buildscript { dependencies { classpath('com.android.tools.build:gradle') classpath('com.facebook.react:react-native-gradle-plugin')kotlinVersion = '2.0.21' ndkVersion = "26.1.10909125"
classpath('org.jetbrains.kotlin:kotlin-gradle-plugin')
} }classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
This saved me. I didn't have the stripe issue but react-native-reanimated required this kotlin version in order to build for Android. thx
In my project, the new architecture is enabled for iOS, while the old architecture is still used for Android. After modifying some code, it ran successfully. Here is my patch. I hope it will be useful to you.
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerInterface.java
index 231abd1c44ba66bee3db047da6fa9b454a7b8cb8..e0a8a4ebef7c3fa24f580d192015fe6ce0084e5f 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/AddToWalletButtonManagerInterface.java
@@ -13,9 +13,8 @@ import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReadableMap;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface AddToWalletButtonManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface AddToWalletButtonManagerInterface<T extends View> {
void setIOSButtonStyle(T view, @Nullable String value);
void setAndroidAssetSource(T view, @Nullable ReadableMap value);
void setTestEnv(T view, boolean value);
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerInterface.java
index 76d3d48c14b78f55ad4a427bfe674a935fb982e4..9031b9cb2140fcbce17b60c30d095cce7fdb8a30 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/AddressSheetViewManagerInterface.java
@@ -13,9 +13,8 @@ import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReadableArray;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface AddressSheetViewManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface AddressSheetViewManagerInterface<T extends View> {
void setVisible(T view, boolean value);
void setPresentationStyle(T view, @Nullable String value);
void setAnimationStyle(T view, @Nullable String value);
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java
index fa12865d7e1f855bae5e0f45bbc6daae8599bf97..3656fbca1c9141bfc26b8e03266e4bfff039c937 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/ApplePayButtonManagerInterface.java
@@ -10,9 +10,8 @@
package com.facebook.react.viewmanagers;
import android.view.View;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface ApplePayButtonManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface ApplePayButtonManagerInterface<T extends View> {
void setDisabled(T view, boolean value);
void setType(T view, int value);
void setButtonStyle(T view, int value);
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerInterface.java
index 3d0e8049fc199658326b8371767aa7af937d4000..0580cf3796c0584bfe65f56884ae0531411bf29f 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/AuBECSDebitFormManagerInterface.java
@@ -12,9 +12,8 @@ package com.facebook.react.viewmanagers;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Dynamic;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface AuBECSDebitFormManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface AuBECSDebitFormManagerInterface<T extends View> {
void setCompanyName(T view, @Nullable String value);
void setFormStyle(T view, Dynamic value);
}
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerInterface.java
index 18e3f8fa4811ce6f174be66b89bd41478ea1ab38..f9dd97970aff47161c85e064198b07d9e421b173 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFieldManagerInterface.java
@@ -13,9 +13,8 @@ import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReadableArray;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface CardFieldManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface CardFieldManagerInterface<T extends View> {
void setAutofocus(T view, boolean value);
void setCardStyle(T view, Dynamic value);
void setCountryCode(T view, @Nullable String value);
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerInterface.java
index 974a60e2e980544f99ef72ec1d1afcfa192c99a4..0dfa5ddf6f8fbe1770d47c31711388ecea952b1b 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/CardFormManagerInterface.java
@@ -13,9 +13,8 @@ import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Dynamic;
import com.facebook.react.bridge.ReadableArray;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface CardFormManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface CardFormManagerInterface<T extends View> {
void setAutofocus(T view, boolean value);
void setCardStyle(T view, Dynamic value);
void setDangerouslyGetFullCardDetails(T view, boolean value);
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java
index aa4c06a3984bf19563c581c52b81ecdbda592eb1..6dade8a23c35e26d30eddabf8d19195def833e07 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/EmbeddedPaymentElementViewManagerInterface.java
@@ -11,9 +11,8 @@ package com.facebook.react.viewmanagers;
import android.view.View;
import com.facebook.react.bridge.Dynamic;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface EmbeddedPaymentElementViewManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface EmbeddedPaymentElementViewManagerInterface<T extends View> {
void setConfiguration(T view, Dynamic value);
void setIntentConfiguration(T view, Dynamic value);
void confirm(T view);
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerInterface.java
index f6369d57a053d572569e14a317a053b78f7a2b49..468d3772ac8eff764e1e2380b0ac3e8ec98f39e9 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/GooglePayButtonManagerInterface.java
@@ -10,9 +10,8 @@
package com.facebook.react.viewmanagers;
import android.view.View;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface GooglePayButtonManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface GooglePayButtonManagerInterface<T extends View> {
void setType(T view, int value);
void setAppearance(T view, int value);
void setBorderRadius(T view, int value);
diff --git a/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerInterface.java b/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerInterface.java
index eb2ccfa898ea2fb6c938f503bd406b4d06f2047e..8994db7b2d603f1807145e54bfd4669b155a902b 100644
--- a/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerInterface.java
+++ b/android/src/oldarch/java/com/facebook/react/viewmanagers/StripeContainerManagerInterface.java
@@ -10,8 +10,7 @@
package com.facebook.react.viewmanagers;
import android.view.View;
-import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface;
-public interface StripeContainerManagerInterface<T extends View> extends ViewManagerWithGeneratedInterface {
+public interface StripeContainerManagerInterface<T extends View> {
void setKeyboardShouldPersistTaps(T view, boolean value);
}
diff --git a/ios/NewArch/CardFormComponentView.mm b/ios/NewArch/CardFormComponentView.mm
index e648159a6e133f75dec78121cc0d74a04c38fa1e..970f76ea7ed77452445c77d82258207504cde9af 100644
--- a/ios/NewArch/CardFormComponentView.mm
+++ b/ios/NewArch/CardFormComponentView.mm
@@ -106,3 +106,8 @@ - (void)focus
{
return CardFormComponentView.class;
}
+
+Class<RCTComponentViewProtocol> GooglePayButtonCls(void)
+{
+ return NSClassFromString(@"GooglePayButton");
+}
try @ivan-moego solution and end up with this:
Note: Recompile with -Xlint:deprecation for details.
e: file:///Users/kelvin/Documents/pelago/pelago-traveller-mobile/node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt:3:27 Unresolved reference 'BaseReactPackage'.
e: file:///Users/kelvin/Documents/pelago/pelago-traveller-mobile/node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt:15:26 Unresolved reference 'BaseReactPackage'.
e: file:///Users/kelvin/Documents/pelago/pelago-traveller-mobile/node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt:16:3 'getModule' overrides nothing.
e: file:///Users/kelvin/Documents/pelago/pelago-traveller-mobile/node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt:25:3 'getReactModuleInfoProvider' overrides nothing.
e: file:///Users/kelvin/Documents/pelago/pelago-traveller-mobile/node_modules/@stripe/stripe-react-native/android/src/main/java/com/reactnativestripesdk/StripeSdkPackage.kt:43:3 'createViewManagers' overrides nothing. FAILURE: Build failed with an exception. * What went wrong:
Execution failed for task ':stripe_stripe-react-native:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction > Compilation error. See log for more details *
Also try to fix StripeSdkPackage but out of my knowledge and look like it related to new architecture implementation, i'm using react-native 0.73.x btw.
So i think update kotlin version to 2.x will not recommend for react-native < 0.75 due to new architecture availability
Hi @kelvin-pelago, did you resolve your integration issue?
If not, I'd love to point you to our support channel on our Discord, where we have engineers ready to help you 24/5. Thank you!
Seems to be a problem with gradleCommand 8.10, fixed for me with :
[
'expo-build-properties',
{
ios: {
useFrameworks: 'static',
},
android: {
kotlinVersion: '1.9.25',
compileSdkVersion: 35,
targetSdkVersion: 34,
buildToolsVersion: '35.0.0',
composeCompilerVersion: '1.5.12',
gradleCommand: '8.8',
},
},
],
Похоже, проблема с gradleCommand 8.10, для меня она исправлена с помощью:
[ 'expo-build-properties', { ios: { useFrameworks: 'static', }, android: { kotlinVersion: '1.9.25', compileSdkVersion: 35, targetSdkVersion: 34, buildToolsVersion: '35.0.0', composeCompilerVersion: '1.5.12', gradleCommand: '8.8', }, }, ],
rn 80+?
Doing the above fix at first did not fix the problem initially
I deleted android/, node_modules/ and my lock file (pnpm-lock.yaml) then ran pnpm i followed by expo run:android and everything now compiles.