Android Baidu Maps SDK crashes

Crashing occurs when calling Baidu SDK. You need to know the specific reason for the crashing . Otherwise, you searched a bunch of tutorials and found that it was a waste of time.

View APP running log through Android IDE

  I am using Android Studio, and partners can also query their own IDE to view logs according to their own situation. In AS, the old version can be viewed through Android Monitor, and the new version can be viewed through LogCat. The two can be seen in the bottom bar of AS, and the details of APP operation can be seen in its window. When a flashback occurs , you can see the detailed error information through the window, and then debug according to the error information.

Error 1:errorcode: 230 uid: -1 appid -1 msg: APP Mcode verification failed

  As shown in the figure below, it prompts that the authentication has failed. Generally, this problem occurs because the SHA1 value used when applying for Baidu Maps SDK is different from the SHA1 value used by the actual APP. Now when applying for the Baidu map key, what is needed is the SHA1 value of the release version of the APP, but in the process of debugging, we actually use the SHA1 of the debug version by default, so we need to use the SHA1 value of the debug version to replace the one used in the application. The SHA1 value of the release version, after the final release, go to the Baidu Maps SDK console to replace it with the release version SHA1.
  There are many online tutorials for obtaining SHA1 values. You can find them by yourself. There is another solution, which is to directly check the signature used by the APK of the APP, and then replace it. I can directly check the signature used by it through the LogCat of AS. For the SHA1 value, I can also check the built APK on the Internet. I couldn’t find the key file, but I also posted it for your reference:
1. Build APK
2. Change the suffix of the .apk file to .zip, of course not change It can also be opened directly with 7Z.
3. Enter the META-INF directory and look for the file CERT.RSA. I didn’t find this file.
4. Run the cmd command in this directory: keytool -printcert -file CERT.RSA, pay attention here Does this machine have multiple JDK versions? If so, you need to use the keytool.exe corresponding to the JDK version used when compiling the APP

## Error 2: com.baidu.mapapi.common.BaiduMapSDKException: not agree privacyMode, please invoke SDKInitializer.setAgreePrivacy(Context, boolean) function   As shown in the figure above, the cause of the exception is not agreeing to the privacy agreement, which needs to be initialized when SDK Set through setAgreePrivacy, the code is as follows
SDKInitializer.setAgreePrivacy(getApplicationContext(),true);
SDKInitializer.initialize(getApplicationContext());
SDKInitializer.setCoordType(CoordType.BD09LL);
LocationClient.setAgreePrivacy(true);

At present, I have only encountered the above two kinds of problems. I hereby record them and add new ones.

Guess you like

Origin blog.csdn.net/qq_35308053/article/details/130638872