android - Mapbox SDK for android 安装不正确
问题描述
我是编程新手,我想创建一个地图应用程序,所以我试图在 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"
/>
一切都显示为红色,表示“在项目或库中找不到布局文件中的类”
解决方案
推荐阅读
- php - 如何在部署中管理 Laravel 队列?
- javascript - 如何处理不在 DOM 中的“queryselected”元素
- javascript - 如何将此json转换为这样的数组?
- javascript - 检查 componentDidMount 中的所有 setState 方法是否完成
- android - 在片段 Val 中使用 RecycleView 无法重新分配问题
- closedxml - 在 ClosedXML (SetAutoFilter) 中应用多个过滤器
- javascript - 为什么使用 NPM 比在 MVC 项目中包含 JavaScript 库更好?
- nim-lang - 如何在 Nim 中将字符转换为 ASCII 码,反之亦然
- python - 操作 3 维 numpy 数组中的值
- elasticsearch - 如何在弹性搜索中的 Rest 高级客户端中传递 json 查询