From f75793f17a0eb1bdccb0da9188219cd0f2f4398f Mon Sep 17 00:00:00 2001 From: Evan Masseau <> Date: Mon, 29 Jan 2024 13:07:38 -0500 Subject: [PATCH 1/2] Add template local.properties file --- example/android/app/build.gradle | 8 ++++++++ .../com/klaviyoreactnativesdkexample/MainApplication.kt | 2 +- example/android/gradle.properties | 4 ++++ example/android/local.properties | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 example/android/local.properties diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 1aa8789..a214a51 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -70,6 +70,12 @@ def enableProguardInReleaseBuilds = false def jscFlavor = 'org.webkit:android-jsc:+' android { + def localProperties = new Properties() + if (rootProject.file("local.properties").canRead()) { + localProperties.load(new FileInputStream(rootProject.file("local.properties"))) + } + def apiKey = localProperties['publicApiKey'] ?: publicApiKey + ndkVersion rootProject.ext.ndkVersion buildToolsVersion rootProject.ext.buildToolsVersion compileSdk rootProject.ext.compileSdkVersion @@ -93,6 +99,7 @@ android { buildTypes { debug { signingConfig signingConfigs.debug + buildConfigField "String", "PUBLIC_API_KEY", "\"${apiKey}\"" } release { // Caution! In production, you need to generate your own keystore file. @@ -100,6 +107,7 @@ android { signingConfig signingConfigs.debug minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" + buildConfigField "String", "PUBLIC_API_KEY", "\"${apiKey}\"" } } } diff --git a/example/android/app/src/main/java/com/klaviyoreactnativesdkexample/MainApplication.kt b/example/android/app/src/main/java/com/klaviyoreactnativesdkexample/MainApplication.kt index 53f2558..757cd4e 100644 --- a/example/android/app/src/main/java/com/klaviyoreactnativesdkexample/MainApplication.kt +++ b/example/android/app/src/main/java/com/klaviyoreactnativesdkexample/MainApplication.kt @@ -36,7 +36,7 @@ class MainApplication : Application(), ReactApplication { override fun onCreate() { super.onCreate() SoLoader.init(this, false) - Klaviyo.initialize("YOUR_PUBLIC_API_KEY", this) + Klaviyo.initialize(BuildConfig.PUBLIC_API_KEY, this) registerActivityLifecycleCallbacks(Klaviyo.lifecycleCallbacks) if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { diff --git a/example/android/gradle.properties b/example/android/gradle.properties index a46a5b9..2fe38e9 100644 --- a/example/android/gradle.properties +++ b/example/android/gradle.properties @@ -39,3 +39,7 @@ newArchEnabled=false # Use this property to enable or disable the Hermes JS engine. # If set to false, you will be using JSC instead. hermesEnabled=true + +# Public API Key for your Company +# or override this from an untracked local.properties file +publicApiKey=YOUR_PUBLIC_API_KEY diff --git a/example/android/local.properties b/example/android/local.properties new file mode 100644 index 0000000..7990cac --- /dev/null +++ b/example/android/local.properties @@ -0,0 +1,5 @@ +## This file must *NOT* be checked into Version Control Systems, +# as it contains information specific to your local configuration, +# such as your Klaviyo company ID aka "Public API Key". + +#publicApiKey=YOUR_PUBLIC_API_KEY From 3f353f8a60baf57a4aed9ed92450fef8b2d6eed1 Mon Sep 17 00:00:00 2001 From: Evan Masseau <> Date: Fri, 2 Feb 2024 12:03:29 -0500 Subject: [PATCH 2/2] Be clearer about VCS status of these files. --- android/local.properties | 9 +++++---- example/android/local.properties | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/android/local.properties b/android/local.properties index 5d66243..509f9fd 100644 --- a/android/local.properties +++ b/android/local.properties @@ -1,6 +1,7 @@ -## This file must *NOT* be checked into Version Control Systems, -## as it contains information specific to your local configuration +## Changes in this file must *NOT* be tracked by Version Control Systems, +# as it contains information specific to your local configuration. +# Only the base template should be checked in to VCS. -## Uncomment for local SDK development so that gradle can locate the -## correct RN version outside the context of an application +## Uncomment for local SDK development, so that gradle can locate the +# correct RN version outside the context of an application #reactNativeAndroidVersion=0.73.1 diff --git a/example/android/local.properties b/example/android/local.properties index 7990cac..76dc8c8 100644 --- a/example/android/local.properties +++ b/example/android/local.properties @@ -1,5 +1,6 @@ -## This file must *NOT* be checked into Version Control Systems, +## Changes in this file must *NOT* be tracked by Version Control Systems, # as it contains information specific to your local configuration, # such as your Klaviyo company ID aka "Public API Key". +# Only the base template should be checked in to VCS. #publicApiKey=YOUR_PUBLIC_API_KEY