SHA1 is changed after I changed my laptop - android

I have a running application in Play Store. I've tested and successfully updated my application three times. Suddenly, I had to change my laptop and reconfigured everything, i.e. Android Studio, JDK, SDK and everything. I knew that the signed key file is important for updating my application. So I backed up my project and the file.
Now I'm going to update my application again and I've noticed that my SHA1 key is changed. I cannot test my G+ login integrated with my app. I think that same problem will arise in GCM also. What should I do?

The Play Store and its APIs were all given the SHA1 of the debug key from your original setup, and that's what it's still expecting.
The easiest thing to do, if possible, is copy the debug key from your old setup to your new setup and rebuild with it. That file is in ~/.android/debug.keystore.
If you don't have your old key available any more, you will have to repeat the process you originally went through to connect your debug builds to whatever Google APIs you use. But this time with the SHA1 of your new key to replace the old key that's no longer being used.

You just need two steps to make your app up and working again:
1) Get your new SHA1 key.
2) Make the changes in the credentiials by going to console.developer.google.com where you have created the API key for signing your application.
Now how you are going to get the updated SHA1 key, for that go to the android studio click on View-> Tool Windows-> Gradle. Open the file with your app name on it and "(root)" written next to it then go to Run Configurations and click on one of the file that you see. That's it you will get your new SHA1 key and MD5 there at the bottom where the configurations are executed.
Update your API key with this SHA1 key and you are good to go!:)
Note: If you can't see the SHA1 key then there is a button next to run button named "Toggle tasks execution/text mode" click on that and you will get the key.

I had the same problem when lost my old pc.
Your app is secure in google play store as the keystores.jks stores the original ShA-1 that identifies your app-identity. If you lost your keystores then you will face others problemas. Here we will resolve the different Sha-1 problem.
The problem you are facing is relative to the debug, as the sha-1 is generated from your pc and its not equal to the one you previously informed.
You need 3 steps:
STEP 1 - Get your new Sha-1.
-Get the path to your new key. Its is in: C:\Users\YOURUSER.android
use this comand in terminal or command prompt -> keytool -list -v -keystore "C:\Users\YOURUSER.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
Copy the sha-1.
STEP 2 - Go to google developers console, find your credentials. Some of them are restricted. Enter in its properties and add the new SHA-1 in the list. Leave the old ones there too. Do it in every restricted credential.
STEP 3 - Go to your firebase console, settings. Then in Apps Android, just add the new SHA-1. This will make work.

Related

How do I set up and deploy a Unity application to Google Play using Play app signing and app bundles?

Using app bundles and play app signing is currently the way recommended by google to deploy new apps on google Play. And starting from August 2021 new apps will be strong-armed into using these formats.
How do I set this up in Unity, and how do I configure the app in Google Play?
I haven't gotten 2019.4 app bundle builds to sucessfully upload to play console, so it's probably a good idea to upgrade to the 2020.3 LTS before you start (as that's what finally worked for me.
Configuring Google Play App signing
First create a new app in Play Console, give it a name, accept terms etc.
Then, click Internal testing on the menu on the left side, and create a new internal release.
In the first question, click Change App Signing key, Use a different key and then select the third option, where you can upload your existing key (and an optional step with to add an upload key) to Google Play.
Now, don't just follow the instructions listed on Google Play, as you will end up with an upload key store that Unity doesn't know how to deal with.
Instead, using Unity, we will create two key stores and two keys. The first one is the app signing key, which you will only need to see once when uploading it to Google Play, then Google will take care of it and use it to do the final signing of your apps after you've uploaded your app bundles.
Go to Player settings → Publishing Settings → Keystore Manager → Create new in dedicated location
You don't need to fill out everything. Just the password, key alias and key password. It doesn't matter what you call the key. Don't configure Unity to use this key just yet (we'll create another key and keystore for Unity to use shortly).
Follow instructions 1.-3. on Google Play to upload this new key using the pepk tool.
Then, you need to create an upload key and keystore. Unity will use this key to sign your app bundles. Again, do NOT use the instructions on Google Play to create this key, instead use the Unity UI to create another key store that plays nice with Unity.
The passwords and alias could be whatever you want I named my key uploadkey, but make sure to keep the key store and passwords somewhere safe, you will need these later, or you'll have to create new keys and talk to Google support to reset it.
When prompted, click yes to configure your project to use this new key.
When you've created the key store and key export its public key to the .pem format...
keytool -export -rfc -keystore upload.keystore -alias uploadkey -file upload_certificate.pem
...and upload it to Google Play.
Click Update and then Continue in Play Console.
Play store should now be ready to accept your .aab files.
Configuring Unity
Hopefully, your project is now set up to sign using the upload key you just created.
Make sure to set the package name yourself by going to Player Settings → Other Settings Override Default Package Name . Type in something appropriate in lower-case characters only, the default package name has uppercase characters, which I think is just begging for problems. You can't change this later, or you'll have to create a new play store entry, so make sure it's something that's acceptable for customers to see, i.e. com.yourcompany.gamename.
It's also a good idea to enable 64-bit builds in player settings otherwise, google play will complain later. Switch Scripting Backend to IL2CPP and then tick ARM64:
Tick Build App Bundle in Build Settings.
Click Build and build your .aab file
Then upload it to the Google Play Console:
If you're lucky, everything went smoothly, and you can click save and be ready to start testing your app.
If not, you may get helpful error messages, in which case just follow them, if not and they're really non-descriptive (like "Couldn't upload. Try again."), then try temporarily uploading an .apk instead, as that sometimes gives better error messages, then switch back to .aab when you've solved the issue.
In Unity 2020.3 you can use a jks upload key in Unity that was generated in Android Studio and keep "Let Google manage your key..." selected.
To generate a key, install Android Studio and create an empty Android Studio project then once gradle settles down, choose Build > Generate Signed Bundle. When it prompts for a keystore, create a new one and save it where you want. Cancel out, then in Unity select the jks you saved as your keystore in publishing settings.
You should be able to generate an aab package in Unity using the jks as a custom keystore to upload and still let Google manage the signing key like they recommend.
After struggling with uploading an app bundle, I realized one extra thing :
Don't use any forbidden characters in your password for the keystore in Unity ! This includes spaces and brackets, maybe not only...
If in doubt, try creating the key with Java keytool command line and it will tell you your password contains characters that can't work... Even just type the command line into a terminal and you'll see your password makes the command line break !
keytool -genkey -keystore yourfile.jks -dname "n=Mark Jones, ou=JavaSoft, o=Sun, c=US" -alias android -keypass YOUR PASSWORD -storepass YOUR PASSWORD -keyalg RSA -keysize 2048 -validity 2000
Maybe special chars are allowed in the Unity key generation panel but not in keytool ! Unity should fix this issue, it was driving me nuts ;)
Peace :)
FOR ALL YOU BEAUTIFUL FOLK WHO GET STUCK AT THE LAST STEP! - READ THIS!
Blockquote
When you've created the key store and key export its public key to the .pem format...
keytool -export -rfc -keystore upload.keystore -alias uploadkey -file upload_certificate.pem
...and upload it to Google Play.
Blockquote
Click Update and then Continue in Play Console.
THIS part drove me NUTS trying to figure out what the hell you meant by that. I know it's down to the fact that I'm a complete noob at this but the rest of the tutorial was AMAZING!
So let me clarify for those newbies (like me) who might lose the plot when they get to the last step and can't figure out what the hell to do.
At this point in the tutorial:
Blockquote
and upload it to Google Play. Click Update and then Continue in Play Console.
Here is what you have to do.
If you have already uploaded the FIRST signing key you were asked to make in unity (NOT the upload one), then simply go back to the INTERNAL TESTING page and refresh it.
Click CHANGE APP SIGNING KEY and then select the third option again: "Export and upload a key from Java keystore"
Click UPLOAD GENERATED ZIP and upload the .zip file that was created during the first steps.... I named mine output.zip
At STEP 4 you will see a link called "SHOW INSTRUCTIONS" - Click the link and upload your public upload certificate that was generated in the last step. The file ending with the .pem format
Click SAVE and it should work.
NOW the next part got me. I didn't know what to do from here. The project is ready to accept the .aab files but DO NOT DO THIS JUST YET!
Learn from Mr Impatient himself (that's me), read the rest of the tutorial. Changing the file name to all lowercase is good practice to prevent issues later with CamelCaseFileNames.
FINALLY
You might get an error that says your target Android API is too low. Simply go to the UNITY PROJECT > FILE > BUILD SETTINGS > PLAYER SETTINGS > OTHER SETTINGS > and half way down the page change MINIMUM API LEVEL to "31" or above as instructed by the Google Prompt you WILL get if you ignore this :)
You can do this through Unity, it will download the latest version of the Android SDK (it opens a powershell terminal - DO NOT CLOSE THIS).
Once that's done, and you've completed all the steps listed above, then and ONLY THEN are you ready to compile your .aab file and upload it to the Google Play Console.
Finally, I want to thank the author of this tutorial BobbaLuba for his amazing efforts. After 7 hours of messing around in Unity -> Android Studio -> Google Play and almost abandoning the thought of releasing my app on Google .... it worked!
You are amazing sir. I tip my hat to you. Keep doing what you do. I for one, am eternally grateful .... I am emotionally, mentally and physically drained. I'm off to bed. Thanks again!
Good luck my little code monkeys!
Peace out
- NewbNinja

