[英]How to deal with “${applicationid}” in Xamarin?
I'm trying to create bindings for Zendesk library and I faced with a problem. 我正在尝试为Zendesk库创建绑定,但我遇到了一个问题。
Zendesk Belvedere library (belvedere-1.0.2.1.aar) contains a file provider in its manifest file: Zendesk Belvedere库(belvedere-1.0.2.1.aar)在其清单文件中包含一个文件提供程序:
<?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. 当Gradle用作构建工具时,它会将此信息放在APK文件中,并使用合并清单文件中的
com.your_package_name_here.belvedere.attachments
替换${applicationId}.belvedere.attachments
。 It's fine. 没关系。
However, Xamarin handles it differently. 但是,Xamarin以不同的方式处理它。 Here is what I found in the manifest of my final APK:
这是我在最终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. 显然,
dollar_openBracket_applicationId_closeBracket
不是我需要的。
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). 似乎一切正常,但是不可能安装几个使用这些绑定的Xamarin应用程序,因为它们都会有相同权限的冲突提供程序(并且用户会收到
INSTALL_FAILED_CONFLICTING_PROVIDER
错误)。
Is there a way to change dollar_openBracket_applicationId_closeBracket
in the manifest? 有没有办法在清单中更改
dollar_openBracket_applicationId_closeBracket
?
Edit: A small sample that shows the problem: https://gitlab.com/lassana/ZendeskXamarin/ 编辑:显示问题的小样本: https : //gitlab.com/lassana/ZendeskXamarin/
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. 当前的
Xamarin.Android
清单合并构建任务,包括版本7.1.0.19
,在合并清单中没有像gradle
那样提供任何bundeID / ApplicationID( ${}
}替换。
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. 这只是清单处理/合并任务的一个限制 ,因此您最终会在最终清单中使用
dollar_openBracket_applicationId_closeBracket
,并且必须自己更正两个清单。
The only current solution know to me to avoid the manifest merge task and it's limitation is to: 当前唯一的解决方案让我知道要避免清单合并任务,它的局限性是:
Note: You have to do both steps 注意:您必须执行这两个步骤
Depending upon how often the .aar
is changing and where you are sourcing the .aar
file from: 根据
.aar
的更改频率以及从以下位置获取.aar
文件的位置:
aar
, remove the entry and re-zip the aar
(the quickest way) aar
,移除条目并重新拉链aar
(最快的方式) aar
manifest be changed upstream (not likely to happen ;-) since it works fine w/ gradle
) aar
清单(不太可能发生;-)因为它可以正常工作/ gradle
) FYI: Personally I have seen the ${applicationId}
issue you are having a few times. 仅供参考:我个人已经看过您有几次问题的
${applicationId}
问题。 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. 我已经编写了构建脚本(
bash/.ps1
)来执行清单修复,因为它似乎总是在我正在处理的.arr
的清单中的一些特殊情况。
According to Microsoft team, Xamarin.Build.Download (0.4.12-preview) finally fixes this bug . 根据微软团队的说法,Xamarin.Build.Download(0.4.12-preview)最终修复了这个bug 。
So, you should follow these steps: 因此,您应该按照以下步骤操作:
The main manifest file of your project is the higher priority manifest, so if you add the provider element to main manifest file and apply a merge rule marker for android:authorities
attribute, the merger tools replaces the android:authorities
value that you declare in the main manifest. 项目的主要清单文件是优先级较高的清单,因此如果将提供程序元素添加到主清单文件并为
android:authorities
属性应用合并规则标记,则合并工具将替换您在其中声明的android:authorities
值。主要表现。
Declare provider
element in main manifest: 在主清单中声明
provider
元素:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
...
...
<application>
<provider
android:name="com.zendesk.belvedere.BelvedereFileProvider"
android:authorities="com.example.belvedere.attachments"
tools:replace=”android:authorities” >
</provider>
</application>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.