rnmapbox / maps

A Mapbox react native module for creating custom maps
MIT License
2.27k stars 849 forks source link

Android New Architecture Build Issues #3511

Closed connorpmullins closed 5 months ago

connorpmullins commented 5 months ago

Environment

Steps to reproduce

Set up a bare-bones react native app with the following package.json:

{
  "name": "RNNavionicsTestApp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "lint": "eslint .",
    "start": "react-native start",
    "test": "jest",
    "postinstall": "patch-package"
  },
  "dependencies": {
    "@rnmapbox/maps": "10.1.24",
    "patch-package": "^8.0.0",
    "react": "18.2.0",
    "react-native": "0.73.6",
  },
  "devDependencies": {
    "@babel/core": "^7.20.0",
    "@babel/preset-env": "^7.20.0",
    "@babel/runtime": "^7.20.0",
    "@react-native/babel-preset": "0.73.21",
    "@react-native/eslint-config": "0.73.2",
    "@react-native/metro-config": "0.73.5",
    "@react-native/typescript-config": "0.73.1",
    "@types/react": "^18.2.6",
    "@types/react-test-renderer": "^18.0.0",
    "babel-jest": "^29.6.3",
    "eslint": "^8.19.0",
    "jest": "^29.6.3",
    "prettier": "2.8.8",
    "react-test-renderer": "18.2.0",
    "typescript": "5.0.4"
  },
  "engines": {
    "node": ">=18"
  }
}

Then attempt to build Android using the new architecture and mapbox v11. After doing that, I receive the following build errors:

