segmentio / analytics-react-native

The hassle-free way to add analytics to your React-Native app.
https://segment.com/docs/sources/mobile/react-native/
MIT License
366 stars 188 forks source link

Task :segment_analytics-react-native:compileDebugKotlin FAILED #225

Closed chinvib66 closed 3 years ago

chinvib66 commented 4 years ago

This problem started after updating Android Studio and Kotlin plugin to latest versions, on Windows as well as Ubuntu.

React Native: 0.63.2 Android Studio Version 4.1 Kotlin Version: 1.4.10

Command: yarn run android

Logs:

Welcome to Gradle 6.2!

Here are the highlights of this release:
 - Dependency checksum and signature verification
 - Documentation links in deprecation messages
 - Shareable read-only dependency cache

For more details see https://docs.gradle.org/6.2/release-notes.html

Starting a Gradle Daemon (subsequent builds will be faster)

> .... Other Tasks ....

> Task :segment_analytics-react-native:compileDebugKotlin FAILED

Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.2/userguide/command_line_interface.html#sec:command_line_warnings
133 actionable tasks: 133 executed
Note: /path/to/project/parent/rn-app/node_modules/@react-native-community/async-storage/android/src/main/java/com
/reactnativecommunity/asyncstorage/AsyncStorageModule.java uses or overrides a deprecated API.

.... Some other Notes ....

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
e: /path/to/project/parent/rn-app/node_modules/@segment/analytics-react-native/android/src/main/java/com/segment/
analytics/reactnative/core/RNAnalyticsModule.kt: (279, 27): 'forEach((Map.Entry<K, V>) -> Unit): Unit' is only available since 
Kotlin 1.3.50 and cannot be used in Kotlin 1.3
e: /path/to/project/parent/rn-app/node_modules/@segment/analytics-react-native/android/src/main/java/com/segment/
analytics/reactnative/core/RNAnalyticsModule.kt: (283, 32): 'forEach((Map.Entry<K, V>) -> Unit): Unit' is only available since 
Kotlin 1.3.50 and cannot be used in Kotlin 1.3

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':segment_analytics-react-native:compileDebugKotlin'.
> Compilation error. See log for more details

* 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

BUILD FAILED in 6m 16s

error Failed to install the app. Make sure you have the Android development environment set up: 
https://reactnative.dev/docs/environment-setup. Run CLI with --verbose flag for more details.
Error: Command failed: ./gradlew app:installDebug -PreactNativeDevServerPort=8081
error Command failed with exit code 1.
chinvib66 commented 4 years ago

So, I solved this by setting kotlinVersion in project/android/build.gradle to the installed version 1.4.10

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "29.0.2"
        minSdkVersion = 16
        compileSdkVersion = 29
        targetSdkVersion = 29
        kotlinVersion = "1.4.10"
    }

.... rest of the code

From the logs in my 1st comment I see that the problem lies in the usage of Unit class in the package, which is introduced in Kotlin v 1.3.50; while the package specifies default version to be used as 1.3.21 as seen here.

So, I guess the defaultKotlinVersion for the package needs to be upgraded to atleast 1.3.50 for proper functioning.

macortesn commented 4 years ago

I have this problem and it is solved by adding the kotlin version, but it only works for the debug version. When generating an apk for the release version, the app crashes and shows the following error: image Does anyone know how to fix this error?

SMJ93 commented 4 years ago

I fixed this by updating node_modules/@segment/analytics-react-native/android/build.gradle line 9 to:

ext.defaultKotlinVersion = '1.3.50'

and used patch-package to save the changes:

npx patch-package @segment/analytics-react-native

your patches/@segment+analytics-react-native+1.3.1.patch should look like:

diff --git a/node_modules/@segment/analytics-react-native/android/build.gradle b/node_modules/@segment/analytics-react-native/android/build.gradle
index 54cffd4..7388e1e 100644
--- a/node_modules/@segment/analytics-react-native/android/build.gradle
+++ b/node_modules/@segment/analytics-react-native/android/build.gradle
@@ -6,7 +6,7 @@ def safeExtGet(prop, fallback) {
 }

 buildscript {
-    ext.defaultKotlinVersion = '1.3.21'
+    ext.defaultKotlinVersion = '1.3.50'

     repositories {
         jcenter()

Now it builds in debug and release mode.

Hopefully Segment release an official fix soon!

jacob-israel-turner commented 4 years ago

Setting ext.defaultKotlinVersion to 1.3.50 solved this problem for me - but I'm really confused why this all of a sudden became an issue. We haven't touched this integration in at least a few weeks - was Kotlin programmed to start failing forEach((Map.Entry<K, V>) -> Unit): Unit on October 16, 2020 or something?

Regardless - I'm hoping the Segment team will release an official patch quickly.

andiradulescu commented 4 years ago

This wasn't enough for me.

I also needed to add a rule to proguard-rules.pro

See https://github.com/segmentio/analytics-react-native/issues/227#issuecomment-714789154

prayansh commented 3 years ago

The main issue here should have been fixed by https://github.com/segmentio/analytics-react-native/pull/223.

Closing this out unless someone else is facing the same issue with the kotlin version

neerajbuccam commented 3 years ago

We are facing this comileDebugKotlin Failed issue again and is open issue here: #289 Fixed mentioned by @SMJ93 dint work this time. Can someone please help?

neerajbuccam commented 3 years ago

We are facing this comileDebugKotlin Failed issue again and is open issue here: #289 Fixed mentioned by @SMJ93 dint work this time. Can someone please help?

i got this fixed using a workaround below https://github.com/segmentio/analytics-react-native/issues/289#issuecomment-818736118

anisurrahman072 commented 2 years ago

Hey guys, I have found these two lines in the log: One is: react-native-agora:compileDebugKotlin Two is: Kotlin. The binary version of its metadata is 1.6.0, expected version is 1.4.0.

So then i updated my android/build.gradle. So i basically add this line under ext

ext {
    ....... other code
        kotlinVersion = "1.6.0"
}

That's it. It is working perfectly now 🎉🚀✌️