Xamarin.android binding from GitHub third-party libraries (Advanced education)----AAR file

Source: Internet
Author: User

Primary teaching (includes installation of the Xamarin.gradlebindings plugin)

Intermediate Teaching

Today we came to advanced teaching, today to bind a project on GitHub on nearly 4000star---------Android picture Carousel control: Banner

Today will deal with a lot of error, this is with the primary intermediate teaching, the largest of the different parts.

Thanks, Xamarin University Chris Teacher for the help of this banner library binding.

Let's look at it first.

Let ' s Rock-n-roll

1.vs2017----Create Android---Single view app----name Bannerproject

2. Solution Bannerproject---> References (right-click)--->generate xamarin.android Bindings via Gradle

3. Find this sentence on the GitHub Readme page of the banner project

Gradle

dependencies{    'com.youth.banner:banner:1.4.10'  //Latest version}  

4. According to the compile written by the author of the library

, fill in External dependency ID: com.youth.banner:banner:1.4.10

5. Right-click the solution to install the NuGet package: Xamarin.Android.Support.v4

6. Rebuild the solution.

7. You will get 55 errors, 43 warnings (today we only resolve the error, do not resolve the warning)

Today's play is coming, this is not covered by the previous primary and advanced teaching, please carefully follow the steps to go

At that time I said a face error!!!, the first time I met so many Black question mark

8. Solve the problem of namespace and class name conflicts by general processing.

Open Binding_banner Project----->transforms folder-----metadata.xml file

Add inside the metadata

<metadata><!--Renaming the Namespace to make sure we don't have a Class names that match Namespace names -    <attrPath= "/api/package[@name = ' Com.youth.banner ']"name= "Managedname">Youth.bannersdk</attr>    <attrPath= "/api/package[@name = ' Com.youth.banner.transformer ']"name= "Managedname">Youth.BannerSdk.Transform</attr>    <attrPath= "/api/package[@name = ' Com.youth.banner.listener ']"name= "Managedname">Youth.BannerSdk.Listener</attr>    <attrPath= "/api/package[@name = ' Com.youth.banner.loader ']"name= "Managedname">Youth.BannerSdk.Loader</attr>    <attrPath= "/api/package[@name = ' Com.youth.banner.view ']"name= "Managedname">Youth.BannerSdk.View</attr></metadata>

9. Rebuild the solution, voila, is not 52 errors, only 3 errors!!! hahaha, magical and magical really magical ......

10. Hmm, these three little thieves, just a modifier question.

No problem, let's do it.

Or in the metadata.xml file.

Add the following code

<!--Update visibility of override methods to match Abstract class -       <attrPath= "/api/package[@name = ' Com.youth.banner.transformer ']/class[@name = ' Cubeintransformer ']/method[@name = ' Ispagingenabled ' and count (parameter) =0] "name= "Visibility">Protected</attr>    <attrPath= "/api/package[@name = ' Com.youth.banner.transformer ']/class[@name = ' Cubeouttransformer ']/method[@name = ' Ispagingenabled ' and count (parameter) =0] "name= "Visibility">Protected</attr>    <attrPath= "/api/package[@name = ' Com.youth.banner.transformer ']/class[@name = ' Defaulttransformer ']/method[@name = ' Ispagingenabled ' and count (parameter) =0] "name= "Visibility">Protected</attr>

11. Rebuild the solution. Voila, WTF, the ultimate boss appeared???

Why is there a new error????????

a petty thief and an old thief!!!!!!!!!!!!!!!

Or in the metadata.xml file.

Add the following code ( As for why, I'm going to do a video detailing, there's not much time for this tonight ...). In short Mark,mark,mark)

  <!--   displayimage  is not implemented-  <Path  = "/api/package[@name = ' Com.youth.banner.loader ']/class[@name = ' Imageloader ']"/>

13. Rebuild the solution without any errors, is it not? All the thieves and the thieves are gone ......

========== All rebuilds: 2 successful, 0 failed, 0 ========== skipped

Awesome

14. Open Bannerproject\bannerproject\androidbindings\binding_banner\bin\debug to find Binding_ Banner.dll file, copy it somewhere else, and save it, don't lose it.

15. We're going to kill Binding_banner this project, right-click Remove

