【问题标题】:Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0. on fresh installation of MapBox找不到 com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0。关于 MapBox 的全新安装
【发布时间】:2021-10-26 05:59:51
【问题描述】:

我建立了一个新的 react-native 项目并添加了带有 yarn add @react-native-mapbox-gl/maps 的 Mapbox。

这个

请注意,如果您使用的是默认 Mapbox Android SDK(包含在此库中) 并且在较新的 Android 操作系统版本(API 30+)上, 你会遇到致命异常:java.lang.SecurityException: getDataNetworkTypeForSubscriber。

据我了解不适用,因为我的目标是 Android 上的 API 29。另外,这不是我遇到的错误。

我添加了提供的演示代码

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

并在 Android 上启动应用程序。我收到以下错误:

找不到 com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0。 要求: 项目:react-native-mapbox-gl_maps > com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0 在 build.gradle 文件中搜索

这是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:构建完成,失败了 8 次。

1: 任务因异常而失败。

  • 出了什么问题: 任务“:app:mergeDebugAssets”执行失败。

无法解析配置“:app:debugRuntimeClasspath”的所有文件。 找不到 com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0。 在以下位置搜索: - https://repo.maven.apache.org/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom - 文件:/Users/macosx/.m2/repository/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom - 文件:/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。绒球 - 文件:/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。绒球 - 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 要求: 项目:app > 项目:react-native-mapbox-gl_maps > com.mapbox.mapboxsdk:mapbox-android-sdk:9.1.0

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。 ==================================================== ==============================

当我点击提供的链接时 https://repo.maven.apache.org/maven2/com/mapbox/mapboxsdk/mapbox-android-accounts/0.7.0/mapbox-android-accounts-0.7.0.pom

我得到一个 404...

【问题讨论】:

    标签: android react-native mapbox mapbox-gl-js


    【解决方案1】:

    我不知道为什么(可能是因为react-native-mapbox-gl 正在更新),this 需要添加到您的代码中:

    allprojects/repositories 部分下将以下内容添加到您的android/build.gradle

        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'] ?: ""
            }
        }
    

    从这里得到这个提示https://github.com/react-native-mapbox-gl/maps/issues/1501#issuecomment-906158991

    【讨论】:

    • 您有没有想出其他解决方案?因为我有 2 个非常相似的项目,在其中一个项目中这个解决方案可以无缝运行,但在另一个项目中,错误 Could not find com.mapbox.mapboxsdk:mapbox-android-accounts:0.7.0. 仍然存在持续存在并将 jcenter() 添加到项目 gradle 文件中根本没有帮助。
    • @Rickertbrandsen 我在答案中发布的内容帮助了我。
    • @Stohpface 很不幸,我真的很绝望,即使来自官方 github 存储库也没有任何帮助。
    • @Rickertbrandsen 很抱歉,我无法进一步帮助您。欢迎来到react-native 的精彩世界...尝试在android/build.gradle 中加入usernamepassword
    • @Stohpface 好吧,老实说,我来自 android native 开发(Kotlin),但对于 gradle,它与 android native 完全相同。这些是我实际尝试过的事情。但感谢您的努力。
    猜你喜欢
    • 2022-07-06
    • 2023-04-03
    • 1970-01-01
    • 2021-12-04
    • 2020-10-04
    • 1970-01-01
    • 2022-12-10
    • 2014-03-18
    • 1970-01-01
    相关资源
    最近更新 更多