首页 > 解决方案 > 不可转换的类型;无法将 'android.support.v4.app.Fragment' 转换为 'com.google.android.gms.maps.SupportMapFragment

问题描述

编译 SDK 版本 26 谷歌地图工作正常,但当我将其更改为 28 时,它显示错误。

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);

这是我的 build.gradle:

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    lintOptions {
        checkReleaseBuilds false // Add this
        abortOnError false
    }
    signingConfigs {
        config {
            keyAlias 'androiddebugkey'
            keyPassword 'android'
            storeFile file('****')
            storePassword 'android'
        }
    }
    compileSdkVersion 28
    defaultConfig {
        applicationId "****"
        minSdkVersion 19
        targetSdkVersion 28
        versionCode 47
        versionName "2.8"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.config
        }
    }
}

dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-places:17.0.0'
    implementation "com.google.android.gms:play-services-base:16.0.1"
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.android.support:support-v4:26.1.0'
    implementation 'com.mikhaellopez:circularimageview:3.0.2'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.android.support:cardview-v7:28.0.0'
    implementation 'com.yalantis:ucrop:2.2.0-native'
    implementation 'io.branch.sdk.android:library:2.+'
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.android.support:multidex:1.0.1'
    implementation 'com.github.d-max:spots-dialog:0.7@aar'
    implementation 'net.gotev:uploadservice:2.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:recyclerview-v7:28.0.0'
    implementation 'com.google.android.gms:play-services-analytics:17.0.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.4.1'
    implementation 'com.squareup.okhttp3:okhttp:3.11.0'
    implementation 'com.squareup.retrofit2:retrofit:2.4.0'
    implementation 'com.google.code.gson:gson:2.8.5'
    implementation "org.jetbrains.anko:anko:$anko_version"
    implementation 'us.belka:androidtoggleswitch:1.2.2'
    implementation 'com.daimajia.easing:library:2.0@aar'
    implementation 'com.daimajia.androidanimations:library:2.3@aar'
    implementation 'net.gotev:uploadservice:3.4.2'
    implementation 'com.github.clans:fab:1.6.4'
    implementation 'net.gotev:uploadservice-okhttp:3.4.2'
    implementation 'cn.jzvd:jiaozivideoplayer:6.3.1'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'id.zelory:compressor:2.1.0'
    implementation 'com.github.WindSekirun.NaraeAudioRecorder:core:1.1.0'
    implementation('com.paytm:pgplussdk:1.3.1') {
        transitive = true
    }

}
apply plugin: 'com.google.gms.google-services'

标签: androidgoogle-mapsfragmentsupportmapfragment

解决方案


推荐阅读