> Task :rnmapbox_maps:compileDebugKotlin
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationModule.kt:12:1 Class 'RNMBXPointAnnotationModule' is not abstract and does not implement abstract base class member public abstract fun refresh(viewRef: Double?, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXPointAnnotationModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationModule.kt:28:5 'refresh' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCameraModule.kt:16:1 Class 'RNMBXCameraModule' is not abstract and does not implement abstract base class member public abstract fun updateCameraStop(viewRef: Double?, stop: ReadableMap!, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXCameraModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXCameraModule.kt:46:5 'updateCameraStop' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXViewportModule.kt:14:1 Class 'RNMBXViewportModule' is not abstract and does not implement abstract base class member public abstract fun getState(viewRef: Double?, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXViewportModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXViewportModule.kt:40:5 'getState' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXViewportModule.kt:46:5 'transitionTo' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/camera/RNMBXViewportModule.kt:57:5 'idle' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/images/RNMBXImageModule.kt:12:1 Class 'RNMBXImageModule' is not abstract and does not implement abstract base class member public abstract fun refresh(viewRef: Double?, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXImageModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/images/RNMBXImageModule.kt:28:5 'refresh' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:16:1 Class 'NativeMapViewModule' is not abstract and does not implement abstract base class member public abstract fun takeSnap(viewRef: Double?, writeToDisk: Boolean, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeMapViewModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:42:5 'takeSnap' overrides nothing

e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:48:5 'queryTerrainElevation' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:58:5 'setSourceVisibility' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:72:5 'getCenter' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:78:5 'getCoordinateFromView' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:88:5 'getPointInView' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:94:5 'getZoom' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:100:5 'getVisibleBounds' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:106:5 'queryRenderedFeaturesAtPoint' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:125:5 'queryRenderedFeaturesInRect' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:144:5 'setHandledMapChangedEvents' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:155:5 'clearData' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/mapview/NativeMapViewModule.kt:161:5 'querySourceFeatures' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSourceModule.kt:16:1 Class 'RNMBXShapeSourceModule' is not abstract and does not implement abstract base class member public abstract fun getClusterExpansionZoom(viewRef: Double?, featureJSON: String!, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXShapeSourceModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSourceModule.kt:33:5 'getClusterExpansionZoom' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSourceModule.kt:44:5 'getClusterLeaves' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/styles/sources/RNMBXShapeSourceModule.kt:57:5 'getClusterChildren' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.kt:147:1 Class 'RNMBXChangeLineOffsetsShapeAnimatorModule' is not abstract and does not implement abstract base class member public abstract fun create(tag: Double, coordinates: ReadableArray!, startOffset: Double, endOffset: Double, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXChangeLineOffsetsShapeAnimatorModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.kt:156:5 'create' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.kt:180:5 'setLineString' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.kt:195:5 'setStartOffset' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXChangeLineOffsetsShapeAnimatorModule.kt:201:5 'setEndOffset' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXMovePointShapeAnimatorModule.kt:71:1 Class 'RNMBXMovePointShapeAnimatorModule' is not abstract and does not implement abstract base class member public abstract fun create(tag: Double, coordinate: ReadableArray!, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXMovePointShapeAnimatorModuleSpec
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXMovePointShapeAnimatorModule.kt:81:5 'create' overrides nothing
e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/shapeAnimators/RNMBXMovePointShapeAnimatorModule.kt:95:5 'moveTo' overrides nothing

> Task :rnmapbox_maps:compileDebugKotlin FAILED

@mfazekas - I have pushed the code required to replicate this to the v11Sandbox branch of our shared repository if you are interested in easily replicating the issue. I believe it's generalizable beyond our repo.

Worth noting: this issue does NOT exist in version 10.1.19. I can't downgrade to 10.1.19, however, as iOS newArch apps have build issues with v11 on that release.

connorpmullins commented 5 months ago

Update to this - I receive the same error even when not overriding a mapbox version.

mfazekas commented 5 months ago

@connorpmullins looking at first error:

e: file:///Users/connormullins/Code/Omnia/NavionicsMapboxTest/node_modules/@rnmapbox/maps/android/src/main/java/com/rnmapbox/rnmbx/components/annotation/RNMBXPointAnnotationModule.kt:12:1 Class 'RNMBXPointAnnotationModule' is not abstract and does not implement abstract base class member public abstract fun refresh(viewRef: Double?, promise: Promise!): Unit defined in com.rnmapbox.rnmbx.NativeRNMBXPointAnnotationModuleSpec

We do have

    @ReactMethod
    override fun refresh(viewRef: ViewRefTag?, promise: Promise) {

in RNMBXPointAnnotationModule.kt

and there is the generated

   @ReactMethod
  @DoNotStrip
  public abstract void refresh(@Nullable Integer viewRef, Promise promise);

in NativeRNMBXPointAnnotationModuleSpec.java.

So looks like the kotlin and java definition doesn't match. Might be a compiler version or kotlin settings issue.

mfazekas commented 5 months ago

Can you check your ? NativeRNMBXPointAnnotationModuleSpec.java ?

https://github.com/rnmapbox/maps/blob/7d72addf3063813e5a896d7f7c6237bb19da73a3/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXPointAnnotationModuleSpec.java#L37-L39

Seems like it's related to https://github.com/rnmapbox/maps/pull/3527

connorpmullins commented 5 months ago

Hey Miklós - here's my NativeRNMBXPointAnnotationModuleSpec.java (after upgrading to 10.1.27):


/**
 * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
 *
 * Do not edit this file as changes may cause incorrect behavior and will be lost
 * once the code is regenerated.
 *
 * @generated by codegen project: GenerateModuleJavaSpec.js
 *
 * @nolint
 */

package com.rnmapbox.rnmbx;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

public abstract class NativeRNMBXPointAnnotationModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
  public static final String NAME = "RNMBXPointAnnotationModule";

  public NativeRNMBXPointAnnotationModuleSpec(ReactApplicationContext reactContext) {
    super(reactContext);
  }

  @Override
  public @Nonnull String getName() {
    return NAME;
  }

  @ReactMethod
  @DoNotStrip
  public abstract void refresh(@Nullable Double viewRef, Promise promise);
}

The issue is still occurring on the most recent release

mfazekas commented 5 months ago

@connorpmullins interesting, what is your react-native release?

Also are you running autogenerate? How come the module spec NativeRNMBXPointAnnotationModuleSpec.java is different than in our source code?

connorpmullins commented 5 months ago

0.73.6!

And how can I check if I'm running auto-generate? Sorry to not be of more help, but I'm not sure why the module spec is different.

I've wiped and re-installed node modules, cleaned android, attempted to match our app (and our shared sandbox app) to the react native docs, and am still getting the above.

mfazekas commented 5 months ago

@connorpmullins sorry I cannot help. In our repo we have

https://github.com/rnmapbox/maps/blob/32b7ce4488870eb122a0245169026eaa3816f59c/android/src/main/old-arch/com/rnmapbox/rnmbx/NativeRNMBXPointAnnotationModuleSpec.java#L37-L40

in your fork you have

- public abstract void refresh(@Nullable Integer viewRef, Promise promise);
+ public abstract void refresh(@Nullable Double viewRef, Promise promise);

Ok I see.

This is old version of our code, the latest version of our code supports only RN 0.74 in the new arch.

So either you use our code before https://github.com/rnmapbox/maps/releases/tag/v10.1.21 with RN 0.73 on new arch. Or upgrade to RN 0.74 and use the latest version of our code.

IASV commented 5 months ago

Hello @mfazekas, I have the error with the updateCameraStop, it appears only when I activate the new architecture.

updateCameraStop

Error: Exception in HostFunction: no non-static method "Lcom/rnmapbox/rnmbx/components/camera/RNMBXCameraModule;.updateCameraStop(Ljava/lang/Double;Lcom/facebook/react/bridge/ReadableMap;Lcom/facebook/react/bridge/Promise;)V"

package

"@rnmapbox/maps": "10.1.27", "react": "18.2.0", "react-native": "0.74.2",

node_modules - RNMBXCameraModule.kt

package com.rnmapbox.rnmbx.components.camera

import com.facebook.react.bridge.Callback
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReadableArray
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.bridge.WritableMap
import com.facebook.react.bridge.WritableNativeMap
import com.rnmapbox.rnmbx.NativeRNMBXCameraModuleSpec
import com.rnmapbox.rnmbx.components.mapview.CommandResponse
import com.rnmapbox.rnmbx.utils.ViewTagResolver

class RNMBXCameraModule(context: ReactApplicationContext, val viewTagResolver: ViewTagResolver) : NativeRNMBXCameraModuleSpec(context) {
    private fun withViewportOnUIThread(
        viewRef: Double?,
        reject: Promise,
        fn: (RNMBXCamera) -> Unit
    ) {
        if (viewRef == null) {
            reject.reject(Exception("viewRef is null"))
        } else {
            viewTagResolver.withViewResolved(viewRef.toInt(), reject, fn)
        }
    }

    private fun createCommandResponse(promise: Promise): CommandResponse = object : CommandResponse {
        override fun success(builder: (WritableMap) -> Unit) {
            val payload: WritableMap = WritableNativeMap()
            builder(payload)

            promise.resolve(payload)
        }

        override fun error(message: String) {
            promise.reject(Exception(message))
        }
    }

    companion object {
      const val NAME = "RNMBXCameraModule"
    }

    override fun updateCameraStop(viewRef: Double?, stop: ReadableMap, promise: Promise) {
        withViewportOnUIThread(viewRef, promise) {
            it.updateCameraStop(stop)
            promise.resolve(null)
        }
    }
}
mfazekas commented 5 months ago

@IASV that's sounds like another issue - see #3522

gioimtg2003 commented 4 months ago

i tried modify in android\gradle.properties

newArchEnabled=false

and it worked