Skip to content
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

8.4.0 broke Android build with custom version of the Mapbox SDK #1601

Closed
doomsower opened this issue Oct 31, 2021 · 12 comments
Closed

8.4.0 broke Android build with custom version of the Mapbox SDK #1601

doomsower opened this issue Oct 31, 2021 · 12 comments

Comments

@doomsower
Copy link
Contributor

Describe the bug

I have customized app/build.gradle as described here in android installation guide to use latest version of native sdk:

implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.7.0'
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.8.0'
implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.9.0'

Expected behavior

My app was building and running fine with version 8.3.0, so I expected it continue working after upgrade to 8.4.0

Actual behavior

I'm getting build error:

Duplicate class com.mapbox.android.telemetry.AlarmReceiver found in modules jetified-mapbox-android-telemetry-6.1.0-runtime (com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0) and jetified-mapbox-android-telemetry-okhttp3-8.1.0-runtime (com.mapbox.mapboxsdk:mapbox-android-telemetry-okhttp3:8.1.0)

It seems that #1550 affects breaks versions, so I had to monkey-patch to remove mapbox-android-telemetry-6.1.0 from react-native-mapbox-gl/maps dependencies as a workaround

Versions (please complete the following information):

  • Platform: Android
  • Dev OS: OSX 11.5.1
  • react-native-mapbox-gl Version 8.4.0
  • Mapbox GL version 9.7.0
  • React Native Version 0.66.1
@ferdicus
Copy link
Member

ferdicus commented Nov 3, 2021

hi @doomsower, thanks for bringing this to our attention 🙇🏿

Can you clarify against which Android version you're building.
Also, just to clarify - this does build totally fine with react-native-mapbox-gl/maps 8.3.0?

Cheers 🍻

@doomsower
Copy link
Contributor Author

doomsower commented Nov 3, 2021

@ferdicus Here's my app/build.gradle:

buildscript {
    ext {
        ndkVersion = "21.4.7075529"
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        supportLibVersion = "28.0.0"
        kotlinVersion = "1.5.21"
        appCompatVersion = "1.3.1"
        swiperefreshlayoutVersion = "1.1.0"
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.2")
        classpath 'com.google.gms:google-services:4.3.10'
        classpath 'com.getkeepsafe.dexcount:dexcount-gradle-plugin:1.0.3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

And it worked with 8.3.0

@ferdicus
Copy link
Member

ferdicus commented Nov 3, 2021

@doomsower, can you also please post your <PROJECT>/android/app/build.gradle dependencies?
<PROJECT>/android/build.gradle is also helpful though, thanks 🙇🏿

@doomsower
Copy link
Contributor Author

Here they are:

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    //noinspection GradleDynamicVersion
    implementation "com.facebook.react:react-native:+"  // From node_modules
    debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}") {
      exclude group:'com.facebook.fbjni'
    }
    debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
        exclude group:'com.squareup.okhttp3', module:'okhttp'
    }
    debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}") {
        exclude group:'com.facebook.flipper'
    }
    // Require by detox
    androidTestImplementation('com.wix:detox:+') { transitive = true }
    androidTestImplementation 'junit:junit:4.12'
    // Required by react-navigation
    implementation("androidx.appcompat:appcompat:${rootProject.ext.appCompatVersion}")
    implementation("androidx.swiperefreshlayout:swiperefreshlayout:${rootProject.ext.swiperefreshlayoutVersion}")
    // Required by mapbox
    // https://github.com/react-native-mapbox-gl/maps/blob/master/android/install.md#mapbox-maps-sdk
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.7.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.8.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.9.0'

    if (enableHermes) {
      def hermesPath = "../../node_modules/hermes-engine/android/";
      debugImplementation files(hermesPath + "hermes-debug.aar")
      debugDetoxImplementation files(hermesPath + "hermes-debug.aar")
      releaseImplementation files(hermesPath + "hermes-release.aar")
      releaseStagingImplementation files(hermesPath + "hermes-release.aar")
    } else {
      implementation jscFlavor
    }
}

@ferdicus
Copy link
Member

ferdicus commented Nov 4, 2021

Thanks 🙇🏿
I'll try to recreate this when I find the time the coming days 👍🏿

@mfazekas
Copy link
Contributor

mfazekas commented Nov 4, 2021

BTW one should be able to use the customisation points made for MapLibre, to change all the mapbox related libs, it can be used for different mabox version as well as for maplibre

https://github.com/react-native-mapbox-gl/maps/blob/master/android/install.md#using-maplibre

@ferdicus
Copy link
Member

ferdicus commented Nov 4, 2021

ah, yes - we should probably point that our more prominently in the guide

@ferdicus
Copy link
Member

I can verify this issue @doomsower - looking into a solution

@ferdicus
Copy link
Member

hmm, I can't seem to get rid of the duplicate class issue 😕

