'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}".
Solution 1:[1]
After getting your API Key from google do the following:
- add your key as in below image (MAPS_API_KEY=AIza ...):
- Final step add a reference in project manifest:
Solution 2:[2]
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())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mohd Ahmed |
| Solution 2 | Manish Kumar |




