WatermelonDB icon indicating copy to clipboard operation
WatermelonDB copied to clipboard

nozbe_watermelondb not build on react native 0.68.1

Open Productivix opened this issue 2 years ago • 11 comments

hi, on a fresk install of react native 0.68.1 , I get the error at the end of build : ` FAILURE: Build failed with an exception.

  • What went wrong: The Android Gradle plugin supports only Kotlin Gradle plugin version 1.3.40 and higher. The following dependencies do not satisfy the required version: project ':nozbe_watermelondb' -> org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.21`

would it be possible to get a more updated version please ? thank you !

Productivix avatar Apr 27 '22 16:04 Productivix

Hi @Productivix

You can customize the kotlin version in your project

Make sure the kotlin version is set to 1.3.50 or above. Just set ext properties `kotlinVersion` in `android/build.gradle`, and WatermelonDB will use the specified kotlin version.
buildscript {
    ext.kotlinVersion = '1.3.50'
}

mlecoq avatar Apr 28 '22 07:04 mlecoq

hi, thank you for your answer. I corrected the file you saied in : `buildscript { ext { buildToolsVersion = "29.0.2" minSdkVersion = 16 compileSdkVersion = 29 targetSdkVersion = 29 kotlin_version = '1.3.50' //before : kotlin_version = '1.3.21' } repositories { google() jcenter() } dependencies { classpath("com.android.tools.build:gradle:3.5.3")

    classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}so i get the error : java.lang.NoClassDefFoundError: Could not initialize class org.codehaus.groovy.vmplugin.v7.Java7 at org.codehaus.groovy.vmplugin.VMPluginFactory.(VMPluginFactory.java:43) at org.codehaus.groovy.reflection.GroovyClassValueFactory.(GroovyClassValueFactory.java:35) at org.codehaus.groovy.reflection.ClassInfo.(ClassInfo.java:107) at org.codehaus.groovy.reflection.ReflectionCache.getCachedClass(ReflectionCache.java:95) at org.codehaus.groovy.reflection.ReflectionCache.(ReflectionCache.java:39) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.registerMethods(MetaClassRegistryImpl.java:210) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.(MetaClassRegistryImpl.java:108) at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.(MetaClassRegistryImpl.java:86) at groovy.lang.GroovySystem.(GroovySystem.java:36)
at org.codehaus.groovy.runtime.InvokerHelper.(InvokerHelper.java:86) at groovy.lang.GroovyObjectSupport.getDefaultMetaClass(GroovyObjectSupport.java:59) at groovy.lang.GroovyObjectSupport.(GroovyObjectSupport.java:32) at org.gradle.internal.extensibility.DefaultExtraPropertiesExtension.(DefaultExtraPropertiesExtension.java:29) at org.gradle.internal.extensibility.DefaultConvention.(DefaultConvention.java:49) at org.gradle.internal.extensibility.ExtensibleDynamicObject.(ExtensibleDynamicObject.java:60) etc...`

  • What went wrong: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache

I do not know how to solve that arror.

Could you please provide us your native example that could run at least on the last react native 0.68.1 ?

Productivix avatar May 02 '22 04:05 Productivix

Here it is


    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 if (Os.isFamily(Os.FAMILY_WINDOWS)) {
            // For Android Users, we need to use NDK 23, otherwise the build will
            // fail due to paths longer than the OS limit
            ndkVersion = "23.1.7779620"
        } else {
            // Otherwise we default to the side-by-side NDK version from AGP.
            ndkVersion = "21.4.7075529"
        }
        kotlin_version = '1.5.20' 
        kotlinVersion = '1.5.20'
    }

mlecoq avatar May 02 '22 05:05 mlecoq

hi, still error : `FAILURE: Build failed with an exception.

  • What went wrong: Could not initialize class org.codehaus.groovy.reflection.ReflectionCache ` you should test with a fresh install of last react native 0.68.1

Productivix avatar May 02 '22 18:05 Productivix

@Productivix here is a fresh install with watermelondb

https://github.com/mlecoq/exampleWatermelonDb

mlecoq avatar May 02 '22 19:05 mlecoq

yes @mlecoq , it is compiling , but displays nothing but the react native splash screen...

Productivix avatar May 03 '22 16:05 Productivix

Not in my case, do you have any error on flipper ?

mlecoq avatar May 03 '22 17:05 mlecoq

I will see Flipper , do not know. For the time being. I just type yarn run android and see on the screen the classic RN screen.

Productivix avatar May 04 '22 05:05 Productivix

hi @mlecoq Some libraries like react native screen doesn't support this kotlinversion please fix this problem

razmjoo-dev avatar May 15 '22 12:05 razmjoo-dev

@razmjoo-dev i am currently using watermelondb with "react-native-screens": "^3.13.1" and "kotlinVersion": 1.5.20 and it works fine

mlecoq avatar May 15 '22 13:05 mlecoq

@mlecoq , ok thanks, I had a problem with kotlinversion 1.3.50

razmjoo-dev avatar May 15 '22 13:05 razmjoo-dev

its important to check if your code is compiling withou watermelondb. Try removing it to see if the problem persists. If it does, its problably a different problem from the topic as was happening with me. After I fixed it and back to install watermelondb, the soluction mentioned by mlecoq worked well

johntravolta1 avatar Aug 17 '22 03:08 johntravolta1

Hi sorry, I do not have this project opened to tests by me, and we have jumped to 0.69.4 version of RN - I close my topic without solution.

Productivix avatar Aug 17 '22 04:08 Productivix

For anyone still stuck with the same problem, this can be solved with patch-package by changing the ReactNativeWatermelonDB_kotlinVersion to match your build.gradle version

diff --git a/node_modules/@nozbe/watermelondb/native/android/gradle.properties b/node_modules/@nozbe/watermelondb/native/android/gradle.properties
index b22e447..9afeb77 100644
--- a/node_modules/@nozbe/watermelondb/native/android/gradle.properties
+++ b/node_modules/@nozbe/watermelondb/native/android/gradle.properties
@@ -1,4 +1,4 @@
-ReactNativeWatermelonDB_kotlinVersion=1.3.21
+ReactNativeWatermelonDB_kotlinVersion=1.6.0
 ReactNativeWatermelonDB_compileSdkVersion=28
 ReactNativeWatermelonDB_buildToolsVersion=28.0.3
 ReactNativeWatermelonDB_targetSdkVersion=28

drvn-eb avatar Nov 18 '22 03:11 drvn-eb

Just add your kotlin version

...
buildscript {
    ext {
        ...
        kotlinVersion = "1.6.0" <- add this line folowing your kotlin version
   }
}
...

rizkhal avatar Dec 21 '22 06:12 rizkhal

@mlecoq I am facing the same issue, but I am using managed expo, and I don't have a build.gradle file. How can I solve this?

pSnehanshu avatar Jul 24 '23 18:07 pSnehanshu

@pSnehanshu Watermelondb cannot be used in managed expo app, you should use a dev client and then you could use expo-build-properties plugin to configure kotlinVersion (see https://docs.expo.dev/versions/latest/sdk/build-properties/) - I didn't try it but it should work

mlecoq avatar Jul 24 '23 20:07 mlecoq

Thanks, but I ended up following @drvn-eb's solution of patch-package, and it worked for me.

pSnehanshu avatar Jul 25 '23 07:07 pSnehanshu