react-native-geocoder-reborn icon indicating copy to clipboard operation
react-native-geocoder-reborn copied to clipboard

Android - Error Kotlin

Open nppull opened this issue 1 year ago • 2 comments
trafficstars

FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':timwangdev_react-native-geocoder'.
> Failed to notify project evaluation listener.
   > Could not create task ':timwangdev_react-native-geocoder:compileDebugAndroidTestKotlin'.
      > Cannot use @TaskAction annotation on method AbstractKotlinCompile.execute() because interface org.gradle.api.tasks.incremental.IncrementalTaskInputs is not a valid parameter to an action method.
   > KotlinJvmAndroidCompilation with name 'debugAndroidTest' not found.

buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 distributionUrl=https://services.gradle.org/distributions/gradle-8.0.1-all.zip Kotlin: 1.8.0

React native: 0.72.7 @timwangdev/react-native-geocoder: 1.0.0-alpha.7

Anyone have the solution to this?

nppull avatar Dec 07 '23 14:12 nppull

Well; suddenly facing the exact same issue, which is weird since it had been working fine for the past 2 years. Did you manage to fix this @nppull ?

I'm starting to think I actually had found the fix years ago (you also commented on my old post) I have a patch package that is supposed to fix it; but for some reason it feels kind of corrupted now

might be something along those lines; let me know if that helps:

import android.location.Address;
 import android.location.Geocoder;
+import android.os.Build
 
 import com.facebook.react.bridge.ReactApplicationContext
 import com.facebook.react.bridge.ReactContextBaseJavaModule
@@ -28,10 +29,12 @@ class GeocoderModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
       config.getMap("bounds")
     } else null
 
-    val swLat = bounds?.getDouble("swLat")
-    val swLng = bounds?.getDouble("swLng")
-    val neLat = bounds?.getDouble("neLat")
-    val neLng = bounds?.getDouble("neLng")
+    val sw: ReadableMap? = bounds?.getMap("sw")
+    val ne: ReadableMap? = bounds?.getMap("ne")
+    val swLat = sw?.getDouble("lat")
+    val swLng = sw?.getDouble("lng")
+    val neLat = ne?.getDouble("lat")
+    val neLng = ne?.getDouble("lng")
     val localeStr = if (config.hasKey("locale")) config.getString("locale") else null
 
     if (localeStr != null && !locale.equals(Locale(localeStr))) {
@@ -41,16 +44,39 @@ class GeocoderModule(reactContext: ReactApplicationContext) : ReactContextBaseJa
     var maxResults = if (config.hasKey("maxResults")) config.getInt("maxResults") else -1
     if (maxResults <= 0) maxResults = 5
     try {
-      val addresses: MutableList<Address>
-      if (swLat != null && swLng != null && neLat != null && neLng != null) {
-        addresses = geocoder.getFromLocationName(addressName, maxResults, swLat, swLng, neLat, neLng)
-      } else {
-        addresses = geocoder.getFromLocationName(addressName, maxResults)
-      }
-      if (addresses != null && addresses.size > 0) {
-        promise.resolve(transform(addresses))
+      if (Build.VERSION.SDK_INT >= 33) {
+        if (swLat != null && swLng != null && neLat != null && neLng != null) {
+          geocoder.getFromLocationName(addressName, maxResults, swLat, swLng, neLat, neLng) {addresses ->
+            if (addresses.size > 0) {
+              promise.resolve(transform(addresses))
+            } else {
+              promise.reject("EMPTY_RESULT", "Geocoder returned an empty list.")
+            }
+          }
+        } else {
+          geocoder.getFromLocationName(addressName, maxResults) {addresses ->
+            if (addresses.size > 0) {
+              promise.resolve(transform(addresses))
+            } else {
+              promise.reject("EMPTY_RESULT", "Geocoder returned an empty list.")
+            }
+          }
+        }
+
+
       } else {
-        promise.reject("EMPTY_RESULT", "Geocoder returned an empty list.")
+        val addresses: MutableList<Address>?
+        if (swLat != null && swLng != null && neLat != null && neLng != null) {
+          addresses = geocoder.getFromLocationName(addressName, maxResults, swLat, swLng, neLat, neLng)
+        } else {
+          addresses = geocoder.getFromLocationName(addressName, maxResults)
+        }
+
+        if (addresses != null && addresses.size > 0) {
+          promise.resolve(transform(addresses))
+        } else {
+          promise.reject("EMPTY_RESULT", "Geocoder returned an empty list.")
+        }
       }
     } catch (e: Exception) {
       promise.reject("NATIVE_ERROR", e)

pierroo avatar Dec 12 '23 11:12 pierroo

@pierroo Thank you for your reply.

I found solution.

I have updated ../node_modules/@timwangdev/react-native-geocoder/android/build.gradle

buildscript {
  // Buildscript is evaluated before everything else so we can't use getExtOrDefault
  def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['Geocoder_kotlinVersion']

to

 buildscript {
   // Buildscript is evaluated before everything else so we can't use getExtOrDefault
   def kotlin_version = '1.8.0'
 

and worked for me.

nppull avatar Dec 16 '23 04:12 nppull