問(wèn)題描述
在設(shè)備上運(yùn)行應(yīng)用程序后,應(yīng)用程序需要清單文件中未提及的不需要的位置權(quán)限.而當(dāng)我從我的朋友 Android Studio 運(yùn)行相同的代碼時(shí),它的運(yùn)行正常而不需要額外的許可.
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.
清單文件
<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"
}
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 'com.google.android.gms:play-services:+'
compile 'com.android.support:multidex:1.0.0'
compile 'com.android.support:appcompat-v7:21.0.3'
}
所以我無(wú)法理解為什么它需要位置許可.如何在我的應(yīng)用中添加此位置權(quán)限?
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:+'
這個(gè)庫(kù)將請(qǐng)求位置權(quán)限,因?yàn)橛袔讉€(gè) Play Services 需要它.
This library will request location permissions, as several pieces of Play Services need it.
首先,永遠(yuǎn)不要使用+
.如果你想允許自由浮動(dòng)的補(bǔ)丁級(jí)別(例如,22.0.+
),這并不完全是瘋狂的,但是對(duì)于版本 is 使用 +
瘋了.
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.
接下來(lái),考慮使用一個(gè)(或多個(gè))更集中的依賴項(xiàng),而不是完整的 Play Services SDK.這不僅可能會(huì)消除您不想要的權(quán)限,而且您的 APK 會(huì)小很多.文檔涵蓋了可用選項(xiàng)(請(qǐng)參閱選擇性地將 API 編譯到可執(zhí)行文件中)" 部分).
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).
如果您仍然獲得不想要的權(quán)限,那么您需要確定權(quán)限的來(lái)源.您的模塊的 build/outputs/logs/
中應(yīng)該有一份清單合并報(bào)告.這將有點(diǎn)難以理解,但希望您能識(shí)別出提供此權(quán)限的庫(kù).此外,當(dāng)您編輯清單時(shí),Android Studio 2.2+ 將在子選項(xiàng)卡中顯示您的合并清單.2020-03-24 更新:現(xiàn)代版本的 Android Studio 還在清單編輯器的Merged Manifest"子選項(xiàng)卡中顯示這些內(nèi)容,并使用顏色編碼來(lái)嘗試向您展示權(quán)限的來(lái)源什么庫(kù).
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/logs/
of your module. It will be a bit difficult to understand, but hopefully you can identify the library that is contributing this permission. Also, Android Studio 2.2+ will show your merged manifest in a sub-tab when you edit your manifest. UPDATE 2020-03-24: Modern versions of Android Studio also show this stuff in the "Merged Manifest" sub-tab of the manifest editor, with color-coding to try to show you what permissions came from what libraries.
此時(shí),您需要決定如何進(jìn)行:
At that point, you need to decide how to proceed:
刪除權(quán)限的最安全答案是不再使用該庫(kù),而是為您嘗試使用該庫(kù)解決的任何問(wèn)題找到其他解決方案
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
或者,在許可下生活
或者,嘗試將以下內(nèi)容添加到您的應(yīng)用清單中:
Or, try adding the following to your app's manifest:
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"
tools:node="remove" />
這將要求您將 xmlns:tools="http://schemas.android.com/tools"
添加到根 <manifest>
元素,如果它還沒有.這將告訴構(gòu)建工具明確排除此權(quán)限,即使庫(kù)正在貢獻(xiàn)它.但是,您對(duì)這些庫(kù)的使用可能會(huì)中斷.僅當(dāng)您有一個(gè)專門的測(cè)試團(tuán)隊(duì)可以花費(fèi)所需的時(shí)間來(lái)確保您阻止此權(quán)限的決定不會(huì)導(dǎo)致崩潰或其他影響用戶的行為時(shí),才執(zhí)行此操作.
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.
這篇關(guān)于Android Studio 在真實(shí)設(shè)備上運(yùn)行應(yīng)用程序后添加了不需要的權(quán)限的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!