接入Google drive的开发过程
- 开始
- 关键词
- 参考资料
- 步骤1
- 步骤2
- 步骤3
开始
一开始是在使用Android studio编译的apk里面接入Google drive,后来由于公司在系统源码环境编译的apk也需要接入apk,对于两次开发做一次记录。
关键词
Google drive, Android studio, Android系统源码,aar
参考资料
Google driver 开发API :https://developers.google.com/drive/
说明文档:https://developers.google.com/drive/android/intro
官方demo下载地址:https://github.com/googledrive/android-demos
maven地址:https://mvnrepository.com/artifact/com.google.android.gms
Android.mk引用aar:https://www.jianshu.com/p/63715928063b
步骤1
不管是Android studio编译还是Android 源码编译都需要登录谷歌开发平台获取API,网址是https://console.developers.google.com/
依次点击“凭据”-“创建凭据”-“OAuth客户端ID”
填入正确信息后创建。
步骤2
- 使用Android studio编译:
在build.gradle(app)里面加入引用包
//google auth 验证
implementation 'com.google.android.gms:play-services-auth:11.6.0'
//google drive
implementation 'com.google.android.gms:play-services-drive:11.6.0'
接着参考https://github.com/googledrive/android-demos官方demo使用接口即可。
- 使用源码编译:
需要到maven里面下载相应的aar包(当初这里尝试找了很久,不清楚到底用哪个)具体需要下载哪个包可以参考Android studio编译的External Libraries
红色框的都是需要自己去maven(网址:https://mvnrepository.com/artifact/com.google.android.gms)下载的。
下载好后,放在需要在系统编译的apk的libs文件夹下,然后编写Android.mk文件
LOCAL_STATIC_JAVA_AAR_LIBRARIES := play-services-auth_aar \
play-services-auth-api-phone_aar \
play-services-auth-base_aar \
play-services-base_aar \
play-services-basement_aar \
play-services-drive_aar \
play-services-tasks_aar
LOCAL_AAPT_FLAGS := \
--rename-manifest-package com.settings.istv811 \
--auto-add-overlay \
--extra-packages com.google.android.gms
include frameworks/opt/setupwizard/library/common-gingerbread.mk
include frameworks/base/packages/SettingsLib/common.mk
#include device/hisilicon/bigfish/appIst/CommonLib/Commonlib/cuslib/common.mk
include $(BUILD_PACKAGE)
include $(CLEAR_VARS)
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := play-services-auth_aar:app/libs/play-services-auth-11.6.0.aar \
play-services-auth-api-phone_aar:app/libs/play-services-auth-api-phone-11.6.0.aar \
play-services-auth-api-phone-license_aar:app/libs/play-services-auth-api-phone-license-11.6.0.aar \
play-services-auth-base_aar:app/libs/play-services-auth-base-11.6.0.aar \
play-services-auth-base-license_aar:app/libs/play-services-auth-base-license-11.6.0.aar \
play-services-base_aar:app/libs/play-services-base-11.6.0.aar \
play-services-base-license_aar:app/libs/play-services-base-license-11.6.0.aar \
play-services-basement_aar:app/libs/play-services-basement-11.6.0.aar \
play-services-basement-license_aar:app/libs/play-services-basement-license-11.6.0.aar \
play-services-drive_aar:app/libs/play-services-drive-11.6.0.aar \
play-services-drive-license_aar:app/libs/play-services-drive-license-11.6.0.aar \
play-services-tasks_aar:app/libs/play-services-tasks-11.6.0.aar \
play-services-tasks-license_aar:app/libs/play-services-tasks-license-11.6.0.aar \
include $(BUILD_MULTI_PREBUILT)
使用LOCAL_STATIC_JAVA_LIBRARIES 要引入的jar定义一个变量名。
使用LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES 给定义的变量 设置一个引用路径
这两个对应的是关键代码
在androidmianfest.xml加上(xxx写上具体的数字)
<uses-sdk android:minSdkVersion='xxx' />
<uses-sdk android:targetSdkVersion='xxx' />
步骤3
接下来就是参考谷歌demo来使用接口编写自己的代码了
Google drive 接口demo:https://github.com/googledrive/android-demos