Skip to content

Instantly share code, notes, and snippets.

View realdadfish's full-sized avatar

Thomas Keller realdadfish

View GitHub Profile
@realdadfish
realdadfish / Crash.txt
Created April 3, 2020 15:00
Material Components
java.lang.NoSuchMethodError: com.google.android.material.shape.MaterialShapeDrawable.<init>(Landroid/content/Context;Landroid/util/AttributeSet;II)V
at com.google.android.material.dialog.MaterialAlertDialogBuilder.<init>(MaterialAlertDialogBuilder.java:121)
at com.google.android.material.dialog.MaterialAlertDialogBuilder.<init>(MaterialAlertDialogBuilder.java:103)
at our.code.onCreate(OurFragment.kt:112)
at androidx.fragment.app.Fragment.performCreate(Fragment.java:2684)
at androidx.fragment.app.FragmentStateManager.create(FragmentStateManager.java:280)
at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1175)
at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1255)
at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1138)
at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:136)
@realdadfish
realdadfish / detekt.yml
Created March 30, 2020 21:17
Detekt configuration
#
# This file configures the static code analysis done by Detekt (https://arturbosch.github.io/detekt/index.html)
#
# Derivations from the defaults (https://github.com/arturbosch/detekt/blob/master/detekt-cli/src/main/resources/default-detekt-config.yml)
# are not listed here, unless we specifically voted on a rule to be used / not used.
#
# If adaptions to a default rule are made, the _complete_ configuration of that rule should be included here, not
# only the part that is actually overridden. This is important to see the rule in context.
#
# If you want to introduce changes to existing rules and / or want to introduce new rules, please use the
@realdadfish
realdadfish / StubbedObserver.kt
Last active March 26, 2020 11:19
Test Utilities
val singleParamUseCase = ...
// single execution (param is stubbed as "any()")
singleParamUseCase.stubObserver {
onSuccess("yay")
}
viewModel.triggerSomething()
singleParamUseCase.execute("some-param")
@realdadfish
realdadfish / FragmentExt.kt
Last active February 13, 2020 08:59
getOrAddFragment
fun <T : Fragment> FragmentActivity.getOrAddFragment(tag: String, commitNow: Boolean = true, initFun: () -> T): T =
supportFragmentManager.findFragmentByTag(tag) as? T ?: run {
initFun().also {
addFragment(supportFragmentManager, tag, commitNow, it)
}
}
fun <T : Fragment> Fragment.getOrAddFragment(tag: String, commitNow: Boolean = true, initFun: () -> T): T =
childFragmentManager.findFragmentByTag(tag) as? T ?: run {
initFun().also {
@realdadfish
realdadfish / build.gradle
Last active January 27, 2020 08:22
JVM Integration Tests with the Android Gradle Plugin. ATTENTION: Does not work!
android.applicationVariants.all { variant ->
configurations.create("${variant.name}IntegrationTestImplementation") {
extendsFrom configurations.find { it.name == "implementation" }
extendsFrom configurations.find { it.name == "${variant.name}Implementation" }
}
def sourceSet = android.sourceSets.create("${variant.name}IntegrationTest") {
// this fails here because `compileClasspath` is not existant in `AndroidSourceSet`
compileClasspath += variant.javaCompile.classpath
runtimeClasspath += variant.javaCompile.classpath
task resolveDependencies {
description "Resolves dependencies for all build variants of this Android module"
doLast {
project.buildscript.configurations.findAll { it.canBeResolved }.each { it.resolve() }
}
}
def factory = project.getObjects()
if (project.plugins.hasPlugin('com.android.application')) {
@realdadfish
realdadfish / MyDependencyResolver.kt
Last active February 5, 2021 21:55
Custom Dependency Resolver for Robolectric 4.2+
import com.google.auto.service.AutoService
import org.robolectric.internal.dependency.DependencyResolver
import org.robolectric.pluginapi.SdkProvider
import org.apache.maven.artifact.ant.DependenciesTask
import org.robolectric.internal.dependency.DependencyJar
import java.io.IOException
import java.nio.channels.FileLock
import java.nio.channels.FileChannel
import java.io.RandomAccessFile
import java.io.File
@realdadfish
realdadfish / Log.txt
Created March 5, 2019 09:18
AndroidX Orchestrator Failure
CoverageListener E Failed to generate Emma/JaCoCo coverage.
E java.lang.reflect.InvocationTargetException
E at java.lang.reflect.Method.invoke(Native Method)
E at androidx.test.internal.runner.listener.CoverageListener.generateCoverageReport(CoverageListener.java:101)
E at androidx.test.internal.runner.listener.CoverageListener.instrumentationRunFinished(CoverageListener.java:70)
E at androidx.test.internal.runner.TestExecutor.reportRunEnded(TestExecutor.java:92)
E at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:65)
E at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:388)
E at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2145)
E Caused by: java.io.FileNotFoundExcept
@realdadfish
realdadfish / MyTest.kt
Created March 2, 2019 13:46
Kotlin Compiler Bug
...
@Before // <-- line 50
fun setup() {
MockitoAnnotations.initMocks(this)
...
}
...
@realdadfish
realdadfish / BaseMagnetActivity.kt
Last active April 4, 2019 20:36
Magnet Scoping / ViewModel injection
open class BaseMagnetActivity : AppCompatActivity(), ScopeOwner {
private val scopeModel: ScopeModel by lazy { ScopeModel.setup(this) }
private var testScope: Scope? = null
override var scope: Scope
get() = testScope ?: scopeModel.scope
@VisibleForTesting
set(value) {
testScope = value