Forum Xamarin.Forms


NicolasKrierNicolasKrier FRMember ✭✭✭

Hi, I'm working on a project which is a XForms application.

I've been asked to create 3 differents applications even if the code is at 90% the same.
Each app will be in a different language.
The differences between those apps are : the design, sometime a page can have more entries or less, the navigation can slightly differ from an app to another.

The problem is I don't want to have dupplicates custom renderers. Neither dupplicates services nor image ressources.

I invite you to take a look to the PDF attached because you will understand in a second what I'm trying to achieve.

1°) Is is possible to have those files (renderers, resources) in a shared project like a SharedAndroidProject and a SharediOSProject ?
2°) If it is possible, how are managed resources : for exemple, I got an image call Menu.png which will be the same for the 3 apps. If i write the URI as follow URI="Menu.png", it will look for the Menu.png located in App2.Droid, if not find, will it look to the SharedAndroidProject/Resources/Drawable if this project is referenced by App2 ? How can I target a file that is located in SharedAndroidProject/Resources/Drawable ?
3°) What do you think of this kind of approach ?

Thank a lot to anyone who reads this. Any help would be very appreciated.
Have a good weekend !


  • NicolasKrierNicolasKrier FRMember ✭✭✭
    edited November 2015

    I 've tested this solution with a custom renderer located in the SharedAndroidProject. It's working well ! The 3 apps have access to the custom renderers without neither a line of code nor a fix.
    It cools because it means I won't have to dupplicate my custom renderers (as they are the same for the 3 apps)

    I'll investigate on the image resource now ! If it works fine, I think my solution will be nice.

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @NicolasKrier - just to answer your question about resources, if you are using Forms, you can reference an image such as logo.png.

    It will look for it in these places in each project
    Windows Phone - root project folder
    Android - Resources/Drawable (defaults to drawable but if you put different images in the other drawable folders it uses them depending upon the resolution the project is deployed on)
    iOS - Resources folder.

  • NicolasKrierNicolasKrier FRMember ✭✭✭

    Hi @AdamP thank you for your answer.
    I already knew this. What I don't know is this :

    I have 3 app : App1 App2 App3. All these 3 apps use 90% the same picture.
    I want those 90% shared resource to be in another project referenced by the 3 apps.

    I need :
    SharedAndroid - Resources/Drawable
    And nothing in App1 - Resources/Drawable

  • NicolasKrierNicolasKrier FRMember ✭✭✭

    At @AdamP ok... No need to be worried. Xamarin handle it itself.
    I can't access to the Resource class and check if a key exist.

    I've put the resource file name. Xamarin tried to find the file in the SharedLibrary once it has looked in the AndroidProject without finding the resource.

  • NMackayNMackay GBInsider, University admin


    I like the way your thinking, noticed the same thing, I have three apps and a lot of the stuff is shared, navigation service etc. In essence we have a base framework and then you add the pages for your specific app and there's a separate project for data stuff like models, services & viewModels.

    Any gotchas too look out for?

  • Gabor.SuranyiGabor.Suranyi USMember ✭✭

    How about creating a shared core (a kind of Forms PCL)? That way you can include renderers, services, etc., and just have to reference those projects (instead of using shared code).

  • NMackayNMackay GBInsider, University admin


    Yeah, that would work for common stuff like authentication, the apps each tend to have their own platform specific data services which wouldn't be shared , just more secure if someone starts poking about in your app for endpoints (even if encrypted).

  • NicolasKrierNicolasKrier FRMember ✭✭✭

    @NMackay I put in this layer the shared dependency services, custom renderers, icons, images... Perhaps we 're working on the same kind of project :)

    @Gabor.Suranyi it's what i kinda ended up with.

    Tomorrow, I ll have a look if binding with images still works if my resources are in another project.
    I'll keep you up to date too !!

    Have a great night

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @NicolasKrier - is it just pictures you want to share between projects? It looks like you are already sharing a lot of code between the projects anyway.

    Pictures have a lot of issues in that each platform shows and handles them differently, which is why you normally need to create a large collection of images for each device. However you can share images by embedding them in a PCL.

    If that is what you are looking for?

  • NicolasKrierNicolasKrier FRMember ✭✭✭
    edited November 2015

    @AdamP Yea I already think about this. But because I want to share my dependency services and custom renderers and maybe some controls, I'm looking for another solutions.

    If it works fine with iOS and android library,it could become easier to code because no need to be worried about if the resource is embedded or local to the app project.

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @NicolasKrier - what exactly are you looking to share with custom renderers? The point of custom renderers is to render a control specifically for a platform. If it uses any complex logic, you can just call methods in a PCL from within the custom renderer but custom renderers are very platform specific and stay within the platform specific project.

    Dependency Services are much the same.

  • NicolasKrierNicolasKrier FRMember ✭✭✭
    edited November 2015

    @AdamP let me explain my situation :
    I have to developp 3 app. The app will be 90% the same. But because the app must be deployed with different names and language, I need 3 different apps. The main difference is that each app have a different workflow. The 3 app may evolve in a different way.
    They target different web services. I know it's possible to handle all my cases with one App (I mean one XForm core project).
    It's a requirement : I was told to separate my app into 3 app. They share a lot of custom renderers (imagine a clock timer event : it will be the same in the 3 app). That's why, for maintainance reason, I need to have the shared resources, custom renderers, etc in a library.

  • AdamPAdamP AUUniversity ✭✭✭✭✭

    @NicolasKrier - ok, apologies, I get you now, you have 3 separate apps but for the same platform(s).

    In that case you just need to generate a separate library for each type of platform. For example on a Windows Phone app you would create a Class Library (Windows Phone) or for iOS a Class Library (iOS) project.

    These projects could be shared between the platform specific project and contain your custom renderers, etc. Embedded Resource for any images etc.

    Use a PCL for anything you can share between different platforms.

    Now that I understand a bit better, is there any particular type of file you are having trouble sharing?

  • NicolasKrierNicolasKrier FRMember ✭✭✭

    @AdamP i'm glad you got me now :)

    For now, I'm investigating why my android app doesn't launch but the ios works. In the meantime I have a lot of other stuff to do so I don't hae enough time to debug deeper this problem.

    Maybe it isn't tied to the shared project resource. Maybe it does. I will keep you updated on this !
    Let me a week or two and I should be able to provide a PoC project and screenshots. (I'm sure it will be helpfull to somebody).

Sign In or Register to comment.