rnmapbox / maps

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

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

Closed Stophface closed 3 years ago

Stophface commented 3 years ago

Describe the bug
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.

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

To Reproduce

npx react-native init 
yarn add @react-native-mapbox-gl/maps

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>
    );
  }
}

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' }
    }
}

Expected behavior
I expect the app to compile and start.

Actual behavior
It is not compiling but giving me this error:

AILURE: Build completed with 8 failures.

1: Task failed with an exception.

2: Task failed with an exception.

3: Task failed with an exception.

4: Task failed with an exception.

5: Task failed with an exception.

6: Task failed with an exception.

7: Task failed with an exception.

8: Task failed with an exception.

Versions


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

Bildschirmfoto 2021-08-23 um 11 45 54
Alaa-Ben commented 3 years ago

Hi ! Add the following code to your repositories in build.gradle: Capture d’écran 2021-08-24 à 15 22 07

Stophface commented 3 years ago

@Alaa-Ben Thanks. What is the MAPBOX_DOWNLOAD_TOKEN? The one Access-Token I generate on mapbox.com for a project?

Alaa-Ben commented 3 years ago

You could use that one, or create another. The important thing is that the token must have access to the DOWNLOADS API.

Stophface commented 3 years ago

@Alaa-Ben That is not doing the trick. I get

Could not HEAD 'https://api.mapbox.com/downloads/v2/releases/maven/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom'. Received status code 401 from server: Unauthorized

The token I used has evey box checked (just for the sake of it)... Under credentials it says

            credentials {
                ...
                // Use the secret token you stored in gradle.properties as the password
                password = project.properties[''] ?: ""
            }

Use the secret token you stored in gradle.properties as the password

Where is gradle.properties? It does not sound like I need an access token here...

Alaa-Ben commented 3 years ago

I don't think you're using the token correctly. gradle.properties is a file in your android folder that allows to access properties in your gradle files. If you don't have one, either create one and add you token there. Example:

FLIPPER_VERSION=0.96.1
MAPBOX_DOWNLOADS_TOKEN=MY_TOKEN_KEY
VERSION_CODE=100000
VERSION_NAME =1.0.0
...

then access it with the same name used in this file:

credentials {
                ...
                // Use the secret token you stored in gradle.properties as the password
                password = project.properties[''MAPBOX_DOWNLOADS_TOKEN"] ?: ""
 }

Or just directly put your token in your credentials:

 credentials {
                ...
                // Use the secret token you stored in gradle.properties as the password
                password = "TOKEN_KEY"
 }
Stophface commented 3 years ago

@Alaa-Ben Ah yes, I did not set the token correctly. I used

project.properties[''MAPBOX_DOWNLOADS_TOKEN"] ?: "" eventhough I hardcoded the token into [''MAPBOX_DOWNLOADS_TOKEN"]. I should have used password = "TOKEN_KEY" instead and not referencing project.properties... Now its in gradle.properties and referencing it with project.properties works.

Thank you so much for sticking with me! I still wonder why I have to do this though. The installation guide only mentions this, when I want to install a custom version of Mapbox, which I do not want to do...

Alaa-Ben commented 3 years ago

My pleasure :) I believe that until this repo updates its internal fetching, it is needed to manually tell which maven link to use.

Stophface commented 3 years ago

Alright... Thank you @Alaa-Ben !

liamgarrison commented 3 years ago

Had this problem today, and this fixed it: https://github.com/react-native-mapbox-gl/maps/issues/1572

zajiclib commented 3 years ago

Is there any other possibly working solution? I have almost 2 exact project, but in one there is the error occuring: > Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0. and in the other one the whole solution works perfectly, without any need of tweaking or anything else.

I tried even adding jcenter() (fromm issue #1572), but it did not work at all. I am using Jetpack Compose in both projects.

Platform: [Android]
Platform OS: [Android 11]
Device: [OnePlus 8 Pro]
Emulator/ Simulator: [no]
Dev OS: [Ubuntu 18.04.6 LTS]
Android SDK
ferdicus commented 3 years ago

Is there any other possibly working solution? I have almost 2 exact project, but in one there is the error occuring: > Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0. and in the other one the whole solution works perfectly, without any need of tweaking or anything else.

I tried even adding jcenter() (fromm issue #1572), but it did not work at all. I am using Jetpack Compose in both projects.

Platform: [Android]
Platform OS: [Android 11]
Device: [OnePlus 8 Pro]
Emulator/ Simulator: [no]
Dev OS: [Ubuntu 18.04.6 LTS]
Android SDK

This should solely be an issue of finding the correct repository for the dependencies. jcenter should work - maybe check the order in which you list the repos?

Alaa-Ben commented 3 years ago

Be aware though ! Jcenter is deprecated, so the workaround in the mentioned issue isn't a viable/durable solution. You should tell your app where to fetch the maven assets. Have you tried my solution above ?

ferdicus commented 3 years ago

Be aware though ! Jcenter is deprecated, so the workaround in the mentioned issue isn't a viable/durable solution. You should tell your app where to fetch the maven assets. Have you tried my solution above ?

@Alaa-Ben, jcenter limitations were mentioned in the other issue.

This is a multifaceted issue, as there are various dependencies with many versions that are deposited in different repositories.

Newer dependencies require tokens and are located via url setup on maven, while older are somewhere on mavenCentral while others are still available on jcenter..... 🤯

dddzw commented 6 months ago

You could use that one, or create another. The important thing is that the token must have access to the DOWNLOADS API.

where can i get your TOKEN_KEY.