amplitude / experiment-react-native-client

React Native Client SDK for Amplitude Experiment
MIT License
6 stars 2 forks source link

Gradle issue after upgrading to React Native 0.71.7 #25

Closed j3lev closed 1 year ago

j3lev commented 1 year ago

Hey there, I've been updating our app to the latest stable RN version 0.71.7 and the new Kotlin version doesn't play nicely with this library and throws the following error:

FAILURE: Build failed with an exception.

* What went wrong:
The Android Gradle plugin supports only kotlin-android-extensions Gradle plugin version 1.6.20 and higher.
The following dependencies do not satisfy the required version:
project ':amplitude_experiment-react-native-client' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30

* Try:
> 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/

Our solution was to patch the library's build.gradle the following way:

 buildscript {
-    ext.kotlinVersion = "1.5.30"
     repositories {
         google()
         jcenter()
     }

     dependencies {
-        classpath 'com.android.tools.build:gradle:3.5.3'
-        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
+        classpath 'com.android.tools.build:gradle:7.3.1'
     }
 }

This fixed our issue however patching node_modules is definitely sub-optimal. The library should be updated to support the latest stable React Native versions. A possible fix could be implemented similarly to how DataDog defensively initializes their kotlin version:

 def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['DdSdkReactNative_kotlinVersion']
...
 implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

Thanks!

bgiori commented 1 year ago

Hi @j3lev, sorry for the late response, I've been out on vacation the past two weeks.

Thanks so much for your detailed issue! I'll get to this ASAP and update this issue when a fix has been released.

bgiori commented 1 year ago

@j3lev Hi I was unable to reproduce the specific error you encountered with a sample app, so I published a beta version with the proposed fix. Before I publish the actual release, can you double check this version works for you without modifying the build.gradle file in the node_modules?

Beta version is 1.1.1-beta.1

j3lev commented 1 year ago

@bgiori Hmm I'm still seeing issues. So you weren't able to reproduce this against a React Native 0.71.7 project? I'm seeing the following error when running a ./gradlew clean against the beta:

* Where:
Build file '/Users/joelevenson/Projects/genoa/genoa/node_modules/@amplitude/experiment-react-native-client/android/build.gradle' line: 59

* What went wrong:
A problem occurred evaluating project ':amplitude_experiment-react-native-client'.
> Could not get unknown property 'kotlin_version' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
lernerb commented 1 year ago

@bgiori - Try updating the build tools as well (which are required for the RN upgrade) - as well as the gradle wrapper file (e.g. - take a look at the other amplitude RN project @ https://github.com/amplitude/Amplitude-ReactNative/blob/main/example/android/gradle/wrapper/gradle-wrapper.properties#L3)

+ classpath 'com.android.tools.build:gradle:7.3.1' - classpath 'com.android.tools.build:gradle:3.5.3'

lernerb commented 1 year ago

If you take a look at the Datadog React Native project, they've fixed the issue on there end with these changes.

bgiori commented 1 year ago

Hi @j3lev @lernerb,

Thanks for your responses and suggestions, and sorry the previous version was not correct.

I've published a new version, 1.1.1-beta.2, with an updated kotlin version, android target, and com.android.tools.build:gradle package.

Let me know if this works for you.