Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deal with "${applicationid}" in Xamarin?

I'm trying to create bindings for Zendesk library and I faced with a problem.

Zendesk Belvedere library (belvedere-1.0.2.1.aar) contains a file provider in its manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    ...

    <application>
        <provider
            android:name="com.zendesk.belvedere.BelvedereFileProvider"
            android:authorities="${applicationId}.belvedere.attachments"
            android:exported="false"
            android:grantUriPermissions="true" >
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/belvedere_attachment_storage" />
        </provider>
    </application>

</manifest>

When Gradle is used as build tool, it puts this aar to the APK file and it replaces ${applicationId}.belvedere.attachments with com.your_package_name_here.belvedere.attachments in the merged manifest file. It's fine.

However, Xamarin handles it differently. Here is what I found in the manifest of my final APK:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    ...
    ...

    <application 
        ...
        ...
        <provider 
            android:name="com.zendesk.belvedere.BelvedereFileProvider" 
            android:exported="false"
            android:authorities="dollar_openBracket_applicationId_closeBracket" 
            android:grantUriPermissions="true">
            <meta-data 
                android:name="android.support.FILE_PROVIDER_PATHS" 
                android:resource="@xml/belvedere_attachment_storage" />
        </provider>
        ...
        ...
    </application>
</manifest>

Obviously, dollar_openBracket_applicationId_closeBracket is not what I need.

Seems everything works, however it makes impossible to install several Xamarin applications that use these bindings, because all of them would have conflicting providers with the same authority (and user would get INSTALL_FAILED_CONFLICTING_PROVIDER error).

Is there a way to change dollar_openBracket_applicationId_closeBracket in the manifest?

Edit: A small sample that shows the problem: https://gitlab.com/lassana/ZendeskXamarin/

like image 890
Mikalai Daronin Avatar asked Jan 09 '17 15:01

Mikalai Daronin


1 Answers

The current Xamarin.Android manifest merge build task, up to and including version 7.1.0.19, does not provide any bundeID/ApplicationID (${}} substitution in the merged manifest like gradle does.

This is just a limitation in the manifest processing/merge task, thus you are ending up with dollar_openBracket_applicationId_closeBracket in your final manifest and will have to correct both manifests yourself.

The only current solution know to me to avoid the manifest merge task and it's limitation is to:

  1. Remove the file provider entry from the '.aar`'s manifest
  2. Add the complete file provider entry your app's manifest

Note: You have to do both steps

Depending upon how often the .aar is changing and where you are sourcing the .aar file from:

  • Manually unzip the aar, remove the entry and re-zip the aar (the quickest way)
  • Automated this in a build step via a shell script using bash or powershell cmds
  • Write a MSBuild C#-based Task to do it.
  • Request that the aar manifest be changed upstream (not likely to happen ;-) since it works fine w/ gradle)

FYI: Personally I have seen the ${applicationId} issue you are having a few times. I have written build scripts (bash/.ps1) to do the manifest fix-up as it seems to always be some special case in the .arr's manifest that I am dealing with.

like image 60
SushiHangover Avatar answered Sep 28 '22 17:09

SushiHangover