Skip to content

Android - Error Kotlin #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nppull opened this issue Dec 7, 2023 · 2 comments
Open

Android - Error Kotlin #46

nppull opened this issue Dec 7, 2023 · 2 comments

Comments

@nppull
Copy link

nppull commented Dec 7, 2023

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?

@pierroo
Copy link

pierroo commented Dec 12, 2023

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)

@nppull
Copy link
Author

nppull commented Dec 16, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants