Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.62k stars 600 forks source link

Execution failed for task ':nozbe_watermelondb:compileDebugKotlin' #1239

Closed przbadu closed 2 years ago

przbadu commented 2 years ago

Steps:

 npx react-native init TodoApp --template react-native-template-typescript
cd TodoApp
yarn add @nozbe/watermelondb
yarn add --dev @babel/plugin-proposal-decorators

Then add .babelrc file

{
  "presets": ["module:metro-react-native-babel-preset"],
  "plugins": [
    ["@babel/plugin-proposal-decorators", { "legacy": true }]
  ]
}

Library version:

"@nozbe/watermelondb": "^0.24.0",
"react": "17.0.2",
 "react-native": "0.66.4"

Run the app

yarn run android

Current Kotlin version

2.6.10

Screenshot_1

Build Error

FAILURE: Build failed with an exception.                                                                                                                                   

* What went wrong:                                                                                                                                                         
Execution failed for task ':nozbe_watermelondb: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 7s                                                                                                                                                         

error Failed to install the app. Make sure you have the Android development environment set up: https://reactnative.dev/docs/environment-setup.                            
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081                                                                                        
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\Database.kt: (42, 39): 'forEach((T) 
-> Unit): Unit' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                     
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\Database.kt: (61, 34): 'forEach((T) 
-> Unit): Unit' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                     
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\Database.kt: (76, 35): 'use((T) -> R
): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                               
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\Database.kt: (82, 66): 'use((T) -> R
): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                               
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\Database.kt: (95, 32): 'forEach((T) 
-> Unit): Unit' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                     
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\Database.kt: (104, 41): 'use((T) -> 
R): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                              
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseBridge.kt: (39, 9): 'assert(
Boolean, () -> Any): Unit' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                          
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseDriver.kt: (44, 88): 'use((T
) -> R): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                         
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseDriver.kt: (59, 40): 'use((T
) -> R): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                         
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseDriver.kt: (77, 40): 'use((T
) -> R): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                         
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseDriver.kt: (89, 40): 'use((T
) -> R): R' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                                         
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseDriver.kt: (145, 16): 'forEa
ch((T) -> Unit): Unit' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                              
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseDriver.kt: (146, 20): 'forEa
ch((T) -> Unit): Unit' is only available since Kotlin 1.3.50 and cannot be used in Kotlin 1.3                                                                              
e: C:\Users\user\Documents\projects\react\TodoApp\node_modules\@nozbe\watermelondb\native\android\src\main\java\com\nozbe\watermelondb\DatabaseDriver.kt: (176, 9): 'requir
e(Boolean, () -> Any): 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 ':nozbe_watermelondb: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 7s                                                                                                                                                         

    at makeError (C:\Users\user\Documents\projects\react\TodoApp\node_modules\execa\index.js:174:9)                                                                        
    at C:\Users\user\Documents\projects\react\TodoApp\node_modules\execa\index.js:278:16                                                                                   
    at processTicksAndRejections (node:internal/process/task_queues:96:5)                                                                                                  
    at async runOnAllDevices (C:\Users\user\Documents\projects\react\TodoApp\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDe
vices.js:109:5)                                                                                                                                                            
    at async Command.handleAction (C:\Users\user\Documents\projects\react\TodoApp\node_modules\@react-native-community\cli\build\index.js:192:9)                           
info Run CLI with --verbose flag for more details.                                                                                                                         
error Command failed with exit code 1.                                                                                                                                     
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.                                                                                                                                                                                                                                                                
przbadu commented 2 years ago

I have few month old project running in below versions, and it is working fine:

"@nozbe/watermelondb": "0.23",
"react": "17.0.1",
"react-native": "0.64.2",
przbadu commented 2 years ago

Ok after doing some investigation, latest version of watermelondb works well with react-native: 0.64.2

Working versions:

"@nozbe/watermelondb": "^0.24.0",
"react": "17.0.1",
"react-native": "0.64.2"

So, it definitely is an issue on latest version of react-native more specifically, 0.66.4 version of react-native and watermelondb causing above error.

muhaimincs commented 2 years ago

failed with "react-native": "0.65.1"

andrepaulo-bit commented 2 years ago

fails with "react-native": "0.67.1", as well Kotlin is on 1.6.10, just like przbadu nevermind, I was in 1.3.10 (or 20).

andrepaulo-bit commented 2 years ago

Updated Kotlin on Android Studio to 1.6.10 and still had errors. Then added kotlinVersion = "1.6.10" to android/build.gradle and it works now:

buildscript {
    ext {
        ...
        kotlinVersion = "1.6.10"
    }

@przbadu while your Kotlin is on 1.6.10 (on Android Studio), the logs say that you're using a 1.3 version. Check if you have a version on the build.gradle

prof-xed commented 2 years ago

This worked!

I have:

{
    "@nozbe/watermelondb": "^0.24.0",
    "react": "17.0.2",
    "react-native": "0.66.4",
}

Just updated android/build.gradle as @andrepaulo-bit suggested and it work just fine. :tada:

kotlinVersion = "1.6.10"

Thanks @andrepaulo-bit