Android百度地图调用LocationClient定位崩溃

最近在开发一个地图相关的项目,其中使用到了百度地图相关的API。在测试过程中遇到了一个崩溃问题,奔溃日志如下


01-22 17:30:25.963 2072-2072/com.laydin.infrared I/dalvikvm: Could not find method android.content.Context.startForegroundService, referenced from method com.baidu.location.LocationClient.a
01-22 17:30:25.963 2072-2072/com.laydin.infrared W/dalvikvm: VFY: unable to resolve virtual method 759: Landroid/content/Context;.startForegroundService (Landroid/content/Intent;)Landroid/content/ComponentName;
01-22 17:30:25.963 2072-2072/com.laydin.infrared D/dalvikvm: VFY: replacing opcode 0x6e at 0x0021
01-22 17:30:26.153 2072-2072/com.laydin.infrared D/dalvikvm: Trying to load lib /data/data/com.laydin.infrared/files/libs/libBaiduMapSDK_map_v5_0_0.so 0x42a52350
    Added shared lib /data/data/com.laydin.infrared/files/libs/libBaiduMapSDK_map_v5_0_0.so 0x42a52350
01-22 17:30:26.153 2072-2072/com.laydin.infrared E/JVMContainer VMSG: RegisterNatives
01-22 17:30:26.183 2072-2072/com.laydin.infrared W/ContextImpl: Failed to ensure directory: /storage/sdcard1/Android/data/com.laydin.infrared/files
01-22 17:30:26.733 2072-2072/com.laydin.infrared E/BaiduMapFragment: onResume()
01-22 17:30:26.753 2072-2135/com.laydin.infrared D/MSimTelephonyManager: mapDualCardSubID, input subscription = 0
    getDeviceId, subscription=0
01-22 17:30:26.833 2072-2150/com.laydin.infrared D/dalvikvm: Trying to load lib /data/app-lib/com.laydin.infrared-1/liblocSDK7b.so 0x42a52350
    Added shared lib /data/app-lib/com.laydin.infrared-1/liblocSDK7b.so 0x42a52350
    No JNI_OnLoad found in /data/app-lib/com.laydin.infrared-1/liblocSDK7b.so 0x42a52350, skipping init
01-22 17:30:26.863 2072-2121/com.laydin.infrared A/libc: Fatal signal 7 (SIGBUS) at 0x761f2c84 (code=2), thread 2121 (Tmcom-Socket)
01-22 17:30:26.863 2072-2133/com.laydin.infrared A/libc: Fatal signal 7 (SIGBUS), thread 2133 (Tmcom-MapData)
01-22 17:30:26.863 2072-2072/com.laydin.infrared A/libc: Fatal signal 7 (SIGBUS) at 0x761f2d44 (code=2), thread 2072 (laydin.infrared)
01-22 17:30:26.863 2072-2127/com.laydin.infrared A/libc: Fatal signal 7 (SIGBUS) at 0x761f2d44 (code=2), thread 2127 (laydin.infrared)
01-22 17:30:26.873 2072-2130/com.laydin.infrared A/libc: Fatal signal 11 (SIGSEGV) at 0x00012aec (code=1), thread 2130 (Thread-2470)
01-22 17:30:27.243 2072-2133/com.laydin.infrared A/libc: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 2133 (Tmcom-MapData)
01-22 17:30:27.673 2072-2121/com.laydin.infrared A/libc: Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 2121 (Tmcom-Socket)
 

 崩溃发生在

1.烧写程序后的第一次运行打开地图界面(包含地图显示与定位)

2. 当应用被回收后恢复应用再次打开地图界面(包含地图显示与定位)

如果只是单独调用定位不显示地图,则不会崩溃。最终解决这个问题存在一定的幸运成分。对比了之前自己开发的一个Demo却不存在这样的问题,最终通过对比两个工程发现崩溃问题的工程中的build.gradle文件中存在externalNativeBuild相关配置

defaultConfig {
        minSdkVersion 19
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
            }
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

 去掉上述externalNativeBuild 相关配置后,崩溃Bug解决!

你可能感兴趣的:(Android)