一、项目需求:
在项目中导入Google框架,Google相关功能可以正常使用。
二、功能实现:
1、首先下载Google框架GMS包,可以在The Open GApps Project网站下载。选择相关配置后下载即可,有些包比较大,下载需要耐心等待一下,最好用外网下载会快一些。
2、由于本人使用的TV平台,Google版本需要使用手机版,不能使用TV版,因为TV版很多apk在Google商店中无法搜索到。修改mtv_core_hardware.xml文件,把TV版改成手机版。有多个路径:device/google/atv/permissions/tv_core_hardware.xml ,vendor/mediatek/common-tv/configs/mtv_core_hardware.xml,vendor/mediatek/proprietary_tv/open/common/preinstall/permission/mtv_core_hardware.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2011 The Android Open Source ProjectLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
--><!-- This is the minimum set of features supported by TV devices. -->
<permissions><feature name="android.hardware.type.television" /><!--feature name="android.hardware.faketouch" /--><feature name="android.hardware.screen.landscape" /><!--feature name="android.hardware.microphone" /--><feature name="android.hardware.usb.host" /><!--feature name="android.hardware.usb.accessory" /--><library name="com.android.future.usb.accessory"file="/system/framework/com.android.future.usb.accessory.jar" /><!-- <feature name="android.hardware.camera.any" /> --><!--<feature name="android.hardware.camera.front" />--><!-- <feature name="android.hardware.camera" /><feature name="android.hardware.camera.autofocus" /><feature name="android.hardware.camera.flash" /> --><feature name="android.hardware.wifi" /><feature name="android.hardware.wifi.direct" /><feature name="android.hardware.ethernet" /><feature name="android.software.app_widgets" /><feature name="android.software.input_methods" /><feature name="android.software.backup" /><!-- <feature name="android.software.leanback" /> TV版打开,手机版关闭--><feature name="android.software.voice_recognizers" /><feature name="android.software.cant_save_state" /><!-- Let Netflix show up on Google Play /--><feature name="nrdp.modelgroup" />
</permissions>
3、由于Google GMS包比较大,打包会占用很大空间。所以分区需要加大,具体加多少需要根据自己打包的内容而定。修改文件device/mediatek/xxxxx/BoardConfig.mk
include $(DEVICE_SOURCES)/BoardConfigCommon.mk# Change on this file should go below this line
# -----------------------------------------------------------------------TARGET_BOOTLOADER_BOARD_NAME := $(TARGET_PRODUCT)
BOARD_KERNEL_CMDLINE += androidboot.boot_devices=mstar_mci.0ifeq ($(findstring true, $(FILE_BASED_ENCRYPTION) $(AB_UPDATE_ENABLE)), true)
# Android UserData Checkpoint (UDC)
BOARD_USES_METADATA_PARTITION := true
BOARD_ROOT_EXTRA_FOLDERS += /metadata
endif# mmc part
#index: type name (size)
# 1: MBOOT (5.000M)
# 2: MPOOL (3.000M)
# 3: MBOOTB (5.000M)
# 4: tvcertificate (8.000M)
# 5: eeprom_a (1.000M)
# 6: tvconfig (32.000M)
# MTK_DATA_SEPARATION=true
# 7: cusdata (150.000M)
# 8: project_id (5.000M)
# 9: misc (1.000M)
#AVB enable
# 10: vbmeta (1.000M)
# 11: recovery (40.000M)
#12: boot (40.000M)
#13: optee (18.000M)
#14: armfw (1.000M)
#15: RTPM (1.000M)
#16: dtb (1.000M)
#AVB enable
#17: dtbo (8.000M)
#18: metadata (16.000M)
#19: frc (1.000M)
#20: linux_rootfs_a (50.000M)
#21: basic_a (1.000M)
#22: 3rd_a (30.000M)
#23: 3rd_rw (30.000M)
#24: vbmeta_a (1.000M)
#25: ciplus (1.000M)
#26: dvbsdb_a (1.000M)
#27: cha (1.000M)
#28: chb (1.000M)
#29: upgrade (112.000M)
#30: schedpvr (1.000M)
#31: cm4 (1.000M)
#32: demura (3.000M)
#33: factory_a (5.000M)
#
# ANDROID_DYNAMIC_PARTITION_SUPPORT=false
#
#34: system (1.464G)
#35: vendor (327.000M)
#36: product (300.00M)
#37: odm_a (1.000M)
#38: cache (100.000M)
#39: tvservice (130.000M)
#40: factory_a (1.000M)
#41: userdata (3.993G)or(4.082G for dtv_svc debug)# ANDROID_DYNAMIC_PARTITION_SUPPORT=true
#
#34: super (2122.000M)
#35: odm_a (1.000M)
#36: cache (100.000M)
#37: tvservice (130.000M)
#38: factory_a (1.000M)
#39: userdata (3.993G)or(4.082G for dtv_svc debug)BOARD_MBOOTIMAGE_PARTITION_SIZE := 5242880 #0x000500000
BOARD_VBMETAIMAGE_PARTITION_SIZE := 65536
BOARD_TVCERTIFICATEIMAGE_PARTITION_SIZE := 8388608
BOARD_TVCONFIGIMAGE_PARTITION_SIZE := 33554432
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 41943040
BOARD_BOOTIMAGE_PARTITION_SIZE := 41943040
BOARD_OPTEEIMAGE_PARTITION_SIZE := 18874368
BOARD_ARMFWIMAGE_PARTITION_SIZE := 1048576
BOARD_RTPMIMAGE_PARTITION_SIZE := 1048576
BOARD_DTBIMAGE_PARTITION_SIZE := 1048576
BOARD_DTBOIMG_PARTITION_SIZE := 8388608
#BOARD_METADATAIMAGE_PARTITION_SIZE := 16777216
BOARD_FRCIMAGE_PARTITION_SIZE := 1048576ifeq ($(findstring true, $(FILE_BASED_ENCRYPTION) $(AB_UPDATE_ENABLE)), true)
BOARD_METADATAIMAGE_PARTITION_SIZE := 16777216
endif# for AB Update
ifeq "$(BOARD_USES_RECOVERY_AS_BOOT)" "true"
BOARD_BOOTIMAGE_PARTITION_SIZE := $(BOARD_RECOVERYIMAGE_PARTITION_SIZE)
BOARD_RECOVERYIMAGE_PARTITION_SIZE :=
endififneq "$(DDI_SUPPORT)" "true"
BOARD_APOLLO_EEPROM_PARTITION_SIZE := 1048576
ifeq "$(DTV_SVC_DBG)" "true"
BOARD_APOLLO_LINUXROOTFS_PARTITION_SIZE := 209715200
BOARD_APOLLO_3RD_PARTITION_SIZE := 209715200
else
BOARD_APOLLO_LINUXROOTFS_PARTITION_SIZE := 52428800
BOARD_APOLLO_3RD_PARTITION_SIZE := 31457280
endif
BOARD_APOLLO_3RD_RW_PARTITION_SIZE := 31457280
BOARD_APOLLO_VBMETA_PARTITION_SIZE := 1048576
BOARD_APOLLO_CHANNELA_PARTITION_SIZE := 1048576
BOARD_APOLLO_CHANNELB_PARTITION_SIZE := 1048576
BOARD_APOLLO_FACTORY_PARTITION_SIZE := 5242880#BOARD_APOLLO_ODM_PARTITION_SIZE := 1048576
ifneq "$(MODEL_REGION)" "cn"
BOARD_APOLLO_CIPLUS_PARTITION_SIZE := 1048576
BOARD_APOLLO_DVBSDB_PARTITION_SIZE := 1048576
BOARD_APOLLO_SCHEDPVR_PARTITION_SIZE := 1048576
endif
#endof DDI_SUPPORT
endif
#ifeq "$(MTK_DATA_SEPARATION)" "true"
#BOARD_PROJECT_ID_PARTITION_SIZE := 5242880 #0x000500000
#BOARD_CUSDATA_PARTITION_SIZE := 157286400 #0x009600000
#endif
#USERDATAIMAGE Size == EMMC Size - ALL PARTITION SIZE
#when mboot set CONFIG_USERDATA_PARTITION_SELF_ADAPTION=y USERDATAIMAGE will self-adaption
#ifeq "$(MTK_DATA_SEPARATION)" "true"
#ifeq "$(DTV_SVC_DBG)" "true"
#BOARD_USERDATAIMAGE_PARTITION_SIZE := 4232052736
#else
#BOARD_USERDATAIMAGE_PARTITION_SIZE := 4462739456
#endif
#else
ifeq "$(DTV_SVC_DBG)" "true"
BOARD_USERDATAIMAGE_PARTITION_SIZE := 4394582016
else
BOARD_USERDATAIMAGE_PARTITION_SIZE := 4625268736
endif
#endif
BOARD_APOLLO_UPGRADE_PARTITION_SIZE := 209715200
BOARD_CM4IMAGE_PARTITION_SIZE := 1048576
BOARD_DEMURAIMAGE_PARTITION_SIZE := 3145728
BOARD_TVSERVICEIMAGE_PARTITION_SIZE := 146800640
BOARD_CACHEIMAGE_PARTITION_SIZE := 104857600
ifeq "$(ANDROID_DYNAMIC_PARTITION_SUPPORT)" "true"
# For non-A/B devices and retrofit A/B devices,
# the sum of maximum sizes of all groups must be:
# BOARD_SUPER_PARTITION_SIZE - overhead
# Overhead is required in the computation to account for metadata, alignments,
# and so on. A reasonable overhead is 4 MiB, but you can pick a larger overhead as needed by the device.
#BOARD_SUPER_PARTITION_SIZE 2254438400 1024*1024 = 2097152 *2 =4194304 + 2254438400= 2258632704
#BOARD_GROUP_OEM_SIZE 2250244096 + 4194304 = 2588532736
BOARD_SYSTEMIMAGE_PARTITION_RESERVED_SIZE := 52428800
BOARD_VENDORIMAGE_PARTITION_RESERVED_SIZE := 52428800
BOARD_SUPER_PARTITION_SIZE := 2778726400
BOARD_SUPER_PARTITION_GROUPS := group_oem
BOARD_GROUP_OEM_SIZE := 2774532096
BOARD_GROUP_OEM_PARTITION_LIST := system vendor
else
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1572864000
BOARD_VENDORIMAGE_PARTITION_SIZE := 367001600
BOARD_PRODUCTIMAGE_PARTITION_SIZE := 314572800
endifBOARD_FLASH_BLOCK_SIZE := 512
4、把下载好的GMS包放到目录下vendor/partner_gms/
5、在文件中添加Google编译:device/mediatek/xxxx/device.mk,添加以下代码即可。
#***************************************Google play************************************
#add by jude for google play service
$(call inherit-product-if-exists, vendor/partner_gms/products/gms_tv.mk)
#***************************************Google play************************************
添加以上修改之后,编译出ROM之后可以正常打开Google商店等应用。
三、遇到问题:
在登录Google账号时,一直提示“您的账号未成功添加,请重试!”。遇到这问题时,一开始以为账号有问题,但在windows下可以正常使用。然后怀疑是不是apk版本问题,替换多版后还是无法解决。
四、解决方案:
1、在替换Google 商店、Google服务等apk后,发现还是一样的问题,排除apk版本问题。
2、通过修改权限也无法解决该问题。
3、最后发现跟设备认证有关,通过外网手动注册设备后,发现问题解决。为什么需要设备认证,官方解释如下。
4、手动认证可以,代码如何自动认证呢?方法如下就是需要修改fingerprint相关属性。首先修改build/make/core/Makefile文件中的BUILD_FINGERPRINT,BUILD_FINGERPRINT的格式是组合起来的。相关文件:build\make\core\version_defaults.mk
........
........
........
# The string used to uniquely identify the combined build and product; used by the OTA server.
ifeq (,$(strip $(BUILD_FINGERPRINT)))ifeq ($(strip $(HAS_BUILD_NUMBER)),false)BF_BUILD_NUMBER := $(BUILD_USERNAME)$$($(DATE_FROM_FILE) +%m%d%H%M)elseBF_BUILD_NUMBER := $(file <$(BUILD_NUMBER_FILE))endif#add by jude for google play_BRAND := MediaTek_PRODUCT := m7332_eu_DEVICE := m7332_eu#_BUILD_NUMBER := eng.$(shell echo $${BUILD_USERNAME:0:6}).$(shell $(DATE) +%Y%m%d.%H%M%S)BUILD_FINGERPRINT := $(_BRAND)/$(_PRODUCT)/$(_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)#BUILD_FINGERPRINT := $(PRODUCT_BRAND)/$(TARGET_PRODUCT)/$(TARGET_DEVICE):$(PLATFORM_VERSION)/$(BUILD_ID)/$(BF_BUILD_NUMBER):$(TARGET_BUILD_VARIANT)/$(BUILD_VERSION_TAGS)#add end
endif
# unset it for safety.
BF_BUILD_NUMBER :=........
........
........
然后还得修改system\core\init\property_service.cpp文件中的property_derive_build_fingerprint函数,ro.build.fingerprint前面的内容需要跟BUILD_FINGERPRINT中的保持一致。
// If the ro.build.fingerprint property has not been set, derive it from constituent pieces
static void property_derive_build_fingerprint() {std::string build_fingerprint = GetProperty("ro.build.fingerprint", "");if (!build_fingerprint.empty()) {return;}const std::string UNKNOWN = "unknown";build_fingerprint = "MediaTek";//GetProperty("ro.product.brand", UNKNOWN);//add by judebuild_fingerprint += '/';build_fingerprint += "m7332_eu";//GetProperty("ro.product.name", UNKNOWN);build_fingerprint += '/';build_fingerprint += "m7332_eu";//GetProperty("ro.product.device", UNKNOWN);build_fingerprint += ':';build_fingerprint += GetProperty("ro.build.version.release", UNKNOWN);build_fingerprint += '/';build_fingerprint += GetProperty("ro.build.id", UNKNOWN);build_fingerprint += '/';build_fingerprint += GetProperty("ro.build.version.incremental", UNKNOWN);build_fingerprint += ':';build_fingerprint += GetProperty("ro.build.type", UNKNOWN);build_fingerprint += '/';build_fingerprint += GetProperty("ro.build.tags", UNKNOWN);LOG(INFO) << "Setting property 'ro.build.fingerprint' to '" << build_fingerprint << "'";std::string error;uint32_t res = PropertySet("ro.build.fingerprint", build_fingerprint, &error);if (res != PROP_SUCCESS) {LOG(ERROR) << "Error setting property 'ro.build.fingerprint': err=" << res << " (" << error<< ")";}
}
通过以上修改,问题得到最终解决。