Firebase服务在应用发布版本中停止工作。

huangapple go评论65阅读模式
英文:

Firebase services stop working for the app release build

问题

Cloud Firestore 和远程配置服务在我的应用中使用。在调试模式下一切正常。但是从 Play 商店(内部测试)安装的应用发布版本无法正常工作。

在我的应用中,使用 OAuth 的 Google 登录在添加来自 Firebase 应用发布配置的另一个 SHA-1 密钥(从 Play 控制台获取)后按预期工作。但是 Cloud Firestore 和远程配置仍然不工作。

日志:Stream closed with status: b1 {code=PERMISSION_DENIED...}

看起来我漏掉了什么。另外,我如何获取应用的发布日志?有任何想法,谢谢。

更新 看起来问题出在规则上,所以我的规则如下:

远程配置规则:
Firebase服务在应用发布版本中停止工作。

Firestore 数据库规则:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /stories/{storyId}{
      allow read, write: if resource.data.userId == request.auth.uid || request.resource.data.userId == request.auth.uid;
    	match /sentences/{itemId}{
      	allow read, write: if request.auth != null;
      }
    }
  }
}

读取的查询如下所示:

Firebase.auth.uid?.let { userId ->
    db.collection("stories")
        .whereEqualTo("userId", userId)
        .whereEqualTo("hasBookmarks", true)
        .orderBy("createdAt", Query.Direction.DESCENDING)
        .addSnapshotListener { value, e ->
    // 处理结果的代码
    }
}
英文:

Cloud Firestore and Remote config services are using in my app. In debug mode all works fine. But the app release build istalled from Play Store (internal testing) doesn't work.

Google sign-in (using OAuth) in my app works as expected after adding another one SHA-1 key (taken from Play Console) to Firebase app release config. But Cloud Firestore and Remote config still don't.

Log: Stream closed with status: b1 {code=PERMISSION_DENIED...}

It looks like I had missing something. Also, how can I get release logs of the app? Any thoughts, thanks.

UPD It seems the problem in rules, so my rules are:

Remote config rules:
Firebase服务在应用发布版本中停止工作。

Firestore DB rules:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /stories/{storyId}{
      allow read, write: if resource.data.userId == request.auth.uid || request.resource.data.userId == request.auth.uid;
    	match /sentences/{itemId}{
      	allow read, write: if request.auth != null;
      }
    }
  }
}

Query to read look like this:

Firebase.auth.uid?.let { userId ->
            db.collection("stories")
                .whereEqualTo("userId", userId)
                .whereEqualTo("hasBookmarks", true)
                .orderBy("createdAt", Query.Direction.DESCENDING)
                .addSnapshotListener { value, e ->
        //result handling code
    }
}

答案1

得分: 0

问题出在发布版本中对Kotlin数据类进行ProGuard混淆。通过对敏感的数据类使用@Keep注解来解决,查看详情

英文:

The issue was in ProGuard obfuscation for Kotlin Data classes in release builds. Solved by using @Keep annotation for sensitive Data classes, see details.

huangapple
  • 本文由 发表于 2023年7月14日 04:25:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76683012.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定