skip to Main Content

I am building a new app for maps. After the creation of new project, Android studio is expecting the definition of properties in local.properties file , but I don’t know how to define a property. So, please help me with this issue.
the instruction is as follows.

      TODO: Before you run your application, you need a Google Maps API key.

         To get one, follow the directions here:

            https://developers.google.com/maps/documentation/android-sdk/get-api-key

         Once you have your API key (it starts with "AIza"), define a new property in your
         project's local.properties file (e.g. MAPS_API_KEY=Aiza...), and replace the
         "YOUR_API_KEY" string in this file with "${MAPS_API_KEY}".

2

Answers


  1. If you want to define a property with a key sdk.dir then put this it in a local.properties like this

    sdk.dir=C:Program Files (x86)Androidandroid-studiosdk

    And for using this properties in other area you can use this code snippet

          Properties properties = new Properties()
          properties.load(project.rootProject.file('local.properties').newDataInputStream())
          def sdkDir = properties.getProperty('sdk.dir')
          def ndkDir = properties.getProperty('ndk.dir')
    

    Use project.rootProject if you are reading the properties file in a sub-project build.gradle otherwise use

    properties.load(project.rootProject.file('local.properties').newDataInputStream())
    
    Login or Signup to reply.
  2. After getting your API Key from google do the following:

    1. Change the Project navigation type from (Android) to (Project)
      Step 1

    2. locate local.properties

    Step 2

    1. add your key as in below image (MAPS_API_KEY=AIza …):

    Step 3

    1. Final step add a reference in project manifest:

    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search