简体   繁体   English

Android Gradle Manifest Merger:覆盖来自库的'uses-permission'属性

[英]Android Gradle Manifest Merger: Override 'uses-permission' attribute coming from a library

For my app that I'm developing with the latest Android Studio I'm using this dependencies within it's gradle file: 对于我正在使用最新Android Studio开发的应用程序,我在其gradle文件中使用此依赖项:

dependencies {
    compile 'com.android.support:support-v4:21.0.+'
    compile 'com.helpshift:android-aar:3.7.1'
}

The com.helpshift:android-aar:3.7.1 library needs the following permission for a feature that I don't use in my main app: com.helpshift:android-aar:3.7.1库需要以下权限才能获得我在主应用中不使用的功能:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

As described here and here I can override attributes from the imported library's activity XML declarations. 如此此处所述,我可以从导入的库的活动 XML声明中覆盖属性。

But can I also override manifest XML declarations like the mentioned uses-permission ? 但我是否也可以覆盖清单 XML声明,如上面提到的uses-permission

I already tried something like this in my main manifest, but it didn't work: 我已经在我的主清单中尝试了类似的东西,但它没有用:

<permission
    android:name="android.permission.WRITE_EXTERNAL_STORAGE"
    tools:node="remove"
    tools:selector="com.helpshift">
</permission>

Also changing the <permission> element to <uses-permission> did not help. 同时将<permission>元素更改为<uses-permission>也无济于事。 The app still asks for permission to access the SC card . 该应用程序仍然要求访问SC卡的权限

My main AndroidManifest.xml looks like this now: 我的主要AndroidManifest.xml现在看起来像这样:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    android:installLocation="auto"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.bmi.rechner" >

    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        tools:node="remove"
        tools:selector="com.helpshift">
    </uses-permission>

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.android.vending.BILLING" />

    <application
        ...

Update : The suggested answer by @CommonsWare is working. 更新 :@CommonsWare建议的答案正在运行。

It's just my tools:selector="com.helpshift" which isn't correct. 这只是我的tools:selector="com.helpshift" ,这是不正确的。 I'm leaving it out because I'm sure I won't need that permission in any other libraries for a while. 我将其遗弃,因为我确信我暂时不会在任何其他图书馆中获得该许可。

He also filed a feature request to improve the Manifest Merger Report which might help to find the right selector in the future. 他还提交了一项功能请求,以改进清单合并报告,这可能有助于在将来找到合适的选择器。

It would be a <uses-permission> element that you would remove , not a <permission> element. 它将是您要remove<uses-permission>元素,而不是<permission>元素。

And note that the library may crash if your app does not hold this permission. 请注意,如果您的应用未拥有此权限,库可能会崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM