Biswajit Sahoo
Biswajit Sahoo

Reputation: 49

Defining Properties in local.properties file in Android Studio

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}".

Upvotes: 5

Views: 9160

Answers (3)

Carlos Saltos
Carlos Saltos

Reputation: 1511

You should not add custom properties at the local.properties file, that is for Gradle internal use only ... just create a new properties file and load it inside Gradle with standard configuration code like for example this key store properties file at https://developer.android.com/build/gradle-tips#remove-private-signing-information-from-your-project.

More info at https://developer.android.com/build

Upvotes: 0

Mohd Ahmed
Mohd Ahmed

Reputation: 317

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

Upvotes: 8

Manish Kumar
Manish Kumar

Reputation: 21

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)\Android\android-studio\sdk

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())

Upvotes: 2

Related Questions