Android 第三方ROM定制之适配谷歌Play Store

本篇博客仅适用于Android第三方ROM定制的开发者单独适配Google框架服务套件。

众所周知,Android系统发展至今一大特色就是碎片化,各厂商也有自己单独定制的ROM,Google为了支持这些厂商的设备,Google的框架服务套件也有很多不同的版本,那么怎么正确的选择自己的定制设备Play Store呢?这就是这篇博客要讲的内容!

一、Google 服务套件包含哪些:
有过平板或者手机定制的经验的同学就应该经常会预制GMS包到源码中,我们看正常的过GMS认证项目的源码里面的gms.mk文件编译了这些APK

# GMS mandatory core packages
PRODUCT_PACKAGES := \
    ConfigUpdater \
    GoogleBackupTransport \
    GoogleExtServices \
    GoogleExtShared \
    GoogleFeedback \
    GoogleLoginService \
    GoogleOneTimeInitializer \
    GooglePackageInstaller \
    GooglePartnerSetup \
    GooglePrintRecommendationService \
    GoogleServicesFramework \
    GoogleCalendarSyncAdapter \
    GoogleContactsSyncAdapter \
    GoogleTTS \
    GmsCore \
    Phonesky \
    SetupWizard \
    talkback \
    WebViewGoogle

其中Google服务的套件就是这四个apk了,如果在其他的海外版方案中(机顶盒,TV)要使用Play Store,但又不需要过GMS认证那么单独预制这几个apk就好了。

GoogleLoginService \ GoogleServicesFramework \ GmsCore \ Phonesky

二、下载的网站

推荐下面的这四个网站,不用翻墙可以直接下载,而且历史版本很全。
https://www.apkmirror.com/
https://apkpure.com/
https://www.androidapksfree.com/
https://www.apkmonk.com/

三、你的项目对应哪个版本的Google套件apk ?

这里面GmsCore.apk在应用市场的名字是GooglePlayService.apk,Phonesky.apk是PlayStore.apk,其实包名是一样的,只不过gms包中的名字有点不同。
在你适配的时候可能会遇到打开Play Store直接弹框报错:
This version of the app isn't compatible with your device.To fix this problem,go to Settings and uninstall updates for the Google Play Store app.
这就是版本和你的方案没有匹配上的原因了。
首先:
GoogleLoginService 是用于账号登录的,这个apk只需要下载一个最新的能支持你系统版本的就可以了,注意需要区分Phone版的和TV版的。
GoogleServicesFramework 是Google的框架服务apk,这个apk 的版本很少,选一个你系统对应的版本就好。
GooglePlayStore 这个是Google商店应用,下载一个最新的能支持你系统版本的就可以了,注意需要区分Phone版的和TV版的。
GooglePlayService 这个是Google的核心服务,也是衍生版本最多的一个apk,需要重点去了解怎么适配。如果适配错了可能就直接报上名那个错了。

我们看下载的网站给了这个说明:
**To figure out the right version of Google Play services for your Android device, download Play Services info or go to Settings -> Apps -> Google Play services, and look at the 3-digit sequence (let’s use XYZ) in the parentheses:
* X defines Android version:
0 for Android <5.0
2 for Android 5.0 and 5.1 starting with Play Services v8
4 for Android 5.0 and 5.1 before Play Services v8, Android >= 6.0 after
5 for Android Wear
7 for Android 5.0
8 for Android TV
9 for Android 8.0+
* Y defines CPU architecture:
1 for armeabi
3 for armeabi-v7a
4 for arm64-v8a
5 for mips
7 for x86
8 for x86_64
* Z defines DPI:
0 for universal nodpi
2 for 160
4 for 240
6 for 320
8 for 480
Notes:
It seems that 7YZ builds became 4YZ with Google Play services v6.5. If you were on 7YZ before, you should now install 4YZ.
It seems that 4YZ builds got split into 2YZ for Lollipop and 4YZ for Marshmallow with Google Play services v8. If you were on 4YZ before, you should now install 2YZ in Lollipop and 4YZ in Marshmallow.
Examples:
014 for Android <5.0 armeabi CPU 240 DPI device
438 for Android 6.0+ armeabi-v7a CPU 480 DPI device
876 for Android TV x86 CPU 320 DPI device
940 for Android 8.0+ arm64 CPU nodpi device**

这里写图片描述
我们看网站上面的Play Service 的版本号数字的前三位有很多种组合,组合的规则就是上面英文讲的那样。如果你是TV版的设备,直接搜索Google Play Service TV 就好了。根据自己的系统版本,cup架构和dpi确定要下载的版本,比如说是030,代表5.0系统以下,armeabi-v7a架构,通用的dpi,那就在030的大分支版本种找一个最新的就好了。

四、adb调试的小技巧
在debug版本的设备中我们可以直接用adb命令去预制Google套件apk。我们一般将这四个apk预制到priv-app下,这样获得的权限较高。
我们可以使用下面的脚本去执行
mount -o remount,rw /system
cp -f /system/googleapps/*.apk /system/priv-app/
sync
chmod 644 /system/priv-app/*.apk
或者直接挂载上system分区,然后将apk push到priv-app下,注意lib库也要一同拷贝过去,最后使用chmod命令给apk读写权限,这一步很重要。

五、其他的问题

6.0以上系统我们在预制的时候可能需要给apk运行时权限,直接修改PackageManageService,给这个包名的apk全部的运行时权限就好了。

diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 65ae245..dbc9d94 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -8708,7 +8708,12 @@ public class PackageManagerService extends IPackageManager.Stub {
if (DEBUG_INSTALL) {
Log.i(TAG, "Package " + pkg.packageName + " granting " + perm+" grant "+grant);}
+ //sprd modify for com.aponline.sims
+ if (pkg.packageName.equals("com.aponline.sims") && perm.equals("android.permission.READ_PHONE_STATE")) {
+ Log.w(TAG, "Package " + pkg.packageName + " is granting " + perm+":GRANT_INSTALL");
+ grant = GRANT_INSTALL;
+ }
+ //sprd modify for com.aponline.sims
if (grant != GRANT_DENIED) {
if (!isSystemApp(ps) && ps.installPermissionsFixed) {
// If this is an existing, non-system package, then

以上是对Play Store适配的总结,如果大家还有问题的话,欢迎留言交流,如果有错误的地方也欢迎指出

猜你喜欢

转载自blog.csdn.net/An_Times/article/details/80158110