four-eyes
four-eyes

Reputation: 12385

Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0. on fresh installation of MapBox

I set up a fresh react-native project and added Mapbox with yarn add @react-native-mapbox-gl/maps.

This

Notice, that if you're using the default Mapbox Android SDK (which is packed in with this lib) and are on newer Android OS version (API 30+), you'll encounter Fatal Exception: java.lang.SecurityException: getDataNetworkTypeForSubscriber.

is not applicable as far as I understand, because I am aiming at API 29 on Android. Plus, it is not the error I am getting.

I added the democode provided

import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import MapboxGL from '@react-native-mapbox-gl/maps';

MapboxGL.setAccessToken('<YOUR_ACCESSTOKEN>');

const styles = StyleSheet.create({
  page: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  container: {
    height: 300,
    width: 300,
    backgroundColor: 'tomato'
  },
  map: {
    flex: 1
  }
});

export default class App extends Component {
  render() {
    return (
      <View style={styles.page}>
        <View style={styles.container}>
          <MapboxGL.MapView style={styles.map} />
        </View>
      </View>
    );
  }
}

and started the App on Android. I get the following this error:

Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0. Required by: project :react-native-mapbox-gl_maps > com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0 Search in build.gradle files

This is app/android/build.gradle

buildscript {
    ext {
        buildToolsVersion = "30.0.2"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29
        ndkVersion = "20.1.5948944"
    }
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath("com.android.tools.build:gradle:4.2.1")
    }
}

allprojects {
    repositories {
        mavenCentral()
        mavenLocal()
        maven {
            url("$rootDir/../node_modules/react-native/android")
        }
        maven {
            url("$rootDir/../node_modules/jsc-android/dist")
        }

        google()
        maven { url 'https://www.jitpack.io' }
    }
}

FAILURE: Build completed with 8 failures.

1: Task failed with an exception.

Could not resolve all files for configuration ':app:debugRuntimeClasspath'. Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0. Searched in the following locations: - https://repo.maven.apache.org/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom - file:/Users/macosx/.m2/repository/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom - file:/Users/macosx/Documents/mapstar-current/MapStar/node_modules/react-native/android/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom - file:/Users/macosx/Documents/mapstar-current/MapStar/node_modules/jsc-android/dist/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom - https://dl.google.com/dl/android/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom - https://www.jitpack.io/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom Required by: project :app > project :react-native-mapbox-gl_maps > com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0

When I click on the link provided https://repo.maven.apache.org/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom

I get a 404...

404

Upvotes: 5

Views: 9757

Answers (2)

David Corbitt
David Corbitt

Reputation: 119

Adding this line in my app/build.gradle file and rebuilding solved the problem for me:

allprojects {
    repositories {
        ...
        jcenter()
    }
}

Upvotes: 2

four-eyes
four-eyes

Reputation: 12385

I am not sure why (maybe because react-native-mapbox-gl is being updated), this needs to be added to your code:

Add the following to your android/build.gradle under section allprojects/repositories

    maven {
        url 'https://api.mapbox.com/downloads/v2/releases/maven'
        authentication {
            basic(BasicAuthentication)
        }
        credentials {
            // Do not change the username below.
            // This should always be `mapbox` (not your username). 
            username = 'mapbox'
            // Use the secret token you stored in gradle.properties as the password
            password = project.properties['MAPBOX_DOWNLOADS_TOKEN'] ?: ""
        }
    }

Got this hint from here https://github.com/react-native-mapbox-gl/maps/issues/1501#issuecomment-906158991

Upvotes: 7

Related Questions