找不到與包名稱匹配的客戶端(Google Analytics(分析))-多個productFlavors和buildTypes [關閉]

本文翻譯自:No matching client found for package name (Google Analytics) - multiple productFlavors & buildTypes [closed]

Context: 內容:

I'm trying to set up Google Analytics for my app. 我正在嘗試爲我的應用設置Google Analytics(分析)。 (having 4 custom buildTypes and more than a few productFlavors ) (具有4個自定義buildTypes和多個productFlavors

It works fine when I select the Build Variant which has the applicationId set to com.my.app.package.name (the package name used when generating the google-services.json ). 當我選擇將applicationId設置爲com.my.app.package.name (生成google-services.json時使用的包名稱)的Build Variant時,它可以正常工作。 But, my other flavors have different applicationIds. 但是,我的其他口味具有不同的applicationIds。

I followed the offical devguide to set it up. 我按照官方的devguide進行了設置。

Error I get when any another build variant is selected in Build Variants Tab (which has a different applicationId (package name) is as follows: 在“ Build Variants Tab (具有不同的applicationId (包名稱))中選擇了任何其他構建變體時,出現以下錯誤:

Error:Execution failed for task ':app:processAllcategoriesDebugfreeGoogleServices'. 錯誤:任務':app:processAllcategoriesDebugfreeGoogleServices'的執行失敗。

No matching client found for package name 'com.my.app.package.name.debug' 找不到與包名稱'com.my.app.package.name.debug'匹配的客戶端

Explanation of Error Message: 錯誤消息說明:

In the task name in the error message above Debugfree is my custom buildType and Allcategories is one of my productFlavors . 在錯誤消息上方的任務名稱中, Debugfree是我的自定義buildTypeAllcategories是我的productFlavors

I understand the error and know the package name is different from what i used when generating the json, but that is what I'm trying to figure a way around. 我理解錯誤,並且知道包名稱與生成json時使用的包名稱不同,但這就是我試圖解決的方法。

Problem: 問題:

Now, the google-services.json resides in the app folder and hence I am not being able to separate them out for each product flavor by dropping them in the flavor specific source set folder. 現在, google-services.json駐留在app文件夾中,因此我無法通過將它們放在特定於口味的源集文件夾中針對每種產品口味將它們分開。

Questions: 問題:

  1. My custom byildType for debugging suffixes .debug to the applicationId (package name). 我用於調試的自定義byildType.debug附加到applicationId (程序包名稱)。 Is there a way I can make it work with the google-services.json which has my release applicationId (ie without the suffix .debug ) 有什麼辦法可以使它與具有我的發佈applicationIdgoogle-services.json一起工作(即不帶後綴.debug
  2. Is there a way to have multiple product flavors configured in the same google-services.json file without using separate files and tasks to copy the required file to app folder. 有沒有一種方法可以在同一google-services.json文件中配置多種產品口味,而無需使用單獨的文件和任務將所需文件複製到app文件夾。 I know it can be done using task as mentioned in this post . 我知道這是可以做到用task中提到的這篇文章 Is there a simpler way to just have one file or pick right file based on gradle configuration? 是否有更簡單的方法來基於gradle配置僅擁有一個文件或選擇正確的文件?
  3. I see the package_name field in google-services.json has the package name com.my.app.package.name . 我看到google-services.jsonpackage_name字段具有包名稱com.my.app.package.name Can I add multiple package names manually to work for all build variants? 我可以手動添加多個軟件包名稱以適用於所有構建版本嗎? If yes, how to do that? 如果是,該怎麼做? Could not find any instructions in documentations. 在文檔中找不到任何說明。

#1樓

參考:https://stackoom.com/question/2MocZ/找不到與包名稱匹配的客戶端-Google-Analytics-分析-多個productFlavors和buildTypes-關閉


#2樓

Found this: 發現了這一點:

The google-services.json file is generally placed in the app/ directory, but as of version 2.0.0-alpha3 of the plugin support was added for build types , which would make the following directory structure valid: google-services.json文件通常放置在app /目錄中, 但自版本2.0.0-alpha3起,已爲構建類型添加了對插件的支持 ,這將使以下目錄結構有效:

 app/src/ main/google-services.json dogfood/google-services.json mytype1/google-services.json ... 

Source 資源

Source 2 來源2


#3樓

check if client_id and package_name in the google-services.json has a correct value according to your package name. 根據您的軟件包名稱檢查google-services.json中的client_idpackage_name是否具有正確的值。

You should add the mentioned file into the flavors directory with corresponding package name in the client_id and package_name field. 您應該在client_idpackage_name字段中使用相應的包名稱將提到的文件添加到flavors目錄中。


#4樓

Check your package name on your google-services.json it should be same with your local package name of your app google-services.json上檢查您的軟件包名稱,該名稱應與您的應用的本地軟件包名稱相同

Example

"client_info": {
    "mobilesdk_app_id": "1:6596814400689:android:65d6f25f5006145",
    "android_client_info": {
      "package_name": "com.my.app.package.name"
    }

In this case my local package name is com.my.app.package.name so also i have changed my package name in google-services.json with my local package name 在這種情況下,我的本地軟件包名稱是com.my.app.package.name,所以我也用本地軟件包名稱更改了google-services.json中的軟件包名稱


#5樓

You need to place google-services.json into app/ dir. 您需要將google-services.json放入app/目錄中。 And for each build type, there should be accordant director in app/src folder. 對於每種構建類型, app/src文件夾中都應該有一致的Director。

For example, if you have release and debug: 例如,如果您具有發佈和調試功能:

app/google-services.json
app/src/debug/google-services.json

In all google-services.json files you should specify correct package_name according to build type. 在所有google-services.json文件中,您應該根據構建類型指定正確的package_name

For example, inside debug dir it should be like {com.myapp}.debug 例如,在debug dir中,它應類似於{com.myapp}.debug


#6樓

I solved it by making two sourcesets , one free and one paid. 我通過製作兩個資源集解決了這個問題,一個是免費的,一個是付費的。 Both of these folders will contain required java code and resource files, which will be edited to the requirements of the particular flavor. 這兩個文件夾都將包含必需的Java代碼和資源文件,將根據特定風味的要求對其進行編輯。 For example, You would like to remove AdMob Code in the Paid both from Java Classes and Layout Files. 例如,您想從Java類和佈局文件中刪除付費中的AdMob代碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章