Load google-services.json from local file system - android

The google-services.json file used by the Firebase Android plugin is usually put in the app's module folder.
What I do want to do instead is put this file somewhere on the filesystem completely outside the project folder and let gradle / the Firebase plugin read it from there.
I thought about putting it's location in the local.properties and somehow 'tell' the Firebase plugin to get the location of the google-services.json from there.
How can I achieve this?

According to offical documentation, the google-services.json file is generally placed in the app/ directory (at the root of the Android Studio app module). As of version 2.2.0 the plugin supports build type and product flavor specific JSON files. All of the following directory structures are valid:
// dogfood and release are build types.
app/
google-services.json
src/dogfood/google-services.json
src/release/google-services.json
...
Note: Providing a google-services.json file in the release directory allows you to maintain a separate Firebase project for your production APKs.
When product flavors are in use these more complicated directory structures are also valid.
// free and paid are product flavors.
app/
google-services.json
src/dogfood/paid/google-services.json
src/release/free/google-services.json
...
As a conclusion, you cannot add google-services.json file outside your project.
Hope it helps.

Related

Is it possible to extract google-services.json from the apk file?

New to android development. When we distribute the .apk file, can the receiver extract the google-services.json and use our database or authentication database.
I looked
I have apk file, Is it possible to get android studio project from apk?
and Is google-services.json confidential?
and Is it possible to decompile an Android .apk file?
but don't directly relate
I tried to extract an apk of mine which has google-services.json file and I couldn't find the google-services.json file in extracted folder .
Edit : Here is more info I found
The google-services plugin has two main functions:
1 - Process the google-services.json file and produce Android resources that can be used in your application's code. See Adding the
JSON File more information.
2 - Add dependencies for basic libraries required for the services you have enabled. This step requires that the apply plugin:
'com.google.gms.google-services' line be at the bottom of your
app/build.gradle file so that no dependency collisions are introduced.
You can see the result of this step by running ./gradlew
:app:dependencies.
This means that the google-services.json file will be converted to android resources by google-services plugin during build process .
You can find how google-services.json works over here
can the receiver extract the google-services.json and use our database or authentication database.
Even if the receiver extracts credentials from apk , he cannot access database as the SHA-1 will be different .

Instant App Uploading APK is failed

I'm trying to add my APKs to Play Store but it gives an error :
Upload failed
Your Instant App APKs contains an APK name 'productdetail' that either does not exist or was not included.
Any idea why can it happen?
Thanks for your help!
A few things you could check here:
Make sure you are uploading the ZIP file, and it does contain the productdetail APK. You need to upload all APKs at once.
In your base module, you have feature project(':productdetail') in your dependencies section of your build.gradle file. (Modify the relative project path if product detail does not sit in the root folder of the project)
In your instant apps project-level build.gradle (i.e. the one with com.android.instantapp plugin applied), you have implementation project(':productdetail') in your dependencies section.
Detailed explanation of project structure could be found here: https://developer.android.com/topic/instant-apps/getting-started/structure.html
I would also recommend checking out Hello World code samples from https://developer.android.com/topic/instant-apps/samples.html and compare your build.gradle against the samples to spot mistakes in build files.

Firebase - Changing file name google-services.json?

Can I change the file name google-services.json to prod-google-services.json?
You should not change the name of the file if you intend to use it. If you're going to use different google-services.json file depending on the app environment, you should Configure Product Flavors.
See Firebase 2.0 - how to deal with multiple flavors (environments) of an android app?
You cannot change the google service file name. You can use flavour to manage the google-services.json file.
Like this:
app/src/
flavor1/google-services.json
flavor2/google-services.json
Look here for detail.
Also, very important to note : You should not delete the google-services.json file from your app folder. Firebase will automatically use google-services.json file from flavor folder if it is present and neglect the google-services.json file from app folder. [Thanks #KrishnaAgarwal]
No you can not change file name . it was detected by android gradle while building project.

Exclude folder from APK in Android Studio

I've included a production folder in the root of my project, after building the APK and opening it as an archive, I've noticed that the production folder has not been included.
Am I right/safe to assume that any un-referenced files/folders are automatically excluded from the APK or should I be using some sort of configuration file to specify an exclusion list?
I would phrase it more as "only stuff in src/ might ever get included in an APK, for a conventional Android Studio project".
If you create random other directories, those will be ignored, unless you specifically do something in build.gradle to try using them (e.g., as an alternative location for assets/).
IOW, the contents of an APK come from a whitelist, not a blacklist.

Add google firebase as a library

For some reason I do not use Android Studio, I compile my apps using a remote server with apache ant so, Is there a way to add firebase analytics, messaging... as libraries?
Firebase is a set of aar (Android Archive) files. Android Studio gradle plugin will simplify the use of the aar files but you can manually configure the app to use the aars. To do so in addition to linking to the libraries you will need to manually merge the manifest from all aar files to your app manifest. That includes permissions, services, receivers, content providers etc. aar is simple zip file. You can open it with unzip (or any other tool that reads zip files) and see the AndroidManifest.xml. You will also need to merge all the resources (if any) for the aar files. The last step will be to add the google_app_id from the generated google-services.json file as string resource. All in all, this is not a trivial work but it is possible.

Categories

Resources