React Native中的Google服务在APK中的分配

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

React native google services allocation in APK

问题

我想知道是否有人可以帮助我创建一个用于Android的本机模块,以读取我用于Firebase的google-services.json文件,我倾向于从JSON对象中提取某个值并将其显示给开发人员。然而,我不确定它在实际APK中的位置。

我有两个不同的google-services.json文件。我的项目结构包含以下内容project/android/app/src/debug/google-services.jsonproject/android/app/src/release/google-services.json。任何帮助都非常受欢迎,我只是困惑于这些文件在实际APK中被复制到哪里,以便我可以以编程方式读取它并提取相应键的值。

英文:

I was wondering if anyone could help me out creating a native module for Android to read my google-services.json file used for Firebase, i tend to extract a certain value from the JSON object and show it to the developer. However, i am not sure where is it located in the actual APK.

I have two different google-services.json files. My project structure contains the following project/android/app/src/debug/google-services.json and project/android/app/src/release/google-services.json. Any help is more than welcome, i am just confused on where the files are copied in the actual APK so that i can go programmatically , read it and extract the values for the corresponding keys.

答案1

得分: 0

以下是翻译好的内容:

那个文件并未按照你所想的方式包含在你的应用中。Google服务的Gradle插件会在构建时解析它,并将其中的一些值作为字符串资源注入到你的应用中。如果你想要读取这些值,只需找出你需要的字符串资源,然后像访问其他任何字符串资源一样访问它。

关于Google服务插件实际在构建时执行的文档在这里。你可以看到它生成的字符串资源如下:

<! -- 所有应用程序中都存在 -->
<string name="google_app_id" translatable="false">1:1035469437089:android:73a4fb8297b2cd4f</string>

<! -- 在配置了适当服务的应用程序中存在 -->
<string name="gcm_defaultSenderId" translatable="false">1035469437089</string>
<string name="default_web_client_id" translatable="false">337894902146-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com</string>
<string name="ga_trackingId" translatable="false">UA-65557217-3</string>
<string name="firebase_database_url" translatable="false">https://example-url.firebaseio.com</string>
<string name="google_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
<string name="google_crash_reporting_api_key" translatable="false">AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8</string>
<string name="project_id" translatable="false">mydemoapp</string>
英文:

That file is not included in your app in the way that you're imagining. The Google services Gradle plugin parses it at build time, and injects some of its values as string resources into your app. If you want to read those values, simply figure out which string resource you need, and access it like you would any other string resource.

The documentation for what the Google service plugin actually does at built time is here. You can see that it generates string resources that look like this:

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;resources&gt;

    &lt;! -- Present in all applications --&gt;
    &lt;string name=&quot;google_app_id&quot; translatable=&quot;false&quot;&gt;1:1035469437089:android:73a4fb8297b2cd4f&lt;/string&gt;

    &lt;! -- Present in applications with the appropriate services configured --&gt;
    &lt;string name=&quot;gcm_defaultSenderId&quot; translatable=&quot;false&quot;&gt;1035469437089&lt;/string&gt;
    &lt;string name=&quot;default_web_client_id&quot; translatable=&quot;false&quot;&gt;337894902146-e4uksm38sne0bqrj6uvkbo4oiu4hvigl.apps.googleusercontent.com&lt;/string&gt;
    &lt;string name=&quot;ga_trackingId&quot; translatable=&quot;false&quot;&gt;UA-65557217-3&lt;/string&gt;
    &lt;string name=&quot;firebase_database_url&quot; translatable=&quot;false&quot;&gt;https://example-url.firebaseio.com&lt;/string&gt;
    &lt;string name=&quot;google_api_key&quot; translatable=&quot;false&quot;&gt;AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8&lt;/string&gt;
    &lt;string name=&quot;google_crash_reporting_api_key&quot; translatable=&quot;false&quot;&gt;AIzbSyCILMsOuUKwN3qhtxrPq7FFemDJUAXTyZ8&lt;/string&gt;
    &lt;string name=&quot;project_id&quot; translatable=&quot;false&quot;&gt;mydemoapp&lt;/string&gt;

&lt;/resources&gt;

huangapple
  • 本文由 发表于 2020年10月9日 11:43:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/64273635.html
匿名

发表评论

匿名网友

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

确定