13. The latest Android Xamarin binding related pits tour

Source: Internet
Author: User
Tags xpath

Today, there are brothers in the group that third-party libraries cannot afford it. To be honest, I think third-party libraries are more likely to succeed than 90% except for a handful of disgusting libraries.

Most third-party libraries can still be bundled.

https://github.com/Youzan/Youzanmobilesdk-android

This is official, and there's a corresponding demo.

First Encounter binding library I will be the first time NuGet query under the very few people will use this library. But what if someone binds?

And then I'm going to search the GitHub with a wooden and nice guy bound up

There's no one to bind 2 of these methods, okay, so I'm going to open my own.

First of all, Android bindings are much easier to handle than iOS bindings, so be patient and careful.

First download the official use as open run up no problem good official no pits. (Be sure to remember this step otherwise you'll be crying if the official pit is there)

Next, prepare a 2 tool ILSpy.exe Jd-gui.exe

And then we'll look at the official dependencies. It's important that this step

Use the relevant gradlew to see dependencies on specific Baidu Android Studio dependent view

Now I've found a dependency.

systemweb-2.0.9

sdk-analytics-0.4.7
youzansdk-6.3.5
anko-commons-0.10.0
anko-sqlite-0.10.0
gson-2.8.0
okhttp-3.8.1
okio-1.13.0
basic-6.3.5

webcache-2.2.0

jsbridge-2.0.2

In this case, AAR, remember to build a separate binding class library.

Start binding

The first step binds basic-6.3.5. AAR when it was discovered that a Youzanbrowser class could not be generated at this time to open

View All Files

Open this folder and look inside there's a classs.jar. Using the Jd-gui.exe tool to decompile view the structure of the following class

Then edit and modify with XML syntax remember that the official auto-generation simply simplifies this step. Well-written libraries are perfectly fine, but some domestic companies don't write well, and that means you just give it up and write it down.

First Remove-node Remove the node that compiled the error

<remove-node path= "/api/package[@name = ' android.support.v4.content ']/class[@name = ' Cursorloader ']/method[@name = ' Loadinbackground '] "/>
What is the object of an XPath syntax operation? is an XML file

Api.xml is a tool to help you build. Sometimes you can't remember the grammar.

Api.xml.fixed is a modified build (after your XPath process, which is the Metadata.xml file you've been talking about)

All right, it's not important. Remember that if you find that compiling a bunch of syntax errors, first remove the nodes and the wrong class directly

Then according to the project need those API methods and classes directly build themselves

We need to youzanbrowser this object to open the corresponding Class.jar with Jd-gui.

Isn't this the kind of class we need? Why can't we build it? Most of this is because third-party libraries that rely on third-party classes and objects that cannot resolve interface implementations can have this problem. We don't have to look at it first.

It doesn't matter what you smear.

See only one package class name inheritance relationship

<Add-nodePath= "/api/package[@name = ' com.youzan.androidsdk.basic ']">    <classAbstract= "false"deprecated= "Not deprecated"extends= "Android.webkit.WebView"Extends-generic-aware= "Java.lang.Object"Final= "false"name= "Youzanbrowser"Static= "false"Visibility= "Public">          </class>  </Add-node>

The name of the people in English good look on the line to pay attention to is 2 things

extends if there is no special need, you can inherit the object directly without inheriting a specific type , but we are here because we need a specific type of code inside so set him to inherit Android.webkit.WebView specific The type of people can see his Jd-gui source

And then just add the method you want.

  <Constructordeprecated= "Not deprecated"Final= "false"name= "Youzanbrowser"Static= "false"Visibility= "Public">        <parametername= "Context"type= "Android.content.Context">        </parameter>      </Constructor>      <MethodAbstract= "false"deprecated= "Not deprecated"Final= "false"name= "Pagegoback"native= "false"return= "Boolean"Static= "false"synchronized= "false"Visibility= "Public">              </Method>      <MethodAbstract= "false"deprecated= "Not deprecated"Final= "false"name= "Reload"native= "false"return= "void"Static= "false"synchronized= "false"Visibility= "Public">      </Method>      <MethodAbstract= "false"deprecated= "Not deprecated"Final= "false"name= "OnPause"native= "false"return= "void"Static= "false"synchronized= "false"Visibility= "Public">      </Method>      <MethodAbstract= "false"deprecated= "Not deprecated"Final= "false"name= "Destroy"native= "false"return= "void"Static= "false"synchronized= "false"Visibility= "Public">      </Method>      <MethodAbstract= "false"deprecated= "Not deprecated"Final= "false"name= "Onresume"native= "false"return= "void"Static= "false"synchronized= "false"Visibility= "Public">      </Method>      <!--boolean receivefile (int paramint, Intent paramintent); -      <MethodAbstract= "false"deprecated= "Not deprecated"Final= "false"name= "Receivefile"native= "false"return= "void"Static= "false"synchronized= "false"Visibility= "Public">        <parametername= "Paramint"type= "int">        </parameter>        <parametername= "Paramintent"type= "Android.content.Intent">        </parameter>      </Method>      <MethodAbstract= "false"deprecated= "Not deprecated"Final= "false"name= "Loadurl"native= "false"return= "void"Static= "false"synchronized= "false"Visibility= "Public">        <parametername= "Paramstring"type= "Java.lang.String">        </parameter>      </Method>

This is very simple according to the anti-compiled object type to adjust and name can also not buckle the head of the want to generate the wrong and so on. Interfaces are similar to processing logic

If the compilation does not pass can be viewed in the output there will be detailed hints

After compiling all the bindings, remember to join the dependent libraries that you originally found.

Sometimes the smart hints get stuck. How do you know if the class I want is generated? You can use Ilspy to see if it comes out, even if there's a wave in the demo, it doesn't matter if he compiles.

Start writing a demo run to see

began to encounter the first deep pit.

  java.lang.NoClassDefFoundError:Failed resolution Of:lkotlin/jvm/internal/intrinsics;

The first crash exception appears. No information is available about Xamarin. You're going to feel insane, what a garbage Xamarin ... It's not that if you do Android native development you'll know that the Java side needs to introduce a stblib when using Kotlin's library.

Our Xamarin has long provided a nuget search under

Join this library and run it without an error.

At this point the entire process is complete

If the run process appears

Java.Lang.NoClassDefFoundError:Failed resolution Of:lorg/jetbrains/anko/db/managedsqliteopenhelper; Noclassdeffounderror Please check if the dependent third-party jar has been hit in your bound libraryremember to clean up before compiling, or it will make you feel the crash added results or not found remember to emptyRun, I'm already on GitHub.

Https://github.com/jsonsugar/XamainAndroidBindLibary

13. The latest Android Xamarin binding related pits tour

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.