Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Prokash Sarkar prokash-sarkar

🎯
Focusing
View GitHub Profile
View Multi-Module, Multi-Flavored Test Coverage with JaCoCo in Android
/**
* How to run?
*
* App Module:
* ./gradlew app:testAppDebugUnitTestCoverage
* ./gradlew app:testBetaDebugUnitTestCoverage
* ./gradlew app:testProdDebugUnitTestCoverage
*
* Domain Module:
* ./gradlew domain:jacocoTestReport
View script-jacoco.gradle
private static boolean isAndroidModule(Project project) {
boolean isAndroidLibrary = project.plugins.hasPlugin('com.android.library')
boolean isAndroidApp = project.plugins.hasPlugin('com.android.application')
return isAndroidLibrary || isAndroidApp
}
View script-jacoco.gradle
afterEvaluate { project ->
def projectName = project.name
if (isAndroidModule(project)) setupAndroidReporting()
else setupKotlinReporting()
}
View script-jacoco.gradle
def setupKotlinReporting() {
jacocoTestReport {
dependsOn test
reports {
csv.enabled false // change if needed
xml.enabled false // change if needed
html {
enabled true
destination file("${buildDir}/coverage-report")
}
View script-jacoco.gradle
private static boolean isAndroidModule(Project project) {
boolean isAndroidLibrary = project.plugins.hasPlugin('com.android.library')
boolean isAndroidApp = project.plugins.hasPlugin('com.android.application')
return isAndroidLibrary || isAndroidApp
}
afterEvaluate { project ->
def projectName = project.name
if (isAndroidModule(project)) setupAndroidReporting()
else setupKotlinReporting()
View build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'jacoco'
apply from: "$project.rootDir/tools/script-jacoco.gradle"
android {
// Code omitted for brevity
View build.gradle
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'kotlin-kapt'
apply plugin: 'jacoco'
apply from: "$project.rootDir/tools/script-jacoco.gradle"
dependencies {
// Code omitted for brevity
}
View build.gradle
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'jacoco'
apply from: "$project.rootDir/tools/script-jacoco.gradle"
android {
// Code omitted for brevity
View script-jacoco.gradle
def setupAndroidReporting() {
// 1
tasks.withType(Test) {
// Whether or not classes without source location should be instrumented
jacoco.includeNoLocationClasses true
}
// Grab all build types and product flavors
// 2
def buildTypes = android.buildTypes.collect { type ->
@prokash-sarkar
prokash-sarkar / ConfirmationDialogFragment.kt
Created Feb 6, 2021
A sample app to demonstrate the process of showing camera preview in web view
View ConfirmationDialogFragment.kt
package com.example.myapplication
import android.app.AlertDialog
import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import androidx.fragment.app.DialogFragment
/**