Things I tried:
excluding the older telemetry dependency

    implementation ('com.mapbox.mapboxsdk:mapbox-android-sdk:9.7.1') {
        exclude group: 'com.mapbox.mapboxsdk', module: 'mapbox-android-telemetry'
    }

resolution strategy

configurations.all {
    resolutionStrategy {
        force 'com.mapbox.mapboxsdk:mapbox-android-telemetry-okhttp3:8.1.0'
    }
}

your hunch is right @doomsower, when I remove the dependency com.mapbox.mapboxsdk:mapbox-android-telemetry:6.1.0 that got introduced with https://github.com/react-native-mapbox-gl/maps/pull/1550 it builds just fine.

I've seen, that with release 9.6.2 mapbox introduced:

Update telemetry to 8.1.0 (okhttp3 variant) and events-core 5.0.0 to make project compatible with Android 12

@mfazekas, any ideas for this?

@ferdicus
Copy link
Member

@doomsower , I was able to build without the mentioned error with this solution:

Add this block to android/build.gradle

        rnmbglMapboxLibs = {
            implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.7.1'
            implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.8.0'
            implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0'
        }

This will overwrite our packages dependencies here:
https://github.com/react-native-mapbox-gl/maps/blob/79e82e0093c894972bbcfa27988803f26369e4a6/android/rctmgl/build.gradle#L55-L60

Notice I used 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0' instead of 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.9.0' because that was throwing some other error (go figure....)

android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java:510: error: <anonymous com.mapbox.rctmgl.components.mapview.RCTMGLMapView$6> is not abstract and does not override abstract method onAnnotationClick(com.mapbox.mapboxsdk.plugins.annotation.Symbol) in com.mapbox.mapboxsdk.plugins.annotation.OnAnnotationClickListener
        symbolManager.addClickListener(new OnSymbolClickListener() {
                                                                   ^
android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java:512: error: onAnnotationClick(com.mapbox.mapboxsdk.plugins.annotation.Symbol) in <anonymous com.mapbox.rctmgl.components.mapview.RCTMGLMapView$6> cannot implement onAnnotationClick(T) in com.mapbox.mapboxsdk.plugins.annotation.OnAnnotationClickListener
            public void onAnnotationClick(Symbol symbol) {
                        ^
  return type void is not compatible with boolean
android/rctmgl/src/main/java/com/mapbox/rctmgl/components/mapview/RCTMGLMapView.java:511: error: method does not override or implement a method from a supertype
            @Override

Also notice, that you're still using most of the default plugins, I've not checked those with updated versions:
https://github.com/react-native-mapbox-gl/maps/blob/79e82e0093c894972bbcfa27988803f26369e4a6/android/rctmgl/build.gradle#L71-L76

You can also overwrite/ disable them with the same approach as above, instead rnmbglMapboxLibs just use rnmbglMapboxPlugins for the block.

So in essence, using the method Miklós mentioned 😅

Can you please try and report back, would be swell - thanks in advance 🙇🏿

@doomsower
Copy link
Contributor Author

@ferdicus I've deleted my patch and also deleted all mapbox references from android/app/build.gradle. Then I modified my android/build.gradle as following:

buildscript {
    ext {
        ndkVersion = "21.4.7075529"
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        supportLibVersion = "28.0.0"
        kotlinVersion = "1.5.21"
        appCompatVersion = "1.3.1"
        swiperefreshlayoutVersion = "1.1.0"

        // Required by mapbox
        // https://github.com/react-native-mapbox-gl/maps/blob/master/android/install.md#mapbox-maps-sdk
        rnmbglMapboxLibs = {
            implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.7.1'
            implementation 'com.mapbox.mapboxsdk:mapbox-sdk-services:5.8.0'
        }
        rnmbglMapboxPlugins = {
            implementation "com.mapbox.mapboxsdk:mapbox-android-gestures:0.7.0"
            implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-localization-v9:0.14.0"
            implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.8.0"
            implementation "com.mapbox.mapboxsdk:mapbox-android-plugin-markerview-v9:0.4.0"
            implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:5.8.0'
        }
    }
...

Seems to be working in both dev and prod builds. Dependency tree contains only one version of telemetry lib, com.mapbox.mapboxsdk:mapbox-android-telemetry-okhttp3:8.1.0. Also I had the same errors with com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v9:0.9.0

I think I tried this approach originally, but it was not clear to me what goes into rnmbglMapboxLibs and what goes into rnmbglMapboxPlugins. For example, mapbox-android-plugin-annotation in the orginal build.gradle is not in plugins. And plugins like markerview and annotation seems to be required for react-native-mapbox-gl to work. It all ends up in dependencies tree anyway, but I think it requires more clear documentation.

@ferdicus
Copy link
Member

yeah, agreed it's a bit opaque.
However, I think this feature was mainly meant as support for MapLibre, it can also be used to independently update mapbox.

Closing this ticket and gonna update the docs a bit.

Thanks for your patience and support on this @doomsower 🙇🏿

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

3 participants