簡體   English   中英

在模塊 ExpoPushTokenManager 上執行導出方法 getDevicePushTokenAsync 時發生異常

[英]Exception occurred while executing exported method getDevicePushTokenAsync on module ExpoPushTokenManager

我升級了我的 expo 推送通知,每當我在 Android 上運行它時,我都會收到以下錯誤:

在模塊 ExpoPushTokenManager 上執行導出的方法 getDevicePushTokenAsync 時發生異常。 請設置您的項目 ID。 與 Firebase 服務器 API 通信需要有效的 firebase 項目 ID:它使用 Goolge 標識您的項目。

誰能告訴我應該把項目ID放在哪里? 我將它鏈接到我的config.js文件中的項目中,但我覺得它也應該在我的app.json文件中,只是不能 100% 確定在哪里。

{
  "expo": {
    "name": "Galavant",
    "slug": "Galavant",
    "platforms": ["ios", "android", "web"],
    "version": "2.0.8",
    "orientation": "portrait",
    "icon": "./assets/logo.png",
    "splash": {
      "image": "./assets/logo_original.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": ["**/*"],
    "ios": {
      "usesAppleSignIn": true,
      "infoPlist": {
        "NSCameraUsageDescription": "So you can add photos to your profile.",
        "NSPhotoLibraryUsageDescription": "So you can add photos to your profile.",
        "NSLocationWhenInUseUsageDescription": "So you can connect with people nearby."
      },
      "supportsTablet": true,
      "bundleIdentifier": "com.test.test",
      "buildNumber": "0.0.1",
      "config": {
        "googleSignIn": {
          "reservedClientId": "com.googleusercontent.apps.12346789"
        }
      }
    },
    "android": {
      "package": "com.test.test",
      "useNextNotificationsApi": true,
      "versionCode": 5,
      "config": {
        "googleMaps": {
          "apiKey": "asdkjfkasjdf9837983rlkajshf"
        },
        "googleSignIn": {
          "apiKey": "asdkjfkasjdf9837983rlkajshf", 
          "certificateHash": "33345w4sdfasdkjfkasjdf9837983srlkajshf"
        }
      },
      "permissions": [
        "ACCESS_COARSE_LOCATION",
        "ACCESS_FINE_LOCATION",
        "CAMERA",
        "MANAGE_DOCUMENTS",
        "READ_CONTACTS",
        "READ_CALENDAR",
        "WRITE_CALENDAR",
        "READ_EXTERNAL_STORAGE",
        "READ_PHONE_STATE",
        "RECORD_AUDIO",
        "USE_FINGERPRINT",
        "VIBRATE",
        "WAKE_LOCK",
        "WRITE_EXTERNAL_STORAGE",
        "com.anddoes.launcher.permission.UPDATE_COUNT",
        "com.android.launcher.permission.INSTALL_SHORTCUT",
        "com.google.android.c2dm.permission.RECEIVE",
        "com.google.android.gms.permission.ACTIVITY_RECOGNITION",
        "com.google.android.providers.gsf.permission.READ_GSERVICES",
        "com.htc.launcher.permission.READ_SETTINGS",
        "com.htc.launcher.permission.UPDATE_SHORTCUT",
        "com.majeur.launcher.permission.UPDATE_BADGE",
        "com.sec.android.provider.badge.permission.READ",
        "com.sec.android.provider.badge.permission.WRITE",
        "com.sonyericsson.home.permission.BROADCAST_BADGE"
      ]
    },
    "notification": {
      "icon": "./assets/PushNotification.png"
    }
  }
}

我嘗試切換到托管流以嘗試處理后台通知(在 Expo Go 中不起作用)並得到完全相同的錯誤(在提到 projectId 時獲取 Expo 推送令牌時無法啟動)。

我最終確實讓我的工作終於開始了。 如果它對其他人有幫助,這就是我偶然發現的地方......

首先,我確認我有這兩個鍵:

  "googleServicesFile": "./google-services.json",
  "useNextNotificationsApi": true,

其次,我認為我沒有完全正確地運行所有https://docs.expo.dev/push-notifications/using-fcm/ 我讓整個“客戶端設置”工作,但后來忘記了“上傳服務器憑據”。

第三,可能也是最令人困惑的,我對發布和更新也很陌生。 我在我的應用程序上創建了一個調試頁面,顯示了它從 Play 商店運行的版本(至少我認為是這樣)。 但它只會在我將 Play 應用程序發布到內部測試后打開然后關閉並重新打開它時才會更新......在了解了有關 OTA 更新的更多信息后,我意識到這實際上是正在發生的事情,而我實際上並沒有得到即使我的 Constants.manifest.android.versionCode 和應用程序版本出現更新(因為它們以某種方式通過 OTA 交付..),使用新的 android 鍵設置的最新版本。

所以修復我的最后一件事是通過 Play 手動卸載我的內部測試應用程序,然后從頭開始重新安裝!

我最終做了幾件事。 首先,我在google-services.json文件中創建並添加。 我在"web"部分添加了項目 ID,最后我用useNextNotificationsApi更新了“android”部分

"android": {
  "package": "com.test.test",
  "googleServicesFile": "./google-services.json",
  "useNextNotificationsApi": true,
  "versionCode": 10,
  "config": {
    "googleMaps": {
      "apiKey": "123456789"
    },
    "googleSignIn": {
      "apiKey": "123456789",
      "certificateHash": "123456789asdfasdf"
    }
  },
  "permissions": [
    "ACCESS_COARSE_LOCATION",
    "ACCESS_FINE_LOCATION",
    "CAMERA",
    "USE_FINGERPRINT",
    "VIBRATE"
  ]
},
"web": {
  "config": {
    "firebase": {
      "projectId": "testprojectID",
      "apiKey": "123456789",
      "measurementId": "measurementid123"
    }
  }
},

解決我的問題的方法是在依賴項中添加./android/app/build.grandle

implementation 'com.google.firebase:firebase-iid'

但就我而言,我之前遇到過其他問題,例如我忘記上傳服務器憑據。 該文檔沒有明確說明這一點。 在此頁面上,步驟更清晰

上傳服務器憑據

您還可以檢查 googleServiceFile 的路徑是否為 o

暫無
暫無

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

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