16. Refer to the Binding_banner that you just saved in the bannerproject project . dll file.

17. Refer to the Binding_picasso.dll file (this library is a jar file format, I have turned it into a DLL, I left this library's github link here, you can do the binding yourself, very simple)

Https://github.com/square/picasso

' com.squareup.picasso:picasso:2.5.2'

Because we use banner this third-party library needs to use Picasso this library (if you do not make this binding, leave a message under the article, I teach you, or send this picasso.dll to you)

======================== exciting time to ==========================================.

==========================================================================

18. Add Myimageloader class, let's write it together

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingAndroid.app;usingandroid.content;usingAndroid.os;usingAndroid.runtime;usingandroid.views;usingAndroid.widget;usingCom.Squareup.Picasso;usingYouth.BannerSdk.Loader;namespacebannerproject{ Public classMyImageLoader:Java.Lang.Object, Iimageloaderinterface { PublicJava.Lang.Object Createimageview (Context p0) {ImageView ImageView=NewImageView (p0); returnImageView; }         Public voiddisplayimage (Context p0, Java.Lang.Object p1, Java.Lang.Object p2) {vartemp =P1.            ToString (); Picasso.with (p0). Load (temp).        Into ((ImageView) p2); }    }}

19. Open the Resources\layout\main.axml file, click Source, and replace it with the following code

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <Com.youth.banner.BannerXmlns:app= "Http://schemas.android.com/apk/res-auto"Android:id= "@+id/banner"Android:layout_width= "Match_parent"Android:layout_height= "600px" /></LinearLayout>

20. Go back to mainactivity, take note of the namespace, replace the code in the entire OnCreate method

Using System;
Using Android.app;
Using Android.content;
Using Android.runtime;
Using Android.views;
Using Android.widget;
Using Android.os;
Using YOUTH.BANNERSDK;
Using System.Collections.Generic;



protected override void OnCreate (bundle bundle) {base. OnCreate (bundle); Set our view from the "main" layout resource Setcontentview (Resource.Layout.Main); Banner Banner = Findviewbyid<Banner>(Resource.Id.banner); Banner. Setbannerstyle (Bannerconfig.circleindicatortitle); ================================================================ var titles = new List<string>() {' My name is 1 ', ' My name is 2 ', ' My name is 3 ', ' My n AME is 4 "," My name is 5 "}; var images = new List<Object> {"http://img.hb.aicdn.com/a0f3cca7aa8e82293c44ef60d8482bb9978499572e121-dr2lA2_fw658", "http://img.hb.aicdn.com/f65b64b9ded69b9b72fccbc2931e6745637953dccf97-WnASP1_fw658", "HTTP://IMG.HB . aicdn.com/3ccb5d8152c42be1a4801701bd6ac22d5260e2f016298-xljvbk_fw658 "," http://img.hb.aicdn.com/8e1a941b74 a8a86736b4c3315985dad6c5c6cc301241e-gfikpc_fw658 "," http://img.hb.aicdn.com/6935c4116e47ffb4c39edd0fc4938f9 9dacb233f136168-0ukcwn_fw658 "}; Banner. Setimageloader (New Myimageloader ()); Sets the picture collection banner. SetImages (images); ----------Test-----banner. Setbannerstyle (Bannerconfig.circleindicatortitleinside); Banner. Setbanneranimation (transformer.accordion); -----------Test---banner. Setbannertitles (titles); Banner the last call to banner when the method is complete. Start (); //=================================================== }

21. Click Start Debugging

22.!!! -------There are a lot of animations in this banner library that can be called-----

banner. Setbanneranimation (transformer.accordion); Modify the Transformer. The following code is available.

PS: If you want to delve into the usage of this library, anyway, we have turned into a DLL, and have learned the basic operation, you just follow the author's introduction on GitHub step by step, or you can read the source code or document directly.

Add permissions to your Androidmanifest.xml (in the properties, on the top of the reference, look it up, you can find this file)
--><android:name="Android.permission.INTERNET--><  android:name="Android.permission.READ_EXTERNAL_STORAGE"/>
My project did not add these two lines, especially the first line, it seems that there is no problem, specifically to see your real machine or simulator situation it.
Well, it's here today.

Xamarin.android binding from GitHub third-party libraries (Advanced education)----AAR file

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.