迁移到Android Studio - 现在我的应用会请求其他权限

时间:2016-02-02 22:54:19

标签: android eclipse android-studio android-permissions

我刚刚将应用程序从Eclipse迁移到Android Studio。我尝试导出已签名的APK并将其上传到Google Play只是为了检查一切是否正常。

那时我注意到我的应用程序现在请求两个额外的权限,除了我在清单中声明的​​权限!这两个权限是android.permission.WAKE_LOCKcom.google.android.c2dm.permission.RECEIVE

这里发生了什么?自上次上传应用程序以来,我没有更改任何代码,并且清单未声明这些权限。我猜一些谷歌组件对此负责,但为什么会这样,因为我迁移到Android Studio?我可以关闭这些权限吗?

我正在使用Google Play服务和Google AdMob,但是我很长时间没有这些权限就这样做了......

的manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.example.app"
      android:versionCode="70"
      android:versionName="7.0" >

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

    <uses-sdk 
        android:minSdkVersion="10"
        android:targetSdkVersion="23" />

    <application android:name="com.example.app.MyApplication"
                 android:icon="@mipmap/ic_launcher_icon" 
                 android:label="@string/app_name" 
                 android:allowBackup="true"
                 android:uiOptions="none">

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


        <activity android:name="com.example.app.MainActivity"
                  android:label="@string/app_name"
                  android:theme="@style/Theme.MyTheme.App"
                  android:windowSoftInputMode="adjustPan" >

                    <intent-filter>
                        <action android:name="android.intent.action.MAIN" />
                        <category android:name="android.intent.category.LAUNCHER" />
                    </intent-filter>
        </activity>

        <activity           
            android:name="com.example.app.OtherActivity"
            android:label="@string/otherActivityTitle"
            android:theme="@style/Theme.MyTheme.App"
            android:parentActivityName="com.example.app.MainActivity" >

            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.app.MainActivity" />                                 
        </activity>                     

        <activity
            android:name="com.example.app.PreferencesActivity"
            android:label="@string/prefsTitle" >            
        </activity>                     

        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />


    </application>
</manifest>

以下是使用Android Studio构建的APK的屏幕截图:

enter image description here

我无法将语言更改为英语,但它基本上表示它现在支持22个较少的设备,需要2个新权限并使用OpenGL 2.0+而不是1.0 +。

以下是使用Eclipse构建的相同APK的屏幕截图:

enter image description here

2 个答案:

答案 0 :(得分:1)

经过一些搜索后,我在Stackoverflow上找到了这个帖子:Android Studio adds unwanted permission after running application on real device

其中一个答案(不是被接受的答案)解决了我的问题。似乎Android Studio导入过程将此依赖项添加到我的build.gradle

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

将其更改为

compile 'com.google.android.gms:play-services-base:8.4.0' // Needed for API Availability test
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'

APK不再请求不需要的权限,它会像以前一样使用相同的设备,并使用与以前相同的OpenGL版本 - 即一切都像Eclipse一样回归!除了现在APK的文件大小小1 MB作为额外的奖金!

对于将来访问此处的人,您可能需要调查应在Gradle, please和/或Setting up Google Play Services使用的Google Play服务版本号。

答案 1 :(得分:0)

将其更改为:

android:targetSdkVersion="22"