Chris Arriola 2ab19b7e0d
feat: Using local.properties to provide API key (#398)
* feat: Using local.properties to provide API key instead of secure.properties.

* Remove redundant declaration in main AndroidManifest.xml

* Migrate ApiDemos - Kotlin to use local.properties.

* Update README for tutorials.

* Genericize.

* Remove references to secure.properties.

* s/master/main
2020-11-25 13:38:00 -08:00

103 lines
3.1 KiB
Groovy

import org.apache.tools.ant.filters.ConcatFilter
apply plugin: 'com.android.application'
apply plugin: 'project-report'
// Set the properties within `local.properties` into a `Properties` class so
// that values within `local.properties` (e.g. Maps API key) are accessible in
// this file.
Properties properties = new Properties()
if (rootProject.file("local.properties").exists()) {
properties.load(rootProject.file("local.properties").newDataInputStream())
}
def mapsApiKey = properties.getProperty("MAPS_API_KEY", "")
android {
compileSdkVersion 30
defaultConfig {
applicationId "com.example.mapdemo"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true
// Inject the Maps API key into the manifest
manifestPlaceholders = [ mapsApiKey : mapsApiKey ]
// Reading the Maps API key into a BuildConfig value. This is only
// necessary so that the sample app can display a toast message if the
// API key was not set, otherwise, this can be skipped.
buildConfigField("String", "MAPS_API_KEY", "\"$mapsApiKey\"" )
// To add your Maps API key to this project:
// 1. Open the root project's local.properties file
// 2. Add this line, where YOUR_API_KEY is your API key:
// MAPS_API_KEY=YOUR_API_KEY
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "version"
productFlavors {
gms {
dimension "version"
applicationIdSuffix ".gms"
versionNameSuffix "-gms"
}
v3 {
dimension "version"
applicationIdSuffix ".v3"
versionNameSuffix "-v3"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation "androidx.recyclerview:recyclerview:1.1.0"
// GMS
gmsImplementation 'com.google.android.gms:play-services-maps:17.0.0'
// V3
v3Implementation 'com.google.android.libraries.maps:maps:3.1.0-beta'
// Tests
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
task generateV3(type: Copy) {
group "V3 Beta"
description "Copies source code from GMS to V3 BETA."
from 'src/gms/java'
into 'src/v3/java'
filter { line ->
line.replace('com.google.android.gms.maps', 'com.google.android.libraries.maps')
}
filter(ConcatFilter, prepend: file('../../V3_FILE_HEADER'))
}
task generateV3Layout(type: Copy) {
group "V3 Beta"
description "Copies layout files from GMS to V3 BETA."
from 'src/gms/res/layout'
into 'src/v3/res/layout'
filter { line ->
line.replace('com.google.android.gms.maps', 'com.google.android.libraries.maps')
}
}