Google Maps are not showing up in a signed apk

I know this is a common question and usually the solution is to generate a separate key for release. I've done it several times and my API key in developers console contains two different SHA1-fingerprints: one for debug from AndroidStudio and on for release from my own keystore. I have signed the app with the same keystore and enabled Google Maps Android API v2 in the console. But still the maps activity shows just the white screen with 'Google' in the left bottom corner.
Are there any suggestions how to solve the problem?
It sounds like you only have the API key entered in the debug google_maps_api.xml. Also, it sounds like you're using the same API key for debug and release, but you still need to enter it in the google_maps_api.xml under the release folder as well as the one in the debug folder.
It's a little confusing, because when the project is in Android view, you can only see the debug file (although it should have (debug) in parenthesis next to it in that view).
In order to modify the release version, switch to Project view by using the dropdown in the upper left of the Project Explorer. Then, expand app/src/, and you will see subfolders debug and release. Under there, you should see two separate google_maps_api.xml files under debug/res/values and release/res/values.
Make sure that the API key is populated in the google_maps_api.xml file under the release/res/values folder, since this is the one that will be used for the signed release apk.
If you chose Google Play App Signing then your App's SHA-1 will be different one when it will be released.
Because Google remove your uploaded certificate and then sign the App with a new one,
So you have to know the new SHA-1 key.
(You don't have to follow the log for release and track the new SHA-1 generated)
You can compare the 2 SHA-1 keys.
Origin answer
I solved it by looking at https://play.google.com/console in the left menu configuration then integrity of the app and copy the SHA1 of the upload key certificate that is below the SHA1 Certificate of the app signing key and add it in the same api key of https://console.cloud.google.com/. This way I didn't have to make changes to the apk.
If it doesn't work for you add both and try.
I did a lot of things to fix these but any solution not fix my problem
to fix these issue I did these things
Create signed apk with new keystore file make sure that the you will create that in release mode
After creating the signed apk you should note the keystore path where you save your keystore file.
You also need to use your google map API key with your release mode and debug mode both, you can use same API key with both but make sure that you should add two different sha keys for your single api key on google console.
You should go to use the path of bin folder of java from c drive because keystore tool is inside bin folder so
suppose your file is like C:\Program Files\Java\jdk1.8.0_11\bin
so you should follow this path to your android studio terminal
change the path to C:\Program Files\Java\jdk1.8.0_11\bin
and then type this command:
keytool -list -v -keystore "/Users/NT/Desktop/generalkey.jks"(adress of your keystore file)
Now by doing these you will get the sha key copy that key
Go to google console/credentials
Now go to your api you will see edit option go to edit and past your sha key into it and save it .
Run your code.
you are using a version of sha1. you need to again generate SHA1 using command prompt after making you apk signed.
Steps to regenerate SHA1 is go to cmd and give the command like below:
C:\Program Files\Java\jre1.8.0_91\bin>keytool -list -v -keystore
"C:\Your key store path\keystores\android.jks"
1)go to your java in program file open java version like jre1.8.0
2)open bin folder and run command like above follwed by your key store path that you have generated when you generated the signed apk
after running this command on cmd you need to provide password of signed app and your SHA1 will be gerarated.
3)copy the sha1 and paste into console.developer with your package name within your api key.
It's too late to answer but may be helpful for others if they phase the same issue.
If adding key in the release did not work then please check your SHA key in your jks file and add the same key in google play google api console
To get released SHA open your terminal and type
Asad-MacBook-Air:~ asad$ keytool -list -v -keystore /your/path/keystore.jks
and then check SHA, it should be the same as it is used in google api console.
this happend to me because we need two google maps api keys one for the debug and another one for the release, you can check in :
C:\Users\username\AndroidStudioProjects\yourapp\app\src\ debug \res\values
and you’ll find an xml with your api key like:
AIza...etc
but if you check here:
C:\Users\username\AndroidStudioProjects\yourapp\app\src\ release \res\values
you will find an xml but without api key inside like:
<string name="google_maps_key" templateMergeStrategy="preserve"
translatable="false">YOUR_KEY_HERE</string>

