2015-06-04 41 views
7

我剛剛發佈了一個在其清單文件中具有兩個權限的應用程序(用於顯示橫幅廣告)。 「android.permission.INTERNET」和「android.permission.ACCESS_NETWORK_STATE」。爲了測試,我試圖從遊戲市場安裝我的應用程序,發現應用程序需要身份,位置,照片/媒體/文件!在我的清單文件中沒有這樣的權限,我不需要它們。嘗試使用類似的manifest.xml(互聯網,網絡狀態)我的其他應用程序,他們正在安裝沒有任何特殊的權限。 考慮到新的內容評級證書系統,我可能會遇到問題,因爲在問卷中,我標記了不需要用戶位置。 爲什麼它需要我沒有問的權限? 我使用過Android Studio和的build.gradle:用戶獲取未包含在清單中的權限請求

android { 
    compileSdkVersion 22 
    buildToolsVersion "22.0.1" 

    defaultConfig { 
     applicationId "com.appName" 
     minSdkVersion 15 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled true 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

repositories { 
    maven { 
     url "https://jitpack.io" 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.github.PhilJay:MPAndroidChart:v2.1.0' 
    compile 'com.melnykov:floatingactionbutton:1.3.0' 
    compile 'com.mcxiaoke.volley:library:1.0.+' 
    compile 'com.nispok:snackbar:2.10.2' 
    compile 'com.android.support:cardview-v7:22.2.0' 
    compile 'com.android.support:recyclerview-v7:22.2.0' 
    compile 'uk.co.chrisjenx:calligraphy:2.1.0' 
    compile 'com.google.android.gms:play-services:7.5.0' 
    compile 'com.android.support:appcompat-v7:22.2.0' 
    compile 'com.github.markushi:android-ui:1.2' 
    compile 'com.afollestad:material-dialogs:0.7.3.1' 
} 

的Manifest.xml

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      package="com.AppPackage" > 

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

    <application 
     android:name=".MyApplication" 
     android:allowBackup="true" 
     android:icon="@mipmap/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" 
     > 
     <activity 
      android:name=".MainActivity" 

      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <activity 
      android:name="com.google.android.gms.ads.AdActivity" 
      android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" /> 

     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 

     <activity android:name=".Prefs_Activity" > 
     </activity> 
     <activity 
      android:name=".Guide_Activity" 
      android:label="@string/title_activity_" > 
     </activity> 
     <activity 
      android:name=".Picker_Activity" 
      android:label="@string/title_activity_" > 
     </activity> 
    </application> 

</manifest> 

更新:

由於CommonsWare的答案我已經找到「清單合併釋放-report.txt「,以及誰使用這些權限。這些是地圖和錢包API。 我從這裏分開播放業務:

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

這(我需要現在):

compile 'com.google.android.gms:play-services-analytics:7.5.0' 
    compile 'com.google.android.gms:play-services-plus:7.5.0' 
    compile 'com.google.android.gms:play-services-ads:7.5.0' 
    compile 'com.google.android.gms:play-services-appindexing:7.5.0' 

結果:

  • 去除不必要的權限
  • APK縮小高達500kb
  • 開始重視API分離

Play Market apk update screenshot

+0

您使用哪種橫幅廣告sdk?也許該SDK是問題,並添加額外的權限 – itay83

+0

我使用AdMob顯示橫幅 – despecher

+0

您是否使用了一些第三方庫?你在使用AndroidStudio還是Eclipse?如果您是基於gradle的,請發佈應用程序模塊gradle文件和清單。看起來你的清單在打包時與包含這個權限的清單合併在一起。 –

回答

8

爲什麼它需要我沒問權限?

因爲您正在加載11個庫,並且其中一個或多個需要這些權限。尤其是,您正在加載com.google.android.gms:play-services,並且它需要很多權限。例如,Play服務具有融合的位置API和Google地圖,兩者都需要位置數據。

清單合併報告應寫入您的項目或模塊的build/outputs/apk/(例如,傳統Android Studio項目中的app/)。您可以使用它來嘗試確定附加權限的來源。然後,停止使用這些庫,或切換到別的東西。在播放服務的情況下,而不是加載全部播放服務,只加載您需要的部分。這包括在the documentation中(請參閱「選擇性地將API編譯到可執行文件」一節中)。