Skip to content

Instantly share code, notes, and snippets.

View mtilbrook-dev's full-sized avatar

Mitchell Tilbrook mtilbrook-dev

  • Sydney, Australia
View GitHub Profile
@mtilbrook-dev
mtilbrook-dev / build.gradle
Last active August 2, 2018 00:17
Include JaCoCo in module
apply plugin: 'com.android.application'
// or apply plugin: 'com.android.library'
enableJacoco(project)
./gradlew testFlavorXDebugUnitTestCoverage
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'org.jacoco:org.jacoco.core:0.8.2'
}
}
def mainSrc = [
'src/main/java',
"src/$productFlavorName/java",
"src/$buildTypeName/java"
// Kotlin src folders
'src/main/kotlin',
"src/$productFlavorName/kotlin",
"src/$buildTypeName/kotlin"
]
@mtilbrook-dev
mtilbrook-dev / openClass.kt
Last active September 11, 2018 22:40
kotlin-allopen annotation
/**
* This annotation allows us to open some classes for mocking purposes while they are final in
* release builds.
*/
@Target(AnnotationTarget.ANNOTATION_CLASS)
annotation class OpenClass
/**
* Annotate a class with [OpenForTesting] if you want it to be extendable in debug builds.
*/
apply plugin: 'kotlin-allopen'
allOpen {
// allows mocking for classes w/o directly opening them for release builds
annotation 'com.android.example.github.testing.OpenClass'
}
// Forked from https://github.com/googlesamples/android-architecture-components/blob/d81da2cb1e3d61e40f052e631bb15883d0f9f637/GithubBrowserSample/app/build.gradle
@mtilbrook-dev
mtilbrook-dev / OpenForTesting.kt
Created September 11, 2018 22:42
Release allopen annotation
@Target(AnnotationTarget.CLASS)
annotation class OpenForTesting
@mtilbrook-dev
mtilbrook-dev / build.gradle
Created September 24, 2018 11:30
Root Build.gradle allopen
buildscript {
dependencies {
// android-gradle-plugin
// …
classpath "org.jetbrains.kotlin:kotlin-allopen:$kotlin_version"
}
}
@mtilbrook-dev
mtilbrook-dev / build.gradle
Created November 12, 2018 00:28
Enable JaCoCo for all Android Modules
subprojects {
afterEvaluate { project ->
BaseExtension android = project.extensions.findByName("android")
if (android != null) {
enableJacoco(project)
}
}
}
@mtilbrook-dev
mtilbrook-dev / mvrx-dagger.kt
Created November 15, 2018 03:52
MvRx Dagger Boilerplate
package au.tilbrook.mvrx.dagger
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModel
import com.airbnb.mvrx.BaseMvRxViewModel
import com.airbnb.mvrx.MvRxState
import com.airbnb.mvrx.MvRxViewModelFactory
import javax.inject.Provider