Pull Fabric props from environment variables, default to 0 which stops build failures

This commit is contained in:
Aidan Follestad 2019-01-24 16:03:12 -08:00
parent 77f939b095
commit 571e7ebff3
5 changed files with 34 additions and 30 deletions

View file

@ -1,3 +0,0 @@
[*.kt]
indent_size = 2
continuation_indent_size=4

2
.idea/misc.xml generated
View file

@ -40,7 +40,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -4,17 +4,7 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'
def getFabricApiKey() {
def propsFile = project.rootProject.file('local.properties')
if (!propsFile.exists()) {
return ""
}
Properties properties = new Properties()
properties.load(propsFile.newDataInputStream())
return properties.getProperty("fabric.apikey") ?: ""
}
apply from: '../fabric.gradle'
android {
compileSdkVersion versions.compileSdk
@ -26,7 +16,6 @@ android {
targetSdkVersion versions.compileSdk
versionCode versions.publishVersionCode
versionName versions.publishVersion
manifestPlaceholders = [fabricKey:getFabricApiKey()]
}
buildTypes {

View file

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.afollestad.nocknock">
<application>
<meta-data
android:name="io.fabric.ApiKey"
android:value="${fabricKey}"/>
</application>
</manifest>

32
fabric.gradle Normal file
View file

@ -0,0 +1,32 @@
apply plugin: 'io.fabric'
ext.getFabricApiKey = {
return System.getenv('FABRIC_APIKEY') ?: "0"
}
ext.getFabricApiSecret = {
return System.getenv('FABRIC_APISECRET') ?: "0"
}
def buildFabricProperties() {
def propertiesFile = file("fabric.properties")
def apiSecret = getFabricApiSecret()
def apiKey = getFabricApiKey()
if (apiSecret == "0" || apiKey == "0") {
logger.warn("API key and/or secret env variables not found, defaulting to 0.")
}
if (propertiesFile.exists()) {
propertiesFile.delete()
}
def commentMessage = "suppress inspection \"UnusedProperty\" for whole file"
ant.propertyfile(file: "fabric.properties", comment: commentMessage) {
entry(key: "apiSecret", value: apiSecret)
entry(key: "apiKey", value: apiKey)
}
}
afterEvaluate {
buildFabricProperties()
}