Skip to content

Commit e74ffb6

Browse files
authored
Utils | Added configure-sdk and bump-version scripts (#219)
* Enabled development against local copy of klaviyo-android-sdk via composite builds. * Added configure-sdk.sh script to manage switching between local and remote SDK targets for android. * Added iOS config to the script * Aaaand a bump-version script to walk you through a version update --------- Co-authored-by: Evan Masseau <>
1 parent 38f9782 commit e74ffb6

9 files changed

Lines changed: 435 additions & 2 deletions

android/build.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath "com.android.tools.build:gradle:7.3.1"
11+
// Android Gradle Plugin. Best to keep in sync with the klaviyo-android-sdk AGP version
12+
classpath "com.android.tools.build:gradle:8.8.0"
1213
// noinspection DifferentKotlinGradleVersion
1314
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1415
}
@@ -95,7 +96,7 @@ def klaviyoAndroidSdkVersion = getExtOrDefault("klaviyoAndroidSdkVersion")
9596
def kotlin_version = getExtOrDefault("kotlinVersion")
9697
def localProperties = new Properties()
9798
if (rootProject.file("local.properties").canRead()) {
98-
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
99+
localProperties.load(new FileInputStream(rootProject.file("local.properties")))
99100
}
100101
def reactNativeAndroidVersion = localProperties['reactNativeAndroidVersion'] ?: ""
101102

@@ -113,6 +114,7 @@ dependencies {
113114
//noinspection GradleDynamicVersion
114115
implementation "com.facebook.react:react-native:+"
115116
}
117+
116118
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
117119

118120
// Klaviyo Android SDK

android/gradle.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,8 @@ KlaviyoReactNativeSdk_minSdkVersion=23
1717
KlaviyoReactNativeSdk_targetSdkVersion=31
1818
KlaviyoReactNativeSdk_compileSdkVersion=31
1919
KlaviyoReactNativeSdk_ndkversion=21.4.7075529
20+
21+
# For local SDK development: set to true in your local.properties file
22+
# you must set separately for the example app and the library
23+
localCompositeBuild=false
24+
localSdkPath=../../klaviyo-android-sdk

android/local.properties.template

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,8 @@
66
## Used for local SDK development, so that gradle can locate the
77
# correct RN version outside the context of an application
88
reactNativeAndroidVersion=0.78.0
9+
10+
# For local SDK development: set to true in your local.properties file
11+
# you must set separately for the example app and the library
12+
localCompositeBuild=false
13+
localSdkPath=../../klaviyo-android-sdk

android/settings.gradle

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Substitute the jitpack SDK dependency for your local instance of the project
2+
// Enabling here allows you to develop against a local android SDK for kotlin files in the library module
3+
if (file("local.properties").canRead()) {
4+
def localProperties = new Properties()
5+
localProperties.load(new FileInputStream(file("local.properties")))
6+
localCompositeBuild = localProperties["localCompositeBuild"] ?: localCompositeBuild
7+
localSdkPath = localProperties["localSdkPath"] ?: localSdkPath
8+
}
9+
10+
if (localCompositeBuild == "true") {
11+
def sdkDirectory = new File(localSdkPath)
12+
13+
if (!sdkDirectory.exists()) {
14+
throw new GradleException("Local Klaviyo Android SDK directory does not exist: " + sdkDirectory.getAbsolutePath())
15+
} else {
16+
print("Configuring composite project with local Klaviyo Android SDK for library.")
17+
}
18+
19+
includeBuild(sdkDirectory) {
20+
dependencySubstitution {
21+
// substitute remote dependency with local module
22+
substitute module("com.github.klaviyo.klaviyo-android-sdk:core") using project(":sdk:core")
23+
substitute module("com.github.klaviyo.klaviyo-android-sdk:analytics") using project(":sdk:analytics")
24+
substitute module("com.github.klaviyo.klaviyo-android-sdk:forms") using project(":sdk:forms")
25+
substitute module("com.github.klaviyo.klaviyo-android-sdk:push-fcm") using project(":sdk:push-fcm")
26+
}
27+
}
28+
}

bump-version.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
#!/bin/bash
2+
3+
# Prompt for the new React SDK version
4+
read -rp "Enter the new React SDK version: " new_version
5+
6+
# Update SDK version in package.json
7+
if [[ -f "package.json" ]]; then
8+
sed -i '' "0,/\"version\": \".*\"/s//\"version\": \"$new_version\"/" package.json
9+
echo "Updated SDK version in package.json."
10+
else
11+
echo "Error: package.json not found."
12+
exit 1
13+
fi
14+
15+
# Update klaviyo_sdk_version in iOS plist file
16+
plist_file="ios/klaviyo-sdk-configuration.plist"
17+
if [[ -f "$plist_file" ]]; then
18+
/usr/libexec/PlistBuddy -c "Set :klaviyo_sdk_version $new_version" "$plist_file"
19+
echo "Updated klaviyo_sdk_version in $plist_file."
20+
else
21+
echo "Error: $plist_file not found."
22+
exit 1
23+
fi
24+
25+
# Update klaviyo_sdk_version_override in Android strings.xml
26+
android_strings="android/src/main/res/values/strings.xml"
27+
if [[ -f "$android_strings" ]]; then
28+
sed -i '' "s/<string name=\"klaviyo_sdk_version_override\">.*<\/string>/<string name=\"klaviyo_sdk_version_override\">$new_version<\/string>/" "$android_strings"
29+
echo "Updated klaviyo_sdk_version_override in $android_strings."
30+
else
31+
echo "Error: $android_strings not found."
32+
exit 1
33+
fi
34+
35+
# Prompt for the Android SDK version
36+
read -rp "Enter the Android SDK version: " android_version
37+
38+
# Update Android SDK version in gradle.properties
39+
gradle_properties="./android/gradle.properties"
40+
if [[ -f "$gradle_properties" ]]; then
41+
sed -i '' "s/KlaviyoReactNativeSdk_klaviyoAndroidSdkVersion=.*/KlaviyoReactNativeSdk_klaviyoAndroidSdkVersion=$android_version/" "$gradle_properties"
42+
echo "Updated Android SDK version in $gradle_properties."
43+
else
44+
echo "Error: $gradle_properties not found."
45+
exit 1
46+
fi
47+
48+
# Prompt for the Swift SDK version
49+
read -rp "Enter the Swift SDK version: " swift_version
50+
51+
# Update Swift SDK version in the podspec
52+
podspec_file="klaviyo-react-native-sdk.podspec"
53+
if [[ -f "$podspec_file" ]]; then
54+
sed -i '' "s/\"KlaviyoSwift\", \".*\"/\"KlaviyoSwift\", \"$swift_version\"/" "$podspec_file"
55+
echo "Updated KlaviyoSwift version in $podspec_file."
56+
else
57+
echo "Error: $podspec_file not found."
58+
exit 1
59+
fi
60+
61+
# Run yarn install or npm install in the example app directory
62+
example_dir="example"
63+
if [[ -d "$example_dir" ]]; then
64+
echo "Running yarn install in $example_dir..."
65+
cd "$example_dir" || exit
66+
if ! yarn install; then
67+
echo "yarn install failed. Trying npm install..."
68+
npm install || { echo "Error: Failed to install dependencies."; exit 1; }
69+
fi
70+
cd - || exit
71+
else
72+
echo "Error: $example_dir not found."
73+
exit 1
74+
fi
75+
76+
# Run bundle install and pod update in the iOS directory
77+
ios_dir="$example_dir/ios"
78+
if [[ -d "$ios_dir" ]]; then
79+
cd "$ios_dir" || exit
80+
if [[ -f "Gemfile" ]]; then
81+
echo "Running bundle install..."
82+
bundle install || { echo "Error: Failed to run bundle install."; exit 1; }
83+
fi
84+
echo "Running pod update for KlaviyoSwift..."
85+
bundle exec pod update KlaviyoSwift || { echo "Error: Failed to update pods."; exit 1; }
86+
cd - || exit
87+
else
88+
echo "Error: $ios_dir not found."
89+
exit 1
90+
fi
91+
92+
echo "All tasks completed successfully."

0 commit comments

Comments
 (0)