Google maps only a grey background as APK

I develop locally with android-studio and a Galaxy S3 android phone connected via USB.
On my local development environment, when I fire up the run configuration to deploy on the S3, everything works fine - the map shows up just fine.
But when I deploy as signed APK to our server, and install via Internet (I am trying on another android phone to keep things clearly separated), the map tiles don't load, I see the Google sign to the lower left and the GPS location icon on the upper right corner.
I've seen a few related posts:
Android Google Maps application showing grey background instead of the map
which seems first a bit dated, second he uses eclipse (I am using android-studio), third - it didn't work for me.
Android - Google Maps Grey Screen on Signed APK
This guy didn't get any useful answers to his question....
The first step is to get the SHA1 value for the key that you used to sign the release version of your app using the keytool command line tool.
keytool -list -v -keystore ~/Keystore/key1.jks -storepass <your_store_password> -keypass <your_key_password>
Replace ~/Keystore/key1.jks with the path and name of the keystore that you used to sign your release version, and replace the passwords with your own.
When you execute this command at the command line, it will list the Certificate Fingerprints, including the SHA1 value that you need.
The next step is to add the SHA1 and package name to a key in the Google Developers Console.
You can either add it to the same key you used for debug builds, or you can create a new key.
To add your release SHA1 and package name to an existing API key, click the Add package name and fingerprint button, and add your SHA1 value and package name.
Then, you can use this API key with the signed release version of your app.
For more information on how to configure your app if you use a different API key for debug and release, see here.
Step 1: Follow the instructions from here:
http://developer.xamarin.com/guides/android/platform_features/maps_and_location/maps/obtaining_a_google_maps_api_key/
Step 2: Then from your Android Studio, follow the steps described here:
https://www.udacity.com/wiki/ud853/course_resources/creating-a-signed-apk
I faced a similar problem and had it solved by doing the above.

Getting Android Google Map v2 working in release version by generating SHA1 fingerprint for API key

I spent a long time tonight trying to figure out how to get my Google Map that worked in the debug version of my Android application to work in the release version. There were a few different problems that came up. Some fragments of Stack Overflow posts helped, but I thought it would be useful to list more detail for the whole process, including the problems I had, which were:
1) How/where do you specify something different for your release version?
2) How do you run the keytool executable needed to get the release version fingerprint?
3) Why was I getting the "keystore file exists but is empty" error when running keytool?
1) As specified in a couple other Stack Overflow posts, you can use the same Google API key for both your debug and release versions, but you have to supply the fingerprints of your debug and release keys in the Google Developers Console.
Log into Google Developers Console https://console.developers.google.com
Choose your appropriate Project
On left side, choose Credentials under "APIs & auth"
Assuming you already have an API Key generated for Android applications, you should already see your application listed as an "allowed application" with its debug fingerprint. Click "Edit allowed Android applications".
You will want to add another line for your application, but with its release fingerprint. To get that...
2) Google mentions in that dialog that you need to run
keytool -list -v -keystore mystore.keystore
But by clicking "Learn more" and going a little further, what you really want to run is
keytool -exportcert -alias MY_RELEASE_KEY_ALIAS -keystore MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE -list -v
Then you'll be asked for your keystore password. One piece that isn't mentioned in the docs is where the keytool program is. Its in your JDK bin folder. So on Windows, something like C:\Program Files\Java\jdk1.8.0_20\bin
3) After I opened a console window in the Java bin folder and ran the keytool as above, I was getting an error that said "keystore file exists but is empty". Eventually I realized that when specifying the full path to my release keystore file, I had only specified the folder name but forgot to include the actual file name, even though there was only one file in the folder. So MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE above should include the .keystore file name
After all that, you will be finally be provided with several fingerprints, including the SHA1. You can copy that, and go back and paste it as a new line in the allowed Android Applications, with your package name on the end separated by a semi-colon, just like the debug one.
Follow the instructions given here. After creating your project in Google Developers Console, select APIs, you will be prompted with a section of Popular APIs, select Google Maps Android API. Press enable API.(the image below is showing the steps in the new version of the console)
If you're still using the old console, enable the API, by selecting Services, then switch the button ON:
Note:
You don't need to enable the API for the debug version!
If you're map is still not showing try regenerating the key!
(new version)
(old version)
Enter the new API key then Sync Project with Gradle Files!

Android: Google Map v2 not showing map for release apk

My google map app works fine on device with debug google map API KEY but when I create signed apk for my app with release google map API KEY, it does not display map.
To generate release mode google API KEY , i am using SHA1 fingerprint with my keystore.
And i am also defining "signing and build types" in my project Settings as explained by developer.android.com(http://developer.android.com/tools/publishing/app-signing.html).
Tried every possible solution(removing apk and than reinstalling it again, restarting the device, cleaning the project ). nothing worked.
Anybody have a good solution to my problem please help.
FYI Using android studios platform.
Maybe you have two google_maps_api.xml files, one in the app/src/debug/res/values folder and the other in the app/src/release/res/values folder, but only the debug one contains your API key.
The API key needs to be hardcoded into the Android Manifest, and it doesn't work if it's in a separate resources XML file.
Debug certificate is different from your production certificate. You need to add both to your Google Maps key entry in your API console as seaparate row - each with the same packageId, but naturally different SHA1 hash.
EDIT
There's no limit of how many certificate fingerprints and package names are assigned to single Google Maps key, so unless you need this separated is's perfectly fine to have both development and production builds using the same key. In google console it would be like this (one sha1 is from debug cert, which is the same for all apps you build using this IDE, other is production cert):
83:10:58:52:EF:3B:59:70:2B:28:9E:AE:4F:5E:1D:F0:7E:19:FB:F1;com.foo.bar
AE:4F:5E:1D:F0:7E:19:FB:83:10:58:52:EF:3B:59:70:2B:28:9E:AA;com.foo.bar
or even (but I do not recommend using same key for different apps):
83:10:58:52:EF:3B:59:70:2B:28:9E:AE:4F:5E:1D:F0:7E:19:FB:F1;com.foobar.myapp
AE:4F:5E:1D:F0:7E:19:FB:83:10:58:52:EF:3B:59:70:2B:28:9E:AA;com.foo.bar
EF:3B:59:7E:19:FB:83:10:58:57:AE:4F:5E:1D:F0:2B:28:DE:9E:01;net.something.otherapp
I had this Problem and running these steps I think this way is perfect and complete
For Android Studio:
Build-Generate Signed APK
Copy Key Store Path.
Now open a command prompt and go to C:\Program Files\Java\jdk1.6.0_39\bin> (or any installed jdk version).
Type keytool -list -v -keystore and then paste your Key Store Path (e.g. C:\Program Files\Java\jdk1.6.0_39\bin>keytool -list -v -keystore "E:\My Projects \Android\android studio\signed apks\Hello World\HelloWorld.jks").
Now it will Ask Key Store Password, provide yours and press Enter to get your SHA1 and MD5 Certificate keys.
You Can See SHA1 For Your Debug Certificate and Use in Developer Google
Console
Sorry for replying late. Hope this helps for future.
I use this solution to solve same problem
When we are using Google maps while developing, a default debug.keystore is used which has no password. When we build apk file to upload on Play store new SHA-1 key is made so we have to make new debug.keystore for that. We have to create new API key for that SHA-1.
According to solution How to obtain Signing certificate fingerprint (SHA1) for OAuth 2.0 on Android? we can get SHA-1 for the exported apk file .
After that use that new API key in Android Manifest as the previous one and you are done.
EDIT 1-
Steps to do this
1) Create apk file using "Use the export Wizard" in "Android Manifest" file of your project.
2) After inserting key and before finishing, MD5 and SHA1 keys are shown as shown is this given pic- (http://i.stack.imgur.com/SldEv.png)
3) Create new API Key for Android project in https://console.developers.google.com for new SHA1 which is retrieved in point 2).
4)Use that API key in manifest file as shown below
5)Clean your project and build APK file again as per point 1).
6) You can see google maps now in that apk.
There are two things to remember and get this working.
Debug Build Variant
Generate a new android debug key using the keytool
Associate this key (SHA-1) with the android map api key on google console
The debug mode has a google_maps_api.xml where the android maps api key is stored (src/debug/.../google_maps_api.xml) as a string "google_maps_key"
Release Build Variant
Generate a new android release key using the keytool
Assoiciate this key (SHA-1) with a new android map api key on google console
The release mode has a google_maps_api.xml where the release android maps api key is stored (src/release/.../google_maps_api.xml) as a string "google_maps_key".
In the AndroidManifest.xml add the following line :
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/google_maps_key" />
Follow the normal procedure for debug and release. It should work seamlessly.
create another Maps API key (to put in your manifest) corresponding with you release
keystore for release.
check Google's documentation
you cannot use same key that you used in debug in the release, they have different works.
to solve this problem you have to generate new Google map key API KEY form the key store that you are using in you release copy
see this video for more details
https://www.youtube.com/watch?v=xLJ0jDFdUZ0
for futures refs ---my case--- there are two google_maps_api.xml files where you need to put your google api key. You can very easily do the mistake to replace YOUR_API_KEY in only one of them (especially if you just deleted the google api/app and created new ones)
In the Google Api console, where we have created the API KEY we have an option to add multiple finger prints to the same key. What I did was adding two SHA1 finger print for my debug keystore and release keystore and the same API key worked for me.
Note the below is for Ubuntu specifically:
Get SHA1 for the debug using the below command
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
For getting SHA1 for release the command changes to
keytool -list -v -keystore /home/atul/Desktop/Learnings/Projects/TestApp/keystore.jks -alias test -storepass password -keypass password
where
/home/atul/Desktop/Learnings/Projects/TestApp/keystore.jks is the path where my keystore file for the signed apk is present
test is the key alias name used while genrating the signed key store
and password is the password used while signing the apk
Hope this helps. Happy coding :)
I had a similar issue and the problem was that I generated the apk from Android Studio without first selecting the right flavour. This means my manifest was still using the Google Maps API key that I created for the debug flavour.
Please make sure you select the release flavour in your Android Studio. See screenshot below:
How do I get the release api SHA1 fingerprint:
install your signed APK, from Playstore, or just copying it to the phone.
Plug USB cable if it is a real phone, and open Android Studio.
The first time you try to get maps, a Log entry will show something like:
E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: AIzaS<YOUR KEY YOUR KEY YOUR KEY YOUR KEY>
Android Application (<cert_fingerprint>;<package_name>): 56:AF:B2:<THIS IS WHAT YOU ARE LOOKING FOR>;br.com.tinx.<your package>
then, just follow those instructions, creating a new entry in the Developer Console.
if you hit your app maps prior seeing the log, you may need to close app from memory and try again)
this procedure should work on an emulator too.
If you are created SHA1 code from custom keystore use the same in release mode. or generate apk by signing with that same keystore and test.
Before that you need clear app data (Setting->App-select app-Clear data->uninstall) and try. this worked for me.
Ensure that package name is same as that in google developer console.
I had a similar problem: after creating a couple of new variants builds with same type ("release") but some new flavors ("free" and "premium"), the Google Maps fragment did not show anymore the maps and the screen appeared totally blank. In the logcat I could only see next error message "Unexpected response code 400 for https://clients4.google.com/glm/mmap/api" that probably was indicating some problem with the Google Maps API access.
Of course I reviewed again all the Google Cloud API process in order to check if something was missing in my API key credentials, but I did not find anything wrong. In fact, for new APK's it is indicated to add the builds info (name+fingerprint) to the existing Project Credentials in order to inherit the same API key that is still valid.
The instructions that we can read are very clear: "Add your package name and SHA-1 signing-certificate fingerprint to restrict usage to your Android apps. Get the package name from your AndroidManifest.xml file. Then use the following command to get the fingerprint: keytool -list -v -keystore mystore.keystore".
The problem in my case was that my new variants "package names" were not the one existing in the Manifest package name ("com.example.app_name.release"). In fact, due to my new flavors I had the same Manifest name BUT two new "real" package names: "com.example.app_name.free.release" and "com.example.app_name.premium.release". Those names do not appear written in the Manifest file as such as they correspond to the Gradle configuration where flavors are defined (in my case with "applicationIdSuffix" attribute). This is quite confusing for me as Gradle "application id" should not overlap the Manifest "package name". But when we read carefully all the Android documentation, we can read "if manifest package name is different than Gradle applicationId, build will copy the application ID in final manifest file". Of course, both variants have the same fingerprint as both are still of the same build type ("release").
So the solution was to add in the same Project Credentials the two new variant entries to inherit the same API key:
original entry (don't need to delete it): Package name = "com.example.app_name.release" - SHA-1 certificate fingerprint = "xxxxx"
new entry 1: Package name = "com.example.app_name.free.release" - SHA-1 certificate fingerprint = "xxxxx" no change, same as used until now
new entry 2: Package name = "com.example.app_name.premium.release" - SHA-1 certificate fingerprint = "xxxxx" no change, same as used until now
Finally, it may be needed to clean your build in order to ensure that you are really watching the correct updated behavior in your maps fragment or activity.
About the rest of recommendations, in my case I did not have to apply them:
- no need to hardcode the API key in the Manifest
- no need to create a new API key for the new variants APK's
- no need to use the google_maps_api.xml files
Below method worked for me:
Put google maps api key in manifest as hardcoded text mentioned by #Florence Herrou
Android Studio creates inside:
app\src\debug\res\values\google_maps_api.xml (debug) //add key here
Add key inside ->
app\src\release\res\values\google_maps_api.xml (release) //add key here
Google key has two types of Security.
1.Non restricted key
2.Restricted key (Android restricted through SHA-1)
Note: Use Restricted key for Maps,Places, but not for Google Directions. use Non restricted api key for google Directions . bcz its web based api response so restricted key doesnt work.
-> When using Non Restricted key
look into two google_maps_api.xml files, one in the app/src/debug/res/values folder and the other in the app/src/release/res/values folder, but only the debug one contains your API key. make sure key is same in both files.
-> When usingRestricted (Android SHA-1) key
Step - 1 : look into two google_maps_api.xml files, one in the app/src/debug/res/values folder and the other in the app/src/release/res/values folder, but only the debug one contains your API key. make sure key is same in both files.
Step - 2 : Generate SHA-1 using AndroidStudio (gradle tab in Left Pane and select signing Report) and add as a item in google Developer console for the Api key which your using.
Step - 3: As soon as you generated Signed Apk google will overwrite your Androidstudio generated SHA-1 a with google own SHA-1 key. so u need to get tht also to be added for Api key in Api key in Developer console
Goto Release Management -> App Signing -> and copy the SHA-1 certificate fingerprint from App signing certificate
Paste this newly copied SHA-1 fingerprint to Developer Console and map in release mode will show.
Step 4: Add Release build SHA-1 also to Api key in Developer console like below.
Goto Release Management -> App Signing -> and copy the SHA-1 certificate fingerprint from Upload certificate
Paste this newly copied SHA-1 fingerprint to Developer Console and map in release mode will show.

Categories

Resources