diff --git a/.gitignore b/.gitignore index 4dc892335..a5bf52c00 100644 --- a/.gitignore +++ b/.gitignore @@ -73,3 +73,7 @@ gen-external-apklibs # macOS .DS_Store + +# Token files +.leanplum_token +.adjust_token diff --git a/app/build.gradle b/app/build.gradle index 05235e75d..afafd95b3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -181,12 +181,12 @@ android.applicationVariants.all { variant -> def buildDate = Config.generateBuildDate() buildConfigField 'String', 'BUILD_DATE', '"' + buildDate + '"' -// ------------------------------------------------------------------------------------------------- -// Adjust: Read token from locale file if it exists (Only release builds) -// ------------------------------------------------------------------------------------------------- - def variantName = variant.getName() +// ------------------------------------------------------------------------------------------------- +// Adjust: Read token from local file if it exists (Only release builds) +// ------------------------------------------------------------------------------------------------- + print("Adjust token: ") if (variantName.contains("Release")) { @@ -202,6 +202,25 @@ android.applicationVariants.all { variant -> buildConfigField 'String', 'ADJUST_TOKEN', 'null' println("--") } + +// ------------------------------------------------------------------------------------------------- +// Leanplum: Read token from local file if it exists +// ------------------------------------------------------------------------------------------------- + + print("Leanplum token: ") + + try { + def parts = new File("${rootDir}/.leanplum_token").text.trim().split(":") + def id = parts[0] + def key = parts[1] + buildConfigField 'String', 'LEANPLUM_ID', '"' + id + '"' + buildConfigField 'String', 'LEANPLUM_TOKEN', '"' + key + '"' + println "(Added from .leanplum_token file)" + } catch (FileNotFoundException ignored) { + buildConfigField 'String', 'LEANPLUM_ID', 'null' + buildConfigField 'String', 'LEANPLUM_TOKEN', 'null' + println("X_X") + } } androidExtensions { @@ -224,6 +243,8 @@ dependencies { implementation Deps.sentry + implementation Deps.leanplum + implementation Deps.mozilla_concept_engine implementation Deps.mozilla_concept_storage implementation Deps.mozilla_concept_toolbar diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index 27b92b9e1..868f5f2d1 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -21,6 +21,7 @@ import mozilla.components.support.base.log.logger.Logger import mozilla.components.support.base.log.sink.AndroidLogSink import mozilla.components.support.rustlog.RustLog import org.mozilla.fenix.AdjustHelper.setupAdjustIfNeeded +import org.mozilla.fenix.LeanplumHelper.setupLeanplumIfNeeded import org.mozilla.fenix.components.Components import java.io.File @@ -49,6 +50,7 @@ open class FenixApplication : Application() { setupGlean(this) loadExperiments() setupAdjustIfNeeded(this) + setupLeanplumIfNeeded(this) } protected open fun setupLeakCanary() { diff --git a/app/src/main/java/org/mozilla/fenix/LeanplumHelper.kt b/app/src/main/java/org/mozilla/fenix/LeanplumHelper.kt new file mode 100644 index 000000000..8a0201fcc --- /dev/null +++ b/app/src/main/java/org/mozilla/fenix/LeanplumHelper.kt @@ -0,0 +1,19 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +package org.mozilla.fenix + +import com.leanplum.Leanplum +import com.leanplum.LeanplumActivityHelper +import com.leanplum.annotations.Parser + +object LeanplumHelper { + fun setupLeanplumIfNeeded(application: FenixApplication) { + Leanplum.setApplicationContext(application) + Parser.parseVariables(application) + LeanplumActivityHelper.enableLifecycleCallbacks(application) + Leanplum.setAppIdForProductionMode(BuildConfig.LEANPLUM_ID, BuildConfig.LEANPLUM_TOKEN) + Leanplum.start(application) + } +} diff --git a/build.gradle b/build.gradle index f2700190f..d6ea61e5e 100644 --- a/build.gradle +++ b/build.gradle @@ -30,6 +30,9 @@ allprojects { maven { url "https://maven.mozilla.org/maven2" } + maven { + url "https://repo.leanplum.com/" + } jcenter() } } diff --git a/buildSrc/src/main/java/Dependencies.kt b/buildSrc/src/main/java/Dependencies.kt index 673488369..04b357428 100644 --- a/buildSrc/src/main/java/Dependencies.kt +++ b/buildSrc/src/main/java/Dependencies.kt @@ -11,6 +11,7 @@ private object Versions { const val anko = "0.10.8" const val sentry = "1.7.10" const val leakcanary = "1.6.3" + const val leanplum = "4.3.1" const val androidx_appcompat = "1.1.0-alpha02" const val androidx_constraint_layout = "2.0.0-alpha2" @@ -110,6 +111,8 @@ object Deps { const val leakcanary = "com.squareup.leakcanary:leakcanary-android:${Versions.leakcanary}" const val leakcanary_noop = "com.squareup.leakcanary:leakcanary-android-no-op:${Versions.leakcanary}" + const val leanplum = "com.leanplum:leanplum-core:${Versions.leanplum}" + const val tools_test_runner = "com.android.support.test:runner:${Versions.test_tools}" const val tools_espresso_core = "com.android.support.test.espresso:espresso-core:${Versions.espresso_core}"