Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes FFImageLoading linker-safe #1378

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

akamud
Copy link

@akamud akamud commented Oct 27, 2019

✨ What kind of change does this PR introduce? (Bug fix, feature, docs update...)

Makes FFImageLoading linker-safe, so people can opt-in on what they want to bring as a dependency when using Linker configured as "Link All". This can help reduce app's sizes.

This closes #1317

If anyone wants the old behavior and doesn't care about the app final size, they can just add rules to their linker.xml. Unfortunately, linker does not allow assembly wildcards (AFAIK), so one rule must be used for each different assembly used, like this:

<linker>
       <!-- Other linker rules -->
        <assembly fullname="FFImageLoading.Forms">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>
        <assembly fullname="FFImageLoading">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>
</linker>

My suggestion is adding a new page to the wiki named "Linker configuration", with this info:


If you are using Linker with "Link All" setting enabled, you might have to add rules to prevent Linker from removing types from FFImageLoading. Ideally you should preserve just what you are using, but if you prefer you can just add a catch-all rule to the Linker XML file as described in Xamarin documentation, although it can result in an app with larger size than you need.

If you decide to just preserve everything, you must add a rule for each FFImageLoading assembly referenced by your project. Please remember that packages have dependencies, so for example, if you are using FFImageLoading.Forms, it has a dependency on FFImageLoading too, so you should add at least two rules, one for each assembly.

Note: If you add a rule for an assembly you are not using, the linker task will throw an error, so you should just add the ones you need:

<linker>
       <!-- Other linker rules -->

       <!-- Xamarin.FFImageLoading NuGet -->
        <assembly fullname="FFImageLoading">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>
        <assembly fullname="FFImageLoading.Platform">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>

        <!-- Xamarin.FFImageLoading.Forms NuGet -->
        <assembly fullname="FFImageLoading.Forms">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>
        <assembly fullname="FFImageLoading.Forms.Platform">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>

        <!-- Xamarin.FFImageLoading.Transformations NuGet -->
        <assembly fullname="FFImageLoading.Transformations">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>

        <!-- Xamarin.FFImageLoading.Svg NuGet -->
        <assembly fullname="FFImageLoading.Svg.Platform">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>

       <!-- Xamarin.FFImageLoading.Forms.Svg NuGet -->
        <assembly fullname="FFImageLoading.Svg.Forms">
                <type fullname="FFImageLoading*" preserve="all" />
        </assembly>
</linker>

⤵️ What is the current behavior?

FFImageLoading has Preserve=All for all classes, which makes impossible for someone to remove unused code to reduce app size.

🆕 What is the new behavior (if this is a feature change)?

FFImageLoading no longer preserves all, making it ok for Linker to remove anything that is unused, leading to a possibly smaller app size.

💥 Does this PR introduce a breaking change?

Yes, if someone is using "Link All", their app build might break with this change alone, so they can just fix it adding only what they need or they can configure their linker as stated above to keep the old behavior.

🐛 Recommendations for testing

Turn on "Link All", add the linker rules mentioned above and rebuild the samples.

📝 Links to relevant issues/docs

Linker configuration

🤔 Checklist before submitting

  • All projects build
  • Follows style guide lines
  • Relevant documentation was updated
  • Rebased onto current develop

@akamud akamud changed the title Make FFImageLoading linker-safe Makes FFImageLoading linker-safe Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant