美文网首页Android开发Android知识Android技术知识
发布 APK 到 Google Play 之 uses-feat

发布 APK 到 Google Play 之 uses-feat

作者: 男子汉大豆腐 | 来源:发表于2016-09-24 13:46 被阅读544次

    在发布应用到 Google Play 之前有一个细节可能很多人会忽略,这就是 <uses-featrue> 的配置。

    什么是 <uses-featrue>

    所谓 <uses-featrue> 就是 Android 官方为发布到 Google Play 的程序建立的一套筛选机制。每一个 <uses-featrue> 都声明了对某种系统资源的硬性要求,在编译阶段,会自动根据我们程序中调用到的资源来添加。 Google Play 会读取 APK 文件信息中的 <uses-featrue>,当用户检索应用的时候,会自动过滤掉那些他们可能无法适用的应用程序。

    比如,我们的应用中某个地方使用到了蓝牙操作,编译时,Android 编译系统会自动在我们的 APK 文件信息中增加对蓝牙的 <uses-featrue> 声明,大概长这个样子:

     <uses-feature android:name="android.hardware.bluetooth" android:required="true" />
    

    如此,不具有蓝牙模块的设备在 Google Play 中检索应用时,将无法看到我们的应用。

    为什么我们需要去配置 <uses-featrue>

    前文说明了,默认状态下 <uses-featrue> 是自动生成了,所以看起来我们不需要去手动配置,但问题是编译系统其实没有那么智能,可以直接筛选出必要的设备需求,现实情况是只要我们程序中有引用到某种资源(可能这种资源并不是必要的),最终的 APK 信息中就会包含这种资源的 <uses-featrue> 声明。

    当然,我们希望我们的应用能有尽可能多的受众,所以发布到 Google Play 之前进行 <uses-featrue> 的配置,避免因为使用了某种不必要的资源被 Google Play 过滤掉,就显得有必要了。

    如何去配置 <uses-featrue>

    网上有很多介绍 <uses-featrue> 的文档,这里就不做搬运工了,本文只介绍如何查看 APK 文件的 <uses-featrue> 和配置方法。

    步骤一:查看 APK 文件的 <uses-featrue>>

    环境需要 : Android SDK

    我们需要使用 Android SDK 工具中的 aapt 工具,其路径一般是在:

    你的 SDK 路径\build-tools\对应编译工具版本目录\
    

    这个路径下有很多编译工具,我们用的 aapt 工具就在这里。

    找到后,切换到上述目录下,运行命令:

    aapt dump badging demo.apk
    

    将上面的 demo.apk 换成你的 APK 名字就可以了。回车执行命令后,会输入整个 APK 的信息,如下是微信的 APK 信息:

    package: name='com.tencent.mm' 
    versionCode='861' 
    versionName='6.3.25' 
    platformBuildVersionName='6.0-2704002'
    install-location:'auto'sdkVersion:'15'
    targetSdkVersion:'23'
    uses-permission: name='com.tencent.mm.plugin.permission.READ'
    uses-permission: name='com.tencent.mm.plugin.permission.WRITE'
    uses-permission: name='com.tencent.mm.permission.MM_MESSAGE'
    uses-permission: name='com.huawei.authentication.HW_ACCESS_AUTH_SERVICE'
    uses-permission: name='android.permission.ACCESS_NETWORK_STATE'
    uses-permission: name='android.permission.ACCESS_COARSE_LOCATION'
    uses-permission: name='android.permission.ACCESS_FINE_LOCATION'
    uses-permission: name='android.permission.CAMERA'
    uses-permission: name='android.permission.GET_TASKS'
    uses-permission: name='android.permission.INTERNET'
    uses-permission: name='android.permission.MODIFY_AUDIO_SETTINGS'
    uses-permission: name='android.permission.RECEIVE_BOOT_COMPLETED'
    uses-permission: name='android.permission.RECORD_AUDIO'
    uses-permission: name='android.permission.READ_CONTACTS'
    uses-permission: name='android.permission.READ_SMS'
    uses-permission: name='android.permission.VIBRATE'
    uses-permission: name='android.permission.WAKE_LOCK'
    uses-permission: name='android.permission.WRITE_EXTERNAL_STORAGE'
    uses-permission: name='android.permission.WRITE_CONTACTS'
    uses-permission: name='android.permission.WRITE_SETTINGS'
    uses-permission: name='com.android.launcher.permission.INSTALL_SHORTCUT'
    uses-permission: name='com.android.launcher.permission.UNINSTALL_SHORTCUT'
    uses-permission: name='com.android.launcher.permission.READ_SETTINGS'
    uses-permission: name='com.tencent.mm.location.permission.SEND_VIEW'
    uses-permission: name='android.permission.BLUETOOTH'
    uses-permission: name='android.permission.BLUETOOTH_ADMIN'
    uses-permission: name='android.permission.BROADCAST_STICKY'
    uses-permission: name='android.permission.SYSTEM_ALERT_WINDOW'
    uses-permission: name='android.permission.CHANGE_WIFI_STATE'
    uses-permission: name='android.permission.GET_PACKAGE_SIZE'
    uses-permission: name='android.permission.DOWNLOAD_WITHOUT_NOTIFICATION'
    uses-permission: name='android.permission.NFC'
    uses-permission: name='com.huawei.android.launcher.permission.CHANGE_BADGE'
    uses-permission: name='android.permission.WRITE_APP_BADGE'
    uses-permission: name='android.permission.ACCESS_WIFI_STATE'
    uses-permission: name='android.permission.READ_PHONE_STATE'
    uses-permission: name='com.tencent.mm.ext.permission.READ'
    uses-permission: name='com.tencent.mm.ext.permission.WRITE'
    uses-permission: name='com.android.vending.BILLING'
    uses-permission: name='android.permission.READ_EXTERNAL_STORAGE'
    uses-permission: name='com.android.alarm.permission.SET_ALARM'
    uses-permission: name='com.tencent.mm.wear.message'
    uses-permission: name='android.permission.BODY_SENSORS'
    uses-permission: name='android.permission.USE_CREDENTIALS'
    uses-permission: name='com.google.android.c2dm.permission.RECEIVE'
    uses-permission: name='android.permission.GET_ACCOUNTS'
    uses-permission: name='com.tencent.mm.permission.C2D_MESSAGE'
    uses-permission: name='android.permission.USE_FINGERPRINT'
    uses-permission: name='android.permission.MANAGE_ACCOUNTS'
    uses-permission: name='android.permission.AUTHENTICATE_ACCOUNTS'
    uses-permission: name='android.permission.READ_SYNC_SETTINGS'
    uses-permission: name='android.permission.WRITE_SYNC_SETTINGS'
    uses-permission: name='android.permission.READ_PROFILE
    'application-label:'WeChat'
    application-label-az-AZ:'WeChat'
    application-label-bn-BD:'WeChat'
    application-label-en:'WeChat'
    application-label-en-AU:'WeChat'
    application-label-en-GB:'WeChat'
    application-label-en-IN:'WeChat'
    application-label-es-US:'WeChat'
    application-label-et-EE:'WeChat'
    application-label-eu-ES:'WeChat'
    application-label-fa:'WeChat'
    application-label-fr-CA:'WeChat'
    application-label-gl-ES:'WeChat'
    application-label-gu-IN:'WeChat'
    application-label-hy-AM:'WeChat'
    application-label-is-IS:'WeChat'
    application-label-ka-GE:'WeChat'
    application-label-kk-KZ:'WeChat'
    application-label-km-KH:'WeChat'
    application-label-kn-IN:'WeChat'
    application-label-ky-KG:'WeChat'
    application-label-lo-LA:'WeChat'
    application-label-mk-MK:'WeChat'
    application-label-ml-IN:'WeChat'
    application-label-mn-MN:'WeChat'
    application-label-mr-IN:'WeChat'
    application-label-ms-MY:'WeChat'
    application-label-my-MM:'WeChat'
    application-label-ne-NP:'WeChat'
    application-label-pa-IN:'WeChat'
    application-label-pt-BR:'WeChat'
    application-label-pt-PT:'WeChat'
    application-label-si-LK:'WeChat'
    application-label-sq-AL:'WeChat'
    application-label-sr:'WeChat'
    application-label-sv:'WeChat'
    application-label-sw:'WeChat'
    application-label-ta-IN:'WeChat'
    application-label-te-IN:'WeChat'
    application-label-tl:'WeChat'
    application-label-uk:'WeChat'
    application-label-ur-PK:'WeChat'
    application-label-uz-UZ:'WeChat'
    application-label-zh-CN:'寰俊'
    application-label-zh-TW:'WeChat'
    application-label-zu:'WeChat'
    application-icon-120:'r/j/icon.png'
    application-icon-160:'r/j/icon.png'
    application-icon-213:'r/y/icon.png'
    application-icon-240:'r/y/icon.png'
    application-icon-320:'r/a0/icon.png'
    application-icon-480:'r/a2/icon.png'
    application-icon-640:'r/a2/icon.png'
    application: label='WeChat' 
    icon='r/j/icon.png'
    uses-library-not-required:'com.google.android.maps'
    uses-library-not-required:'com.sec.android.app.multiwindow'
    launchable-activity: name='com.tencent.mm.ui.LauncherUI' 
    label='WeChat' 
    icon=''
    uses-library-not-required:'com.here.android'
    feature-group: 
    label='' 
    uses-feature-not-required: name='android.hardware.bluetooth' 
    uses-feature-not-required: name='android.hardware.bluetooth_le' 
    uses-feature-not-required: name='android.hardware.camera' 
    uses-feature-not-required: name='android.hardware.camera.autofocus' 
    uses-feature-not-required: name='android.hardware.location' 
    uses-feature-not-required: name='android.hardware.location.gps' 
    uses-feature-not-required: name='android.hardware.location.network' 
    uses-feature-not-required: name='android.hardware.microphone' 
    uses-feature-not-required: name='android.hardware.telephony' 
    uses-feature-not-required: name='android.hardware.touchscreen' 
    uses-feature-not-required: name='android.hardware.wifi' 
    uses-feature: name='android.hardware.screen.portrait' 
    uses-implied-feature: name='android.hardware.screen.portrait' 
    reason='one or more activities have specified a portrait orientation'
    mainother-activitiesother-receiversother-services
    supports-screens: 'small' 'normal' 'large' 'xlarge'
    supports-any-density: 'true'locales: '--_--' 'az-AZ' 'bn-BD' 'en' 'en-AU' 'en-GB' 'en-IN' 'es-US' 'et-EE' 'eu-ES' 'fa' 'fr-CA' 'gl-ES' 'gu-IN' 'hy-AM' 'is-IS' 'ka-GE' 'kk-KZ' 'km-KH' 'kn-IN' 'ky-KG' 'lo-LA' 'mk-MK' 'ml-IN' 'mn-MN' 'mr-IN' 'ms-MY' 'my-MM' 'ne-NP' 'pa-IN' 'pt-BR' 'pt-PT' 'si-LK' 'sq-AL' 'sr' 'sv' 'sw' 'ta-IN' 'te-IN' 'tl' 'uk' 'ur-PK' 'uz-UZ' 'zh-CN' 'zh-TW' 'zu'
    densities: '120' '160' '213' '240' '320' '480' '640'
    native-code: 'armeabi' 'lib/'
    

    可以看到,下面的以 uses-feature 打头的信息就是了,发现没有,微信使用了很多uses-feature-not-required的声明,这就是我们接下来需要做的事情了。

    步骤二:声明不必要的资源

    如上面微信的那样,我们声明那些不必要的资源,告诉 Google Play 在不具备这些资源的设备上显示我们。

    经过步骤一,我们已经可以拿到自己应用的 APK 信息了,跟声明应用权限很类似,我们只需要在 Androidmainfest.xml 文件中声明对应不需要的信息为 false 就可以了,比如声明上面的蓝牙信息为不必要:

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

    这样再使用步骤一的命令查看应用信息,就会看到uses-feature-not-required: name='android.hardware.bluetooth' 了,如此没有蓝牙设备的用户就会在 Google Play 中看到我们了。

    相关文章

      网友评论

        本文标题:发布 APK 到 Google Play 之 uses-feat

        本文链接:https://www.haomeiwen.com/subject/qtexyttx.html