什么导致了“错误:未找到mapbox_styleUrl属性”?

3
当我试图将 Mapbox 导航 SDK 应用到我的项目中时,一直出现“找不到属性 mapbox_styleUrl”的错误。 我想这可能与 Map SDK 迁移到 7.0.0 版本有关,他们删除了 mapbox_styleUrl XML 属性,但我无法找到解决方法。 我代码中没有使用 styleUrl。我保留了地图布局的默认样式,并在 onMapReady 中设置它。 以下是完整的错误信息:
Android resource linking failed
Output:  C:\Users\Jonas\.gradle\caches\transforms-1\files-1.1\mapbox-android-navigation-ui-0.26.0.aar\0ea5c6919c35d65de36f46fe7fce49d7\res\layout\navigation_view_layout.xml:10: error: attribute mapbox_styleUrl (aka com.fishdev.planmyrun:mapbox_styleUrl) not found.
error: failed linking file resources.

完整的build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.fishdev.planmyrun"
        minSdkVersion 24
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

    //  Mapbox dependencies
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:7.0.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-plugin-annotation-v7:0.4.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.26.0'

我的布局中的MapView:

<com.mapbox.mapboxsdk.maps.MapView
        android:id="@+id/mapView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        mapbox:mapbox_cameraTargetLat="50.87485515"
        mapbox:mapbox_cameraTargetLng="4.707931288875566"
        mapbox:mapbox_cameraZoom="11"
        /> 
2个回答

2

今天在将Android应用从Mapbox Android SDK 6.5.0迁移到7.0.0时,我碰巧遇到了完全相同的问题。

我在代码中也没有使用过mapbox_styleUrl,所以我花了一些时间在思考之后注意到错误引用了mapbox-android-navigation-ui-0.26.0,该库似乎正在使用这个属性(在Mapbox Android SDK 7.0.0中已被移除)。深入研究 Mapbox Navigation Android repository 后,我注意到mapbox-android-navigation-ui最新提交(大约6小时前)已经与Mapbox Android SDK 7.0.0保持最新。

由于这些修复措施尚未作为官方发布包打包,因此我通过Gradle更新依赖关系来将最新的快照版本添加到我的项目中:

repositories {
    mavenCentral()
    maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
}

dependencies {
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.27.0-SNAPSHOT'
}

我真诚地希望这能为您解决一个头疼问题!


0

确保将内容视图设置为正确的布局

例如:我的设置内容视图的行被设置为MainActivity而不是MapsActivity

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Mapbox.getInstance(MapsActivity.this, getString(R.string.mapbox_access_token));
        setContentView(R.layout.activity_maps);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接