机器人工作室运行在实际设备应用程序后,增加了不必要的权限 [英] Android studio adds unwanted permission after running application on real device

查看:274
本文介绍了机器人工作室运行在实际设备应用程序后,增加了不必要的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行未提及清单文件的设备应用程序所需的不必要的位置许可申请后。而当我运行从我的朋友Android的工作室一样的code比其运行正常,无需额外的许可。

清单文件

 <使用-SDK
    安卓的minSdkVersion =14
机器人:targetSdkVersion =21/>
    <使用-权限的Andr​​oid:名称=android.permission.ACCESS_WIFI_STATE/>
    <使用-权限的Andr​​oid:名称=android.permission.INTERNET对/>
    <使用-权限的Andr​​oid:名称=android.permission.WRITE_EXTERNAL_STORAG​​E/>
    <使用-权限的Andr​​oid:名称=android.permission.VIBRATE/>
    <使用-权限的Andr​​oid:名称=android.permission.CALL_PHONE/>
    <使用-权限的Andr​​oid:名称=android.permission.READ_EXTERNAL_STORAG​​E/>
    <使用-权限的Andr​​oid:名称=android.permission.USE_CREDENTIALS/>
    <使用-权限的Andr​​oid:名称=android.permission.GET_ACCOUNTS/>
    <使用-权限的Andr​​oid:名称=com.android.vending.BILLING/>
    <使用-权限的Andr​​oid:名称=com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY/>

    <用途特征
        机器人:名称=android.hardware.telephony
        机器人:要求=FALSE/>

    <使用-权限的Andr​​oid:名称=android.permission.ACCESS_NETWORK_STATE/>
 

Build.gradle

 应用插件:com.android.application

安卓{
    compileSdkVersion 21
    buildToolsVersion21.1.2

    defaultConfig {
        的applicationIDXXXXXXX
        的minSdkVersion 14
        targetSdkVersion 21

        //启用multidex支持。
        multiDexEnabled真

    }


    dexOptions {

        javaMaxHeapSize4G
    }

    packagingOptions {
        不包括META-INF / LICENSE.TXT
        不包括META-INF / NOTICE.txt
        不包括META-INF /许可证
        不包括META-INF /注意事项
    }

    lintOptions {
        abortOnError假
    }
}
库{
    mavenCentral()
}
依赖{

    编制项目(:boxAndroidLibraryV2)

    编译com.google.http客户端:谷歌的HTTP客户GSON:1.19.0
    编译com.google code.gson:GSON:2.1
    编译com.google.android.gms:播放服务:+
    编译文件(库/ HockeySDK-3.0.2.jar)
    编译文件(库/ Dropbox的,Android的SDK-1.6.3.jar)

    编译com.google.apis:谷歌API-服务驱动:V2-rev164-1.20.0


    编译文件(库/在应用程序 - 采购 -  2.0.59.jar)
    编译文件(库/ json_simple-1.1.jar)
    编译com.android.support:multidex:1.0.0
    编译com.android.support:appcompat-v7:21.0.3
    编译文件(库/ SLF4J-API-1.7.5.jar)
    编译文件(库/兔崽子,WebDAV的2.7.2.jar)
    编译文件(库/公地httpclient的-3.1.jar)
    编制项目(:电力公司)
    编译文件(库/通v1.1.3.jar)
    编译文件(库/ SDK-v1.0.0.jar)
    编译com.google.api客户端:谷歌的API客户端:1.20.0
    编译com.google.oauth客户端:谷歌的OAuth客户端:1.20.0
    编译com.google.api客户端:谷歌的API客户端 - 机器人:1.20.0
    编译com.google.http客户端:谷歌的HTTP客户端的android:1.20.0

}

配置{
    所有* .exclude组:com.google.guava',模块:番石榴,JDK5
}
 

所以我无法理解为什么它需要的位置的权限。如何添加在我的应用程序这个位置的权限?

解决方案

 编译com.google.android.gms:玩-服务:+
 

这个库将请求位置的权限,为几个部件播放业务的需要。

首先,永远不要使用 + 。如果你想允许自由浮动patchlevels(例如, 22.0。+ ),这不是完全疯了,但使用 + 对于版本的的疯狂。

其次,可以考虑使用一个更集中的依赖关系(或以上),而不是充分发挥服务SDK。这不仅可能消除,你不希望权限,但你的APK将是小了很多。 <一href="https://developers.google.com/android/guides/setup#add_google_play_services_to_your_project">The文档涵盖了可用的选项(参见有选择的API编译成可执行文件部分)。

