Skip to content

Commit

Permalink
Fixes for React Native Apps <= 0.72.0 (#71)
Browse files Browse the repository at this point in the history
* Fix the react-native gradle dependency
* Add a local property to enable specifying react-native version for the SDK for local development
* Specify Kotlin version that is compatible with Android SDK's (although this didn't seem to actually cause any build errors)
* Remove accidental use of an extension method that is technically SDK 24+

---------

Co-authored-by: Evan Masseau <>
  • Loading branch information
evan-masseau committed Feb 2, 2024
1 parent 9f78438 commit 6208295
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
26 changes: 22 additions & 4 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,33 @@ repositories {
}

def kotlin_version = getExtOrDefault("kotlinVersion")
def localProperties = new Properties()
if (rootProject.file("local.properties").canRead()) {
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
}
def reactNativeVersion = localProperties['reactNativeAndroidVersion'] ?: ""


dependencies {
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-android:0.73.1"
if (reactNativeVersion) {
// For local development of the SDK code, specify the react-android version to use
// So that the SDK can be built and .kt files are linted against a real version of react-native
implementation "com.facebook.react:react-android:$reactNativeVersion"
} else {
// Production build / once embedded in a react-native app,
// the react-native version gets loaded in from the application dependencies.
// For < 0.71, this will be from the local maven repo
// For > 0.71, this will be replaced by `com.facebook.react:react-android:$version` by react gradle plugin
//noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
}
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"

// Klaviyo Android SDK
api "com.github.klaviyo.klaviyo-android-sdk:analytics:2.0.0"
api "com.github.klaviyo.klaviyo-android-sdk:push-fcm:2.0.0"

// We used reflection to enumerate keywords in the Klaviyo Android SDK dynamically
implementation "org.jetbrains.kotlin:kotlin-reflect:1.8.21"
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
# org.gradle.parallel=true
#Tue Dec 19 15:08:27 EST 2023
KlaviyoReactNativeSdk_compileSdkVersion=31
KlaviyoReactNativeSdk_kotlinVersion=1.7.0
KlaviyoReactNativeSdk_kotlinVersion=1.8.0
KlaviyoReactNativeSdk_minSdkVersion=23
KlaviyoReactNativeSdk_ndkversion=21.4.7075529
KlaviyoReactNativeSdk_targetSdkVersion=31
Expand Down
6 changes: 6 additions & 0 deletions android/local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## This file must *NOT* be checked into Version Control Systems,
## as it contains information specific to your local configuration

## Uncomment for local SDK development so that gradle can locate the
## correct RN version outside the context of an application
#reactNativeAndroidVersion=0.73.1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class KlaviyoReactNativeSdkModule internal constructor(private val context: Reac
override fun setProfile(profile: ReadableMap) {
val parsedProfile = Profile()

profile.toHashMap().forEach { (key, value) ->
profile.toHashMap().iterator().forEach { (key, value) ->
when (key) {
LOCATION, PROPERTIES ->
(value as? HashMap<*, *>)?.forEach { (key, value) ->
Expand Down

0 comments on commit 6208295

Please sign in to comment.