英文:
React native google services allocation in APK
问题
我想知道是否有人可以帮助我创建一个用于Android的本机模块,以读取我用于Firebase的google-services.json
文件,我倾向于从JSON对象中提取某个值并将其显示给开发人员。然而,我不确定它在实际APK中的位置。
我有两个不同的google-services.json
文件。我的项目结构包含以下内容project/android/app/src/debug/google-services.json
和project/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:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<! -- Present in all applications -->
<string name="google_app_id" translatable="false">1:1035469437089:android:73a4fb8297b2cd4f</string>
<! -- Present in applications with the appropriate services configured -->
<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>
</resources>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论