Problems with binding Baidu map SDK to xamarin. android: xamarin. androidsdk
In the xamarin. android binding project, bind the LBS map SDK of Baidu map, refer to the https://developer.xamarin.com/guides/android/advanced_topics/binding-a-java-library/binding-a-jar/ after setting, compile, and then prompt error, one of the errors is
This means that the converted CS Code contains repeated types. Theoretically, the converted CS code should not have repeated code, which means the jar has repeated code.
Then, view the SDK description of Baidu map,
It is found that there is a "overload method with different parameters". Therefore, it is assumed that this method with the same name cannot be identified during the conversion process, resulting in one-to-one conversion, duplicate type code is available in CS.
However, xamarin provides the Metadata. xml file for rewriting the specified method name.
Find Baidu SDK (or anti-cheap jar file). The above two methods are located inOnMapStatusChangeListener
Interface.
Decompilation:
Locate the error code file and find the code with the name. There is an interface.IOnMapStatusChangeListener
, The corresponding interface above is shown below
In fact, the converted code is correct in the interface,IOnMapStatusChangeListener
In the code of the interface implementation, each interface hasEventHandler, resulting in two onmapstatuschangestarandler
Will occur during compilation!
Since the problem is found, what is the solution?
Currently, one method is to modify the name,
In Metadata. in an xml file, path refers to the path of the name to be modified. In the converted cs file, the paths corresponding to each name are marked in the preceding annotations, which is very convenient, you don't have to find it yourself!
Here, I want to modify the secondOnMapStatusChangeStart
If there are two parameters, change the nameOnMapStatusChangeStart2
<attr path="/api/package[@name='com.baidu.mapapi.map']/interface[@name='BaiduMap.OnMapStatusChangeListener']/method[@name='onMapStatusChangeStart' and count(parameter)=2 and parameter[1][@type='com.baidu.mapapi.map.MapStatus'] and parameter[2][@type='int']]" name="managedName">OnMapStatusChangeStart2</attr>
If you execute the compilation again, the compilation will pass.
Link: https://blog.wuliping.cn/post/note-xamarin-android-binding-baidu-lbs-sdk