Skip to content

Commit

Permalink
Fixes mozilla-mobile#891 - Adds the leanplum sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
boek committed Mar 7, 2019
1 parent d15e4bb commit 7039ae6
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ gen-external-apklibs

# macOS
.DS_Store

# Token files
.leanplum_token
.adjust_token
27 changes: 24 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,12 @@ android.applicationVariants.all { variant ->
def buildDate = Config.generateBuildDate()
buildConfigField 'String', 'BUILD_DATE', '"' + buildDate + '"'

def variantName = variant.getName()

// -------------------------------------------------------------------------------------------------
// Adjust: Read token from locale file if it exists (Only release builds)
// Adjust: Read token from local file if it exists (Only release builds)
// -------------------------------------------------------------------------------------------------

def variantName = variant.getName()

print("Adjust token: ")

if (variantName.contains("Release")) {
Expand All @@ -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 {
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/org/mozilla/fenix/FenixApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -49,6 +50,7 @@ open class FenixApplication : Application() {
setupGlean(this)
loadExperiments()
setupAdjustIfNeeded(this)
setupLeanplumIfNeeded(this)
}

protected open fun setupLeakCanary() {
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/org/mozilla/fenix/LeanplumHelper.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ allprojects {
maven {
url "https://maven.mozilla.org/maven2"
}
maven {
url "https://repo.leanplum.com/"
}
jcenter()
}
}
Expand Down
3 changes: 3 additions & 0 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -111,6 +112,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}"

Expand Down

0 comments on commit 7039ae6

Please sign in to comment.