問題描述
在設備上運行應用程序后,應用程序需要清單文件中未提及的不需要的位置權限.而當我從我的朋友 Android Studio 運行相同的代碼時,它的運行正常而不需要額外的許可.
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'
}
所以我無法理解為什么它需要位置許可.如何在我的應用中添加此位置權限?
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:+'
這個庫將請求位置權限,因為有幾個 Play Services 需要它.
This library will request location permissions, as several pieces of Play Services need it.
首先,永遠不要使用+
.如果你想允許自由浮動的補丁級別(例如,22.0.+
),這并不完全是瘋狂的,但是對于版本 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.
接下來,考慮使用一個(或多個)更集中的依賴項,而不是完整的 Play Services SDK.這不僅可能會消除您不想要的權限,而且您的 APK 會小很多.文檔涵蓋了可用選項(請參閱選擇性地將 API 編譯到可執行文件中)" 部分).
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).
如果您仍然獲得不想要的權限,那么您需要確定權限的來源.您的模塊的 build/outputs/logs/
中應該有一份清單合并報告.這將有點難以理解,但希望您能識別出提供此權限的庫.此外,當您編輯清單時,Android Studio 2.2+ 將在子選項卡中顯示您的合并清單.2020-03-24 更新:現代版本的 Android Studio 還在清單編輯器的Merged Manifest"子選項卡中顯示這些內容,并使用顏色編碼來嘗試向您展示權限的來源什么庫.
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.
此時,您需要決定如何進行:
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, 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>
元素,如果它還沒有.這將告訴構建工具明確排除此權限,即使庫正在貢獻它.但是,您對這些庫的使用可能會中斷.僅當您有一個專門的測試團隊可以花費所需的時間來確保您阻止此權限的決定不會導致崩潰或其他影響用戶的行為時,才執行此操作.
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.
這篇關于Android Studio 在真實設備上運行應用程序后添加了不需要的權限的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!