Nozbe / WatermelonDB

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

Does not compile for android using react-native 0.72.4 #1653

Open abhisekmallik opened 1 year ago

abhisekmallik commented 1 year ago

I have followed all the steps mentioned in the installation:

then ran yarn android

FAILURE: Build failed with an exception.

mattjbrill commented 1 year ago

Hi @abhisekmallik!

I'm not a collaborator on this project. I just happened to be looking through issues for something unrelated to yours.

Lot of react native packages are having issues due to the architecture changes, including the upcoming move to AGP 8.0. As of AGP 7.3, which is shipped with react native 0.71+, android projects should start including a namespace. As of AGP 8.0, it is required. Wouldn't you know it, there's no namespace in watermelondb.

I don't know if this will resolve your issue, but try adding

def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
  namespace "com.nozbe.watermelondb"
}

to this line https://github.com/Nozbe/WatermelonDB/blob/0974c47a559fa4f102f0026afb62d0ee368d01ca/native/android/build.gradle#L26

Also you may see a warning about the package name being declared in the android manifest (https://github.com/Nozbe/WatermelonDB/blob/0974c47a559fa4f102f0026afb62d0ee368d01ca/native/android/src/main/AndroidManifest.xml#L2), but you should be able to ignore it for now.

Props to https://github.com/react-native-community/discussions-and-proposals/issues/671#issuecomment-1598892444 for the potential fix!

daamsie commented 1 year ago

I was able to get past this error by specifying the kotlin version in build.gradle

buildscript {
    ext {
        ...
        kotlinVersion = "1.8.22"
    }
    ...
}
xkelxmc commented 11 months ago

same problem with kotlinVersion 1.8.10, 1.8.22, 1.9.0

edwinwong90 commented 10 months ago

@xkelxmc you need to check the react native gradle's version to specific dedicated kotlinVersion. Please refer here. To check your gradle version, go to android/gradle/wrapper/gradle-wrapper.properties in the file you will see this line

distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip

Which mean the gradle version is 8.0.1. and use the correct kotlin version based on the link I mentioned. Hope this help!

mimeyn commented 6 months ago

I was able to get past this error by specifying the kotlin version in build.gradle

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

This solution worked for me. Thanks a lot daamsie.

As a side note (Honestly at first I was a little confused🤦‍♂️):

Add this lines to android/build.gradle✅, not adding to android/app/build.gradle