Skip to content

Commit

Permalink
dispatcher: change gradle piano api depency to compileOnly + check fo…
Browse files Browse the repository at this point in the history
…r old sdk
  • Loading branch information
arnaud-roland committed Dec 6, 2023
1 parent 5a8db3b commit 813f8a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
5 changes: 3 additions & 2 deletions piano-dispatcher/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ android {
dependencies {

api 'com.batch.android:batch-sdk:1.20.1'
api 'io.piano:analytics:3.2.0' // Legacy Piano SDK
api 'io.piano.android:analytics:3.3.5' // New Piano SDK

compileOnly 'io.piano:analytics:3.2.0' // Legacy Piano SDK
compileOnly 'io.piano.android:analytics:3.3.5' // New Piano SDK

testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test.ext:junit:1.1.5'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public BatchEventDispatcher getDispatcher(Context context) {
if (instance == null) {
if (isNewPianoSDKPresent()) {
instance = new PianoDispatcher();
} else {
} else if(isOldPianoSDKPresent()) {
Log.w("Batch", "PianoDispatcher - It looks like your app is running with an old version of the Piano Analytics SDK. You should migrate on version 3.3.0 or newer.");
instance = new LegacyPianoDispatcher(context);
} else {
Log.w("Batch", "PianoDispatcher - It looks like the Piano Analytics SDK is not present. Did you add the dependency in your build.gradle?");
}
instance.enableBatchCustomEvents(getBooleanMetaDataInfo(context, CUSTOM_EVENT_ENABLED_METADATA, false));
instance.enableBatchOnSiteAdsEvents(getBooleanMetaDataInfo(context, ONSITE_AD_EVENT_ENABLED_METADATA, true));
Expand Down Expand Up @@ -77,4 +79,17 @@ private boolean isNewPianoSDKPresent() {
return false;
}
}

/**
* Check if the old Java Piano SDK (3.2.1-) is present.
* @return Whether the old Piano SDK is present.
*/
private boolean isOldPianoSDKPresent() {
try {
Class.forName("io.piano.analytics.PianoAnalytics");
return true;
} catch (ClassNotFoundException e) {
return false;
}
}
}

0 comments on commit 813f8a9

Please sign in to comment.