Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set up android module bare bone #7

Merged
merged 6 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
plugins {
id 'com.android.library'
id 'kotlin-android'
}

android {
compileSdk 31

defaultConfig {
multiDexEnabled true

minSdk 16
targetSdk 31
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why disable the minify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was auto generated, we can adjust this later

proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
}

dependencies {
implementation project(':main')
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2'

testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2'
qingzhuozhen marked this conversation as resolved.
Show resolved Hide resolved
testImplementation 'io.mockk:mockk:1.10.6'
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.2'
testImplementation 'org.robolectric:robolectric:4.7.3'
testImplementation 'androidx.test:core:1.4.0'
}
Empty file added android/consumer-rules.pro
Empty file.
21 changes: 21 additions & 0 deletions android/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.amplitude.android;

import android.content.Context;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
assertEquals("com.amplitude.android.test", appContext.getPackageName());
}
}
5 changes: 5 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amplitude.android">

</manifest>
15 changes: 15 additions & 0 deletions android/src/main/java/com/amplitude/android/AndroidAmplitude.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.amplitude.android

import android.content.Context
import com.amplitude.Amplitude
import com.amplitude.platform.plugins.AmplitudeDestination

open class AndroidAmplitude(
val context: Context,
configuration: AndroidConfiguration
): Amplitude(configuration) {

override fun build() {
add(AmplitudeDestination())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.amplitude.android

import com.amplitude.Configuration
import com.amplitude.Constants
import com.amplitude.LoggerProvider
import com.amplitude.StorageProvider
import com.amplitude.android.utilities.AndroidLoggerProvider
import com.amplitude.android.utilities.AndroidStorageProvider
import com.amplitude.events.BaseEvent

class AndroidConfiguration(
apiKey: String,
flushQueueSize: Int = Constants.FLUSH_QUEUE_SIZE,
qingzhuozhen marked this conversation as resolved.
Show resolved Hide resolved
flushIntervalMillis: Int = Constants.FLUSH_INTERVAL_MILLIS,
optOut: Boolean = false,
storageProvider: StorageProvider = AndroidStorageProvider(),
loggerProvider: LoggerProvider = AndroidLoggerProvider(),
minIdLength: Int? = null,
callback: ((BaseEvent) -> Unit)? = null,
useAdvertisingIdForDeviceId: Boolean = false,
useAppSetIdForDeviceId: Boolean = false,
enableCoppaControl: Boolean = false
) : Configuration(apiKey, flushQueueSize, flushIntervalMillis, optOut, storageProvider, loggerProvider, minIdLength, callback)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.amplitude.android.plugins

import com.amplitude.Amplitude
import com.amplitude.events.BaseEvent
import com.amplitude.platform.Plugin

class AndroidContextPlugin : Plugin {
override val type: Plugin.Type = Plugin.Type.Before
override lateinit var amplitude: Amplitude

override fun execute(event: BaseEvent): BaseEvent? {
return event
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.amplitude.android.plugins

import com.amplitude.Amplitude
import com.amplitude.platform.Plugin

class AndroidLifecyclePlugin : Plugin {
override val type: Plugin.Type = Plugin.Type.Utility
override lateinit var amplitude: Amplitude
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.amplitude.android.utilities

import com.amplitude.Amplitude
import com.amplitude.Logger
import com.amplitude.LoggerProvider

class AndroidLogger() : Logger {
override var logMode: Logger.LogMode = Logger.LogMode.INFO

override fun debug(message: String) {
TODO("Not yet implemented")
}

override fun error(message: String) {
TODO("Not yet implemented")
}

override fun info(message: String) {
TODO("Not yet implemented")
}

override fun warn(message: String) {
TODO("Not yet implemented")
}
}

class AndroidLoggerProvider() : LoggerProvider {
override fun getLogger(amplitude: Amplitude): Logger {
return AndroidLogger()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.amplitude.android.utilities

import com.amplitude.Amplitude
import com.amplitude.Storage
import com.amplitude.StorageProvider
import com.amplitude.events.BaseEvent

class AndroidStorage(
val amplitude: Amplitude
) : Storage {
override fun write(event: BaseEvent) {
TODO("Not yet implemented")
}

override fun rollover() {
justin-fiedler marked this conversation as resolved.
Show resolved Hide resolved
TODO("Not yet implemented")
}

override fun getEvents(): List<String> {
TODO("Not yet implemented")
}
}

class AndroidStorageProvider: StorageProvider {
override fun getStorage(amplitude: Amplitude): Storage {
return AndroidStorage(amplitude)
}
}
17 changes: 17 additions & 0 deletions android/src/test/java/com/amplitude/android/ExampleUnitTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.amplitude.android;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
12 changes: 4 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ buildscript {
ext.kotlin_version = "1.5.10"
repositories {
mavenCentral()
google()
}

dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand All @@ -17,16 +19,10 @@ allprojects{
maven { url "https://kotlin.bintray.com/kotlinx" }
}

apply plugin: "kotlin"

compileKotlin {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
freeCompilerArgs = ['-Xjvm-default=enable']
jvmTarget = "1.8"
javaParameters = true
}
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
}
4 changes: 4 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
android.enableJetifier=true
kotlin.code.style=official
1 change: 1 addition & 0 deletions main/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'kotlin'
id 'org.jetbrains.kotlin.jvm'
}

Expand Down
2 changes: 1 addition & 1 deletion main/java/com/amplitude/Amplitude.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ open class Amplitude internal constructor(
*/
constructor(configuration: com.amplitude.Configuration) : this(configuration, com.amplitude.State())

internal fun build() {
open fun build() {
add(ContextPlugin())
add(AmplitudeDestination())

Expand Down
2 changes: 1 addition & 1 deletion main/java/com/amplitude/Configuration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.amplitude.events.BaseEvent
import com.amplitude.utilities.ConsoleLoggerProvider
import com.amplitude.utilities.InMemoryStorageProvider

data class Configuration(
open class Configuration(
val apiKey: String,
val flushQueueSize: Int = Constants.FLUSH_QUEUE_SIZE,
val flushIntervalMillis: Int = Constants.FLUSH_INTERVAL_MILLIS,
Expand Down
1 change: 1 addition & 0 deletions main/java/com/amplitude/platform/Plugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface Plugin {
Before,
Enrichment,
Destination,
Utility,
Observe
}

Expand Down
1 change: 1 addition & 0 deletions main/java/com/amplitude/platform/Timeline.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ internal class Timeline {
Plugin.Type.Before to Mediator(mutableListOf()),
Plugin.Type.Enrichment to Mediator(mutableListOf()),
Plugin.Type.Destination to Mediator(mutableListOf()),
Plugin.Type.Utility to Mediator(mutableListOf())
)
lateinit var amplitude: com.amplitude.Amplitude

Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ include 'main'
project(':main').projectDir = file('main')
include 'samples:kotlin-jvm-app'
project(':samples:kotlin-jvm-app').projectDir = file('samples/kotlin-jvm-app')
include 'android'
project(':android').projectDir = file('android')