如果你还是风与你不想要的权限,那么你就需要确定权限的来源。应该有的模块的编译/输出/ APK / 清单合并报告。这将是一个有点难以理解,但希望你能确定是造成此权限的库。在这一点上,你需要决定如何处理:

  • 这消除了许可的最安全的答案就是不再使用该库,而是找一些其他的解决办法的任何问题,你正在试图解决与该库

  • 或者说,生活在许可

  • 或者,尝试添加以下到你的应用程序的清单:

     &LT;使用-权限的Andr​​oid:名称=android.permission.ACCESS_COARSE_LOCATION工具:节点=删除/&GT;
     

这将要求你添加的xmlns:工具=htt​​p://schemas.android.com/tool​​s&LT;清单&GT; 元素,如果它已不存在。这将告诉生成工具,以明确排除此权限,即使库贡献吧。然而,您使用这些库可能会打破。只有做到这一点,如果你有一个专门的测试团队,可以花所需的时间,以确保你的决定阻止此权限将不会导致崩溃或其他行为影响的用户。

After running application on device application required unwanted location permission that is not mention in manifest file. While when I am running same code from my friend Android studio than its run normal without extra permission required.

Manifest file

<uses-sdk
    android:minSdkVersion="14"
android:targetSdkVersion="21" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.android.vending.BILLING" />
    <uses-permission android:name="com.samsung.android.providers.context.permission.WRITE_USE_APP_FEATURE_SURVEY"/>

    <uses-feature
        android:name="android.hardware.telephony"
        android:required="false" />

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

Build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "xxxxxxx"
        minSdkVersion 14
        targetSdkVersion 21

        // Enabling multidex support.
        multiDexEnabled true

    }


    dexOptions {

        javaMaxHeapSize "4g"
    }

    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

    lintOptions{
        abortOnError false
    }
}
repositories {
    mavenCentral()
}
dependencies {

    compile project(':boxAndroidLibraryV2')

    compile 'com.google.http-client:google-http-client-gson:1.19.0'
    compile 'com.google.code.gson:gson:2.1'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/HockeySDK-3.0.2.jar')
    compile files('libs/dropbox-android-sdk-1.6.3.jar')

    compile 'com.google.apis:google-api-services-drive:v2-rev164-1.20.0'


    compile files('libs/in-app-purchasing-2.0.59.jar')
    compile files('libs/json_simple-1.1.jar')
    compile 'com.android.support:multidex:1.0.0'
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/slf4j-api-1.7.5.jar')
    compile files('libs/jackrabbit-webdav-2.7.2.jar')
    compile files('libs/commons-httpclient-3.1.jar')
    compile project(':utilities')
    compile files('libs/pass-v1.1.3.jar')
    compile files('libs/sdk-v1.0.0.jar')
    compile 'com.google.api-client:google-api-client:1.20.0'
    compile 'com.google.oauth-client:google-oauth-client:1.20.0'
    compile 'com.google.api-client:google-api-client-android:1.20.0'
    compile 'com.google.http-client:google-http-client-android:1.20.0'

}

configurations {
    all*.exclude group: 'com.google.guava', module:'guava-jdk5'
}

So I am unable to understand why its require location permission. How this location permission added in my app?

解决方案

compile 'com.google.android.gms:play-services:+'

This library will request location permissions, as several pieces of Play Services need it.

First, never use +. If you want to allow free-floating patchlevels (e.g., 22.0.+), that's not completely insane, but using + for the version is insane.

Next, consider using one (or more) of the more focused dependencies, rather than the full Play Services SDK. Not only will this perhaps eliminate the permission that you do not want, but your APK will be a lot smaller. The documentation covers the available options (see the "Selectively compiling APIs into your executable" section).

If you still wind up with permissions that you do not want, then you will need to determine where the permissions are coming from. There should be a manifest merger report in build/outputs/apk/ of your module. It will be a bit difficult to understand, but hopefully you can identify the library that is contributing this permission. At that point, you need to decide how to proceed:

  • The safest answer that removes the permission is to no longer use that library, but instead find some other solution to whatever problem you are trying to solve with that library

  • Or, live with the permission

  • Or, try adding the following to your app's manifest:

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" tools:node="remove" />
    

This will require you to add xmlns:tools="http://schemas.android.com/tools" to the root <manifest> element if it is not already there. This will tell the build tools to explicitly exclude this permission, even though libraries are contributing it. However, your use of those libraries may break. Only do this if you have a dedicated testing team that can spend the time needed to ensure that your decision to block this permission will not result in crashes or other behavior that affects the user.

这篇关于机器人工作室运行在实际设备应用程序后,增加了不必要的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