Shared resources for separate android/iOS projects

I'm creating a Forms PCL project which will contain two Android apps (one for each company brand) and two iOS apps (one for each company brand), and one shared PCL.

I'm hoping that i will be able to store many of the shared resources (images, mostly, but possibly also text) in a shared project for each device. For the time being, there won't be any separate functionality between the two android and two iOS projects per brand, but that might happen down the road.

For example, I'd love this setup:
Root
- PCL Project (shared code, Forms, etc)
- Android.Shared (shared resources/localisations for the android apps)
- Android.Brand1 (custom resources (logos, colors, etc) for Brand1)
- Android.Brand2 (custom resources (logos, colors, etc) for Brand2)
- iOS.Shared (shared resources/localisations for the android apps)
- iOS.Brand1 (custom resources (logos, colors, etc) for Brand1)
- iOS.Brand2 (custom resources (logos, colors, etc) for Brand2)

I'm also wanting to be able to use the standard /drawable/dpi and /resources/@2x resource functionality within the four platform-specific apps as it already exists, but I'm unsure of how to set this up.

Any advice would be welcome, as I am fairly new to this whole process. Thanks.

Best Answer

Answers

  • PubuduGayanPubuduGayan NZMember ✭✭✭

    @BrianMah In user experience wise I recommend to add different resource images with different quality to the relevant folders in droid Resource folder, but if you want to share single image you can added to the PCL and shared it but make sure to change the Build action property = “Embedded Resource”.

    Plus , probably you may know keep in mind not to add “-” to your image names that will hurt you… :neutral:

  • BrianMahBrianMah USMember ✭✭

    The issue is not sharing between different qualities.
    The issue is that I would put my shared resources (button images, backgrounds, icons, etc) into the platform-shared project, which would then be used by the two 'child' projects for that platform. Then, the brand specific resources (logos, etc) would go into the individual platform projects. I want to keep the current built-in resource loading mechanism that automatically chooses the correct quality/dpi/whatever, but need the child platform projects to be able to pull resources from the shared project.

  • PaulDistonPaulDiston USUniversity ✭✭✭✭
    edited September 2016

    @BrianMah Hi, I am looking to do the same thing, have you managed to find a solution to this?

  • LobboLobbo GBMember ✭✭
    edited December 2017

    @BrianMah, Sorry to raise an old thread but I've struggled to find much on anyone else doing this. I have my project set up like your example before but I'm unable to tell the "Brand" projects to use files from the "Android.Shared" and "iOS.Shared" project, such as an interface for device specific code which I wouldn't want repeated across all the brand projects.
    How did you get around this?

    Edit: I got this working for iOS by setting the dependencies correctly, but the same settings for iOS don't work.
    Shared code calls Dependency
    DependencyService.Get<ISystemFunctions>().ToggleTorch();

    Shared iOS project has the interface code (code worked originally when i was running the shared iOS project before i added brands)

    ` [assembly: Dependency(typeof(SystemFunctions_iOS))]

    namespace SharedApp.iOS.iOS_Interfaces
    {
    public class SystemFunctions_iOS : ISystemFunctions
    {
    public SystemFunctions_iOS()
    { }

        public void ToggleTorch()
        {
            var device = AVCaptureDevice.GetDefaultDevice(AVMediaTypes.Video);
            if (device == null)
                return;
    
            device.LockForConfiguration(out NSError error);
            if (error != null)
            {
                device.UnlockForConfiguration();
                return;
            }
            else
            {
                device.TorchMode = device.TorchMode == AVCaptureTorchMode.On ? AVCaptureTorchMode.Off : AVCaptureTorchMode.On;
                device.UnlockForConfiguration();
            }
        }
    }`
    

    Sorry again!

Sign In or Register to comment.