Skip to content

Instantly share code, notes, and snippets.

View jeremyrempel's full-sized avatar

Jeremy Rempel jeremyrempel

View GitHub Profile
@HiltAndroidApp
class MyApplication : Application() {
@Inject
lateinit var appInit: ApplicationInitializer
override fun onCreate() {
super.onCreate()
appInit.initTracking()
@HiltAndroidApp
class MyApplication : Application
package com.github.jeremyrempel.applint
import com.android.tools.lint.client.api.IssueRegistry
import com.android.tools.lint.detector.api.CURRENT_API
/*
* The list of issues that will be checked when running <code>lint</code>.
*/
@Suppress("UnstableApiUsage")
class MyIssueRegistry : IssueRegistry() {
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'com.android.lint'
lintOptions {
htmlReport true
htmlOutput file("lint-report.html")
textReport true
absolutePaths false
ignoreTestSources true
class AndroidWtfLogUsageDetectorTest : LintDetectorTest() {
@Test
fun `test given kotlin log wtf usage one failure reported`() {
lint()
.sdkHome(File("/path/to/Android/Sdk"))
.files(
java(
"""
import android.util.Log;
class DeprecatedClassUsageDetector : Detector(), SourceCodeScanner {
companion object {
/** Issue describing the problem and pointing to the detector implementation */
@JvmField
val ISSUE: Issue = Issue.create(
// ID: used in @SuppressLint warnings etc
id = "DeprecatedLib",
// Title -- shown in the IDE's preference dialog, as category headers in the
// Analysis results window, etc
/**
* Look for usages of android.util.Log.wtf and replace with f
*
*/
class AndroidWtfLogUsageDetector : Detector(), SourceCodeScanner {
companion object {
/** Issue describing the problem and pointing to the detector implementation */
@JvmField
val ISSUE: Issue = Issue.create(
// ID: used in @SuppressLint warnings etc
Available issues:
Correctness
===========
AdapterViewChildren
-------------------
Summary: AdapterViews cannot have children in XML
Priority: 10 / 10

Memory Leaks

Setup Leak Canary

Context Leaks via Threads

  • When not static will retain reference to outer class beyond lifecycle of container (Activity, Fragment). In below example MyTask will retain a reference to Activity
# Memory Leaks
## Setup Leak Canary
- https://github.com/square/leakcanary
- Add to gradle. initialize on app startup, ensure debug is off
## Context Leaks via Threads
- When not static will retain reference to outer class beyond lifecycle of container (Activity, Fragment). In below example MyTask will retain a reference to Activity