Android Google map API key application and use (debug/release)

Source: Internet
Author: User

Android requires that each application be digitally signed before it can be used. The signature contains information such as the key, creator, and Creation Unit, and is saved in a keystore. Google map provides the map service for every registered application. application developers need to transmit the keystore fingerprint to Google to obtain the API key. When applying for the map service each time, transmit the API key as a parameter to Google. Google can determine the application's needs based on the API key from the client's legend and determine whether the application has been registered.

Google map in Android is implemented using the mapview control. Its definition in the XML file is as follows:


[Plain]View
Plaincopy

[HTML]View
Plaincopy

  1. <Com. Google. Android. Maps. mapview
  2. Android: Id = "@ + ID/mapview"
  3. Android: layout_width = "match_parent"
  4. Android: layout_height = "match_parent"
  5. Android: clickable = "true"
  6. Android: apikey = "0h91bcbpm7oya_1vun_tl0ygqqupnktt_ejfow"/>

Androdi: apikey is obtained from Google using the fingerprint of the keystore file.

1. debug key

As an android developer, two apikeys are generally required: Debug key and release key. The so-called debug key is used during program development. Because the android program requires a digital signature for use, it is too troublesome to run the program every time during development. Therefore, the system automatically uses debug during the development process. keystore signs the program, debug. keystrore is located in c: \ Documents and Settings \ <username> \ in Windows Server 2003 \. android.

To obtain the fingerprint of DEBUG. keystore, we need to use the following command:

[HTML]View
Plaincopy

  1. $ Keytool-list-alias androiddebugkey-keystore <path_to_debug_keystore>. keystore-storepass Android-keypass android

If it succeeds, the correct fingerprint of the keystore will be output. The format is as follows:

[HTML]View
Plaincopy

  1. 14: 5E: B2: 3A: 3f: de: 50: 61: 07: 2f: 39: 34: DB: 38: 57: dd

Open webpage

Http://code.google.com/android/maps-api-signup.html

Select the agree protocol check box and copy the fingerprint obtained above to obtain the apikey, as shown below:

Copy the key to the mapview in the XML file, and Google map can be used normally.

2. Release key

The method for applying the release key is the same as that for the debug key. The difference is that the release keystrore is not a debug. keystore file, but must be generated by itself. The command is as follows:

[HTML]View
Plaincopy

  1. $ Keytool-genkey-v-keystore my-release-key.keystore-alias alias_name-keyalg RSA-keysize 2048-validity 10000


You can use your own keystore to apply for an API key and write it to mapview.

In addition, the system should not automatically use DEBUG. keystore to sign the application, but the developer must manually sign the application. First, you need to export the project in unsigned mode, right-click the project-> Android tools-> export unsigned application package, such:

Use your own keystore file to sign the application:

[HTML]View
Plaincopy

  1. $ Jarsigner-verbose-sigalg md5withrsa-digestalg sha1-keystore my-release-key.keystore my_application.apk alias_name


The APK signature is an in-situ signature. It will overwrite the original APK and verify whether the signature is successful:

[HTML]View
Plaincopy

  1. $ Jarsigner-verify my_signed.apk


Finally, you need to compress the APK:

[HTML]View
Plaincopy

  1. $ Zipalign-V 4 your_project_name-unaligned.apk your_project_name.apk


References:

Http://developer.android.com/tools/publishing/app-signing.html

Https://developers.google.com/maps/documentation/android/mapkey#registering

Reprinted: http://blog.csdn.net/lrenjun/article/details/7717958

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.