簡體   English   中英

expo:如何根據發布通道 expo 加載不同的 google-services-json

[英]expo: how to load different google-services-json based on release channel expo

對於每個 releaseChannel,我都有一個不同的 google-service.json 文件(一個用於 prod、stage、QA 和 dev 的文件)

有關更多詳細信息,我想在不同的環境中實現推送通知。 因為我不想在 QA 中發送測試通知並將通知發送給產品用戶!

這是app.json中的 android 配置

"android": {
      "googleServicesFile": "./google-services.json",
      "adaptiveIcon": {
        "foregroundImage": "./src/assets/adaptive-icon.png"
      },
      "permissions": [
        "android.permission.CAMERA",
        "android.permission.ACCESS_FINE_LOCATION",
        "android.permission.WRITE_EXTERNAL_STORAGE",
        "android.permission.READ_EXTERNAL_STORAGE",
        "android.permission.ACTION_BOOT_COMPLETED",
        "android.permission.RECORD_AUDIO",
        "com.google.android.gms.permission.AD_ID"
      ],
      "package": "com.beyondbelievers.awal",
      "versionCode": 1
    },Ï

有什么辦法可以在每個環境中加載不同的文件嗎?

這個答案的靈感來自一個老問題,在我搜索了整個互聯網后,你可以在這里查看我找到了一種方法,但使用的是app.config.js

我將嘗試通過以下步驟解釋我如何實現我的目標:

{
    "qa": {
      ...
      "releaseChannel": "qa",
      "env": {
        "APP_VARIANT": "qa"
      }
      ...
    },
    "stage": {
      ...
      "releaseChannel": "stage",
      "env": {
        "APP_VARIANT": "stage"
      }
      ...
    },
    "prod": {
      ...
      "releaseChannel": "prod",
      "env": {
        "APP_VARIANT": "prod"
      }
      ...
    }
  }
}

"APP_VARIANT"變量包含 env 的類型,基於它我可以稍后檢查我們的文件。

  • 現在回到app.config.js添加以下行:

    // this will return the value of APP_VARIANT defined in eas.json
    const APP_RELEASE_CHANNEL = process.env.APP_VARIANT;
    
    // define the AndroidGoogleServicesFile variable to use instead of the normal string and assign a default value to it
    let AndroidGoogleServicesFile = "./google-services-dev.json";
    
    
    // now check the value of the APP_VARIANT and based on it assign the path of the google-services you wanna use
        if (APP_RELEASE_CHANNEL === "qa") {
          AndroidGoogleServicesFile = "./google-services-qa.json";
        } else if (APP_RELEASE_CHANNEL === "stage") {
          AndroidGoogleServicesFile = "./google-services-stage.json";
        } else if (APP_RELEASE_CHANNEL === "prod") {
          AndroidGoogleServicesFile = "./google-services-prod.json";
        }

  • 現在您知道您需要使用哪個文件,剩下的一步就是分配該文件,以便您的應用程序可以使用它
android: {
    ...
    googleServicesFile: AndroidGoogleServicesFile,
    ...
  },

這就是我解決問題的方法我希望這也能解決您的問題。

如果您不明白我歡迎詳細解釋的內容

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM