Android Google Maps API Key - android

I'm developing an app that uses Google Maps. I got the debug keystore and got the API key to work while I am debugging my program in Eclipse, but I am thoroughly confused in how to change this so that it works on an Android device when I export the .apk. I have searched around Google, but am mainly finding things that use the debug.keystore and I don't think this is what I want to use when I deploy this on an Android device, because I sent my .apk to a friend and he said he is getting gray boxes on the Map View.
Can anyone fill me in, step-by-step, on how to correctly make a new keystore for my app and how to sign my app so that it will work outside of debugging on Eclipse? A video tutorial would be preferable, but if not, simple 1-2-3 step type instructions would work. Thanks!

Eclipse (through ADT) has a nice wizard that lets you create a real keystore and build a signed apk. Right click your project, then Android Tools -> Export signed Application package
For the google maps key just follow these instructions

head to the command prompt, (I use windows so I'm going to go that route but same general idea for the other OS's)
The keytool program you'll need is part of the JDK so you do have it if your able to compile the apps at all. but it may not be on the app path so you can't just type it into the command line to be used.
for me it was in:C:\Program Files\Java\jdk1.7.0_21\bin so to get it on the app path I typed this in set PATH=%PATH%;C:\Program Files\Java\jdk1.7.0_21\bin
next you need to change to the directory your keystore files are in for me that is: C:\android\keys so I used the command cd C:\android\keys to change to the proper directory
then you need to run the keytool with the proper settings so it knows your after the key and not trying to do something else. the command I used was: keytool -list -v -keystore Testkeys and Testkeys is the name of my keystore use the name of your keystore there instead.
Last by not least it will spit out a whole bunch of different information but the one your looking for will look something like this
SHA1: A1:DF:83:DD:04:B2:26:10:B2:EB:26:00:90:75:D0:10:66:5E:A9:8A
you want all the numbers and : that are after the "SHA1: " that is your app key for the published version of your app, the one you need to register with the google maps api service, and then they will give you a new map api key that you need to put in your project and then republish it, and then the maps will 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 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.

how do i find my SHA 1 for my android app in android studio?

I'm new to developing Android apps and I wanted to create a Google map inside of a Fragment. So far I've gotten the part where I need the API key and I'm confused by the instructions from the Android developer site and everything I've found online hasn't cleared my confusion.
Could someone provide me with a step by step of how to get my SHA1 fingerprint on Windows 7?
You cannot obtain the API_KEY until you get your SHA1.
Click here to get a nice tutorial that will guide you step by step with images (Specifically when you are operating on Windows 7).
Hope this would Help!!
There are two kinds of fingerprints, debug and release. Assuming you want a release one, then from a console window, you need to run this command to get the fingerprint
keytool -exportcert -alias MY_RELEASE_KEY_ALIAS -keystore MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE -list -v
The keytool program is in your JDK bin folder. So on Windows, something like C:\Program Files\Java\jdk1.8.0_20\bin is where you should find keytool
Last thing to note is that MY_FULL_PATH_TO_RELEASE_KEYSTORE_FILE in the command above should be the full path to your .keystore file, including the file name
After all that, you will be finally be provided with several fingerprints, including the SHA1. You can copy that, and go back to Google Developers Console and paste it as a new line in the allowed Android Applications, with your package name added to the end, separated by a semi-colon.

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!

Google maps not loading android

Google map gets displayed on device when I plug it to my machine and run app from eclipse. But when I run the same code from another machine's eclipse map is not displayed.
It shows "Failed to load map. Could not contact google services. This is probably due to wifi connection or the request is not authorized."
I have all the permission and other manifest tags added correctly with correct API key. This is obvious as it runs from my machine.
Has anyone encountered similar problem?
As the API key is coupled with your debug keystore, the best way would be to copy this keystore to other machines, which are also used for development. debug.keystore is in .android folder in your user folder.
I know the answer for your problem! You need a new API Key for the new machine you are trying to launch the app from. You'll need the SHA1 fingerprint of the new machine in order to create the new API Key in the API Console.
With the new Android Development Tools you can do this very easily. You no longer need to find the debug.keystore and the java bin files to run the previous command line in the command console that generates the SHA1.
To generate the SHA1: Open ADT. Go to Main Menu Window => Preferences => Android => Build. There you have the SHA1 and MD5 options. You know what to do now: join the SHA1 with the package of your project: e.g. SHA1;myandroid.project.
You have the new Key for the new machine. Update the manifest.xml and run the project again. It should work now.
I have just noticed another issue: Be careful when you create your apk file, if you sign it with a keystore you have created, your application map don´t work. I have read that you have to sign it with the same file you have used for creating the API key(debug.keystore). Keep this in mind !
You may be run your code in newer system. For that you need to get new API key using the new SHA1 from the console.
Orelse,
Follow the process,
Go to the home of your older system
Find the location ---- /.android/debug.keystore
Copy the debug.keystore
Replace the debug.keystore in your newer system
Your map will be working fine.
Advance wishes :)
You can't just move your code to another machine and expect it to work.
As been mentioned already you Google Map uses an API key that was produces using the SHA1 fingerprint from the debug.keystore folder in your user folder.
In order this to work you have 2 choices:
1. Copy the the debug.keystore to the other machine you want to develop this project on.
2. Register the SHA1 fingerprint from the new machine into the console as well.
Have you added the keyhash from the other machine to your Google API Console account?

Categories

Resources