Android Studio开发APP之调用百度地图SDK

本文记录了在集成百度地图SDK过程中遇到的问题,包括在Eclipse和Android Studio中遇到的闪退和编译错误。文章详细介绍了如何解决这些问题,如正确配置文件夹和.so文件,确保地图正常显示。
  • 写在前面

  • 百度地图SDK是一套应用程序接口, 通过调用地图SDK接口,开发者可以轻松访问百度地图的服务和数据,构建功能丰富、交互性强的地图类应用程序。

  • 下面是官网上的使用指南,步骤十分详细。
    百度地图——Android 地图SDK使用指南
    (注意:不同的项目,要申请不同的AK)

  • 但是就是这样,任然遇到很多其他的坑
  • 首先
eclipse

新建项目,配置工作做好,显示地图的代码写好,APP安装成功后,在进入的时候一直闪退。
花费两天空闲时间没有搞定。
和同学讨论果断选择Android Studio开发项目。

  • 其次
Android Studio

在所有工作做好之后,包括百度官网里面的Android 地图SDK 的配置。
遇到一个错误,如下:

Information:Gradle tasks [:app:clean, :app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:assembleDebug]
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.android.bbalbs.common.util.c) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.ab) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.f) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.g) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.h) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.i) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.j) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.k) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.l) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.m) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.n) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(com.baidu.ar.npc.o) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
...

大致意思就是:这个类可能是由不针对现代.class文件格式的编译器生成的。建议的解决方案是使用最新的编译器,不指定任何“目标”类型选项,从源重新编译类。忽略此警告的后果是,对该类的反射操作将错误地指示它是*而不是*内部类。忽略匿名内部类的innerClass属性,而匿名内部类不附带关联的外壳方法属性。不太懂什么意思!!!

解决方法:


只留下armeabi文件夹里面的.so文件。原因是因为:导入的五个包含.so文件相互干扰而出错。
所以,现阶段我只留下一个文件夹,后续将对次进行研究,总之,意思也就是在导入的时候选择合适的,不要全都放在里面。

错误,不显示地图,然后过几秒后闪退。解决方法:里面必须有armeabi文件夹里面的.so文件。

### 配置和调用百度地图SDK #### 一、创建并配置新项目 为了在Android Studio中集成百度地图SDK,需先建立一个新的Android应用项目。完成项目的初始设置之后,确保已按照官方指南进行了必要的环境准备。 #### 二、引入依赖项 编辑`build.gradle(Module: app)`文件来添加对于百度地图库的支持: ```gradle dependencies { implementation 'com.baidu.mapapi.sdk:map:x.x.x' // 替换成最新版本号[^1] } ``` 同步Gradle以使更改生效。 #### 三、获取API密钥 前往[百度开发者平台](https://lbsyun.baidu.com/)注册账号,并申请适用于移动设备的地图服务API Key。此Key用于验证身份以及访问权限管理。 #### 四、初始化SDK 打开`AndroidManifest.xml`文件,在<application>标签内加入如下声明语句以便于启动时加载地图资源: ```xml <meta-data android:name="com.baidu.lbsapi.API_KEY" android:value="您的API KEY"/> <!-- 更多配置可参见文档说明 --> ``` 同时还需要注意检查是否已经授予了应用程序所需的定位权限以及其他可能涉及的安全策略调整。 #### 五、编写显示地图界面代码 通过继承自MapActivity类或者直接利用MapView控件可以在布局文件里定义一个视图容器用来承载实际的地图展示部分;而在对应的Java/Kotlin源码中则负责实例化对象并与UI组件关联起来实现交互逻辑功能。 例如,在activity_main.xml中添加MapView widget: ```xml <com.baidu.mapapi.map.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/baidu_map_view" android:layout_width="match_parent" android:layout_height="match_parent"> </com.baidu.mapappi.map.MapView> ``` 接着是在MainActivity.java/kotlin里面操作这个widget: ```java public class MainActivity extends AppCompatActivity { private MapView mMapView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mMapView = findViewById(R.id.baidu_map_view); // 初始化地图控制器引用 BaiduMap baiduMap = mMapView.getMap(); ... } @Override protected void onDestroy() { super.onDestroy(); // 在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理 mMapView.onDestroy(); } // 实现其他生命周期回调函数... } ``` 如果遇到程序运行过程中崩溃的情况,则可能是由于某些特定条件未满足所引起的异常错误。建议仔细排查日志输出信息中的提示内容,针对性地解决问题。比如确认所有必需的权限都已经正确声明并且被用户授予权限请求对话框中选择了允许选项等。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值