First create a new binding library project, the project name is random, I named Bmap
The jar file is then placed into the jars directory, and the build property is changed to Embeddedjar
At this point, if the build DLL file fails, it is suggested that there are several classes of subkeys that cannot drink the same class name
The solution is to add several properties under Metadate
<attr path= "/api/package[@name = ' Com.baidu.mapapi ']/class[@name = ' versioninfo ']/field[@name = ' version_info ']" Name= "Name" >VersionInfos</attr> <attr path= "/api/package[@name = ' com.baidu.location ']/class[@ Name= ' address ']/field[@name = ' address '] "name=" name ">address2</attr> <attr path="/api/package[@ Name= ' Com.baidu.platform.comapi.map ']/class[@name = ' a ']/field[@name = ' A '] "name=" name ">As</attr> <attr path= "/api/package[@name = ' Com.baidu.platform.comapi.map ']/class[@name = ' B ']/field[@name = ' B ']" name= "name ">Bs</attr>
The As,bs in the property is any kind of input, but the Name= property can not be changed, the Path property is a copy of the error message, the error effect is as follows
After resolving this error, you can build the DLL, and after the build succeeds, reference the project or DLL in the Android project.
At this time we add Baidu map under the Android project can
The code is as follows
[Assembly:metadata ("Com.baidu.lbsapi.API_KEY", Value = "Your Baidu map KEY")]
Effect
Baidu map key Application address http://lbsyun.baidu.com/
Apply for Baidu Map when you need to register and keystore the value of SHA1
The SHA1 value is obtained by using the Keytool command in the cmd command (if prompted without this command stating that the environment variable is not configured, Baidu resolves it itself)
Xmarin secret key password is empty, directly enter can, in cmd copy secret key method is right button, mark, check the value of SHA1, enter the copy good
Keytool-list-v-keystore File Location
After resolving the Baidu map compilation and key, also need to import so library, so library is the core of Baidu map with code, add method is to create a new Libs folder in the Android project (this should not be said)
Add arm64-v8a,armeabi,armeabi-v7a three directories in Libs (these three directories are added to ensure software compatibility enhancements, Baidu's requirements Armeabi this directory add)
Copy the so library into it, and the build action is set to Androidnativelibrary note that the so library is placed directly on the Android project, not in Bmap.
Such as
Finally, the code, the new class inherits activity, creates a new layout file layout1
The layout code is as follows
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:orientation=" vertical " android:layout_width=" match_parent " android:layout_height= "Match_parent" > <com.baidu.mapapi.map.mapview android:id= "@+id/bmapview" android:layout_ Width= "Fill_parent" android:layout_height= "fill_parent" android:clickable= "true"/></linearlayout >
The CS code is as follows
namespace testandroid_blankapp{ [Activity (Label = "Testbaidumap")] public class Testbaidumap:activity { private Mapview map; protected override void OnCreate (Bundle savedinstancestate) { base. OnCreate (savedinstancestate); Sdkinitializer.initialize (ApplicationContext); Setcontentview (RESOURCE.LAYOUT.LAYOUT1); Map = findviewbyid<mapview> (Resource.Id.bmapView); Create your application here } protected override void Onresume () { base. Onresume (); Map. Onresume (); } protected override void OnPause () { base. OnPause (); Map. OnPause (); } protected override void OnDestroy () { base. OnDestroy (); Map. OnDestroy ();}}}
Debug, run the effect as follows
Run successfully, this time I tried to compile release version, found an error, "Java.exe" has exited, the code is 1.
Check for half a day, found that because of the compile release version of the time vs2015 will go to confuse the code, Baidu map code is not confused, so in the configuration I closed the confusion configuration, temporarily did not study this how to exclude confusion
Modify the following
I will compile the version down the Baidu cloud, we can see the effect, Baidu Map has been integrated into the Xmarinapp
http://pan.baidu.com/s/1dE2Cyx7
The app is divided into two pages, chat room and Baidu map test page, chat server is my computer, sometimes open during the day
Xmarin.android for vs2015 use Baidu map api3.6.1