2016年5月6日 星期五

[Android]Google Analytics 8.3.0 conflict 版本衝突

昨天在公司幫忙將專案加入GA時
我照著Google 官方說明一步一步加上去時 官方範例點我
發現怎麼加上dependencies後

compile 'com.google.android.gms:play-services-analytics:8.4.0'

在compile 整個project 時,總是會出現錯誤訊息

Please fix the version conflict either by updating the version of the google-services plugin.

後來搞了老半天,終於發現也有人有相同的問題

起初我一直以為是我的其他lib裡面的google service 版本與8.4.0版的analytics衝突了,結果原來問題在於需要把

apply plugin: 'com.google.gms.google-services'

擺到整個build.gradle檔案的最下方,這時才可以正常compile
整個是很無言阿,在終於加入GA後,另一個問題又來了

當我trackScreen之後,我查看logcat是否有正常將訊息回傳至Google service上,結果居然跟我說

W/GAv4(10565): AnalyticsReceiver is not registered or is disabled. Register the receiver for reliable dispatching on non-Google Play devices. See http://goo.gl/8Rd3yj for instructions.

W/GAv4(10565): AnalyticsService not registered in the app manifest. Hits might not be delivered reliably. See http://goo.gl/8Rd3yj for instructions.

什麼阿!!這到底是什麼鬼..以前加GA不是很簡單嗎?
只要google play service的jar檔有加到lib當中,在將key丟入code中不是就可以用了?後來還多了一個需要放入configuration file,這個又還好,因為官方上就有很明確的跟我說要放了

但以前都不用放receicer才對阿...什麼時候又改的
於是我又詢問了google ,才終於找到答案

現在必須要在AndroidManifest.xml當中加入

        
        
            
                
            
        
        

        
        
            
                
            
        
          

這才終於解決了加GA這件事,真是花了我不少時間阿...