【问题标题】:Mapbox SDK for android doesn't install properlyMapbox SDK for android 安装不正确
【发布时间】:2021-04-14 01:23:56
【问题描述】:

我是编程新手,我想创建一个地图应用程序,所以我正在尝试在 android studio (Kotlin) 中安装 Mapbox SDK,我已逐步按照安装指南进行操作 (https://docs.mapbox.com/android/maps/guides/install/) ,但它没有导入,也没有创建类,我不知道出了什么问题。

构建 gradle(项目)

buildscript {
    ext.kotlin_version = "1.4.30"
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        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'] ?: ""
            }
        }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

构建 gradle(模块)

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 29
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.maptest04"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:9.6.1'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

在我放置导入的主要活动中,单词 mapbox 显示为红色,并且单词 Mapview、Mapbox 和 Style 在“类 MainActivity”中显示为红色

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.mapboxsdk.Mapbox
import com.mapbox.mapboxsdk.maps.Style

class MainActivity : AppCompatActivity() {
    
    private var mapView: MapView? = null
    
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        
        Mapbox.getInstance(this, getString(R.string.mapbox_access_token))
        
        setContentView(R.layout.activity_main)
       
        mapView = findViewById(R.id.mapView)
        mapView.onCreate(savedInstanceState)
        mapView.getMapAsync { mapboxMap ->

            mapboxMap.setStyle(Style.MAPBOX_STREETS) {

            }     
      }
  }

当我把它放在 XML 中

<com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

一切都显示为红色,表示“在项目或库中未找到布局文件中的类”

【问题讨论】:

    标签: android kotlin mapbox mapbox-android


    【解决方案1】:

    那么您是否在 gradle 主目录的 gradle.properties 中配置了下载令牌。如果您使用 Mac,该文件应位于 /Users/you/.gradle/gradle.properties。 对于 Windows,它应位于 C:\Users。 gradle\gradle.properties。

    【讨论】:

    • 嗨,谢谢你的回答,我把秘密令牌放在了 android studio 内的 Gradle Scrips > gradle.properties 中,但我认为我必须安装 Gradle 我把秘密令牌放在那个地方你说的。
    【解决方案2】:

    问题显然是 SDK 版本,由于某种原因,实际的 SDK 没有运行,所以我使用较旧的 SDK 版本进行了确切的安装过程,并且工作正常。

    【讨论】:

      猜你喜欢
      • 2022-07-13
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 2015-03-06
      • 2023-03-20
      相关资源
      最近更新 更多