google 对于android studio使用gradle集成Google Analytics,并提供插件
com.google.gms:google-services进行打包,这使得用Makefile集成的方式有些困难,
一下是对Android.mk方式构建项目集成google analytics进行总结.
首先在android studio 导入google 提供的daemon,地址是git clone https://github.com/googlesamples/google-services.git
可以对daemon进行测试,之后找到google-service插件.位置是{$GRADLE_HOME}/caches/modules-2/files-2.1/com.google.gms/google-services/3.0.0/ee538ce9cf4148485e43017c5542202b8c78ff8e/google-services-3.0.0.jar //换成你的版本
反编译发现里面提供了个gradle插件,用groovy写的,语法很简单,导入android studio会自动反编译.
这个插件大概的任务就是在你的项目app/build/generated/res/google-service下面创建两个resource文件,供aapt打包,这两个文件分别是
values/values.xml xml/grobal_tracker.xml (这两个文件是解析app/google-services.json生成的)
之后你可以将你的daemon名字改成你自己的项目包名,将你的google-services.json放在app下面,然后点击as的build
去相应的目录想找到这两个xml文件,放到对应的用于make构建的项目的res文件夹(名字自己定,文件夹要放对).
这样aapt就可以打包这两个资源了. 这才刚刚完成了一小步. 之所以告诉你看插件,是因为这个插件的功能可能会增加,
另外你也可以根据插件写个shell脚本,在make的时候做同样的事情.
接着上一步,你按下build的时候在android的gradle console下面会打印刚才打包过程的log.有两种情况
1 你可能使用gms上报你的数据,那么你的app/build.gradle 有
apply plugin: ‘com.google.gms.google-services’ 这样一条代码,这时候你的应用里面就会将freebase的包也打包到应用里面,对应的gradlelog如下
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2520Library
:app:prepareComAndroidSupportAppcompatV72520Library
:app:prepareComAndroidSupportSupportCompat2520Library
:app:prepareComAndroidSupportSupportCoreUi2520Library
:app:prepareComAndroidSupportSupportCoreUtils2520Library
:app:prepareComAndroidSupportSupportFragment2520Library
:app:prepareComAndroidSupportSupportMediaCompat2520Library
:app:prepareComAndroidSupportSupportV42520Library
:app:prepareComAndroidSupportSupportVectorDrawable2520Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics1020Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1020Library
:app:prepareComGoogleAndroidGmsPlayServicesBase1020Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement1020Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1020Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks1020Library
:app:prepareComGoogleFirebaseFirebaseAnalytics1020Library
:app:prepareComGoogleFirebaseFirebaseAnalyticsImpl1020Library
:app:prepareComGoogleFirebaseFirebaseCommon1020Library
:app:prepareComGoogleFirebaseFirebaseCore1020Library
:app:prepareComGoogleFirebaseFirebaseIid1020Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
Parsing json file: /home2/google-services/android/analytics/app/google-services.json
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:incrementalDebugJavaCompilationSafeguard
:app:javaPreCompileDebug
:app:compileDebugJavaWithJavac
:app:compileDebugJavaWithJavac - is not incremental (e.g. outputs have changed, no previous execution, etc.).
:app:compileDebugNdk NO-SOURCE
:app:compileDebugSources
:app:mergeDebugShaders
:app:compileDebugShaders
:app:generateDebugAssets
:app:mergeDebugAssets
:app:transformClassesWithDexForDebug
:app:mergeDebugJniLibFolders
:app:transformNativeLibsWithMergeJniLibsForDebug
:app:processDebugJavaRes NO-SOURCE
:app:transformResourcesWithMergeJavaResForDebug
:app:validateSigningDebug
:app:packageDebug
:app:assembleDebug
2 如果没有用google-playservice则输出的log是这样的
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2520Library
:app:prepareComAndroidSupportAppcompatV72520Library
:app:prepareComAndroidSupportSupportCompat2520Library
:app:prepareComAndroidSupportSupportCoreUi2520Library
:app:prepareComAndroidSupportSupportCoreUtils2520Library
:app:prepareComAndroidSupportSupportFragment2520Library
:app:prepareComAndroidSupportSupportMediaCompat2520Library
:app:prepareComAndroidSupportSupportV42520Library
:app:prepareComAndroidSupportSupportVectorDrawable2520Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics1020Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1020Library
:app:prepareComGoogleAndroidGmsPlayServicesBase1020Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement1020Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1020Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks1020Library
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:incrementalDebugJavaCompilationSafeguard UP-TO-DATE
:app:javaPreCompileDebug
:app:compileDebugJavaWithJavac
根据这个log就可以分析出我们的应用需要引入哪些aar包,第一种情况集成freebase比较复杂,这里先说下第二种情况
:app:prepareComGoogleAndroidGmsPlayServicesAnalytics1020Library
:app:prepareComGoogleAndroidGmsPlayServicesAnalyticsImpl1020Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement1020Library
:app:prepareComGoogleAndroidGmsPlayServicesTagmanagerV4Impl1020Library
:app:prepareComGoogleAndroidGmsPlayServicesTasks1020Library
这些包是我们需要的,GmsPlayServicesAnalytics1020 GmsPlayServicesAnalyticsImpl1020 GmsPlayServicesBase1020 GmsPlayServicesBasement1020 GmsPlayServicesTagmanagerV4Impl1020 GmsPlayServicesTasks1020
这些包在你的sdk路径下 如GmsPlayServicesAnalyticsImpl1020 {$ANDROID_SDKHOME}/extras/google/m2repository/com/google/android/gms/play-services-analytics-impl/10.2.0/play-services-analytics-impl-10.2.0.aar 根据名字找到版本号
在make(ant)构建的项目下引入这些库
LOCAL_STATIC_JAVA_AAR_LIBRARIES:= \
xxx_play_services_analytics \
xxx_play_services_analyticsimpl \
xxx_play_services_basement \
xxx_play_services_base \
xxx_play_services_tagmanager_v4_impl \
xxx_play_services_tasks
LOCAL_AAPT_FLAGS := –auto-add-overlay \
–extra-packages google.android.gms
LOCAL_PREBUILT_STATIC_JAVA_LIBRARIES := \
xxx_play_services_analytics:aar/play-services-analytics-10.2.0.aar \
xxx_play_services_analyticsimpl:aar/play-services-analytics-impl-10.2.0.aar \
xxx_play_services_basement:aar/play-services-basement-10.2.0.aar \
xxx_play_services_base:aar/play-services-base-10.2.0.aar \
xxx_play_services_tagmanager_v4_impl:aar/play-services-tagmanager-v4-impl-10.2.0.aar \
xxx_play_services_tasks:aar/play-services-tasks-10.2.0.aar
lib的名字自己定 不要和我的产生重复.
之后编译就能正常集成了, 不使用freebase的不用往下看了
第一种方式使用freebase的,里面有很多包会有{applicationid}的站位符号,需要你解压aar, jar -xvf xxx.aar 之后修改AndroidManifest.xml文件,将{applicationid}换成包名. 然后重新打包 jav -cvf xxx.aar xxx目录
另外你需要对这写aar单独构建,生成带com.google.gmd.R文件的库. 然后引入,才能正常编译使用