pedrovgs / Shot

Screenshot testing library for Android
Apache License 2.0
1.19k stars 116 forks source link

Shot cannot be used in tests due .jar is not generated #189

Closed svasquezm closed 3 years ago

svasquezm commented 3 years ago

Expected behaviour

Shot can be used in tests

Actual behaviour

Shot external library file .jar is not generated and Shot cannot be used in tests (unrecognized com.karumi.* package).

Steps to reproduce

Simplified app gradle module

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.karumi:shot:5.5.1'
    }
}

repositories {
    google()
    maven { url 'http://maven.apptimize.com/artifactory/repo' }
    maven { url "https://dl.bintray.com/onfido/maven" }
    maven { url "https://appboy.github.io/appboy-android-sdk/sdk" } 
    mavenCentral()
}

if (getGradle().getStartParameter().getTaskRequests().toString().contains("Prod")) {
    apply plugin: 'newrelic'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlin-android-extensions'
apply from: '../jacoco.gradle'
apply plugin: 'realm-android'
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
apply plugin: 'shot'

project.ext {
    defaultApplicationId = "<MY_APP_ID>"
}

android {

    dataBinding {
        enabled = true
    }

    def keyStorePropertiesFile = file('../keystore.properties')
    def keystoreProperties = new Properties()
    keystoreProperties.load(new FileInputStream(keyStorePropertiesFile))

    signingConfigs {
        ReleaseSigning {
            //...
        }
        DebugSigning {
            //...
        }
    }

    compileSdkVersion versions.compileSdk
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId defaultApplicationId
        minSdkVersion versions.minSdk
        versionCode 239
        targetSdkVersion versions.targetSdk
        versionName "3"  /*Mayor */
        useLibrary 'org.apache.http.legacy'
        testInstrumentationRunner "com.karumi.shot.ShotTestRunner"
        manifestPlaceholders = [HOCKEYAPP_APP_ID: "<XXX>", applicationIdWithSuffix: "${applicationId}"]
        vectorDrawables.useSupportLibrary = true

        multiDexEnabled true
        multiDexKeepProguard file('multidex-config.pro')

        buildConfigField "String", "ACCOUNT_TYPE", "\"${applicationId}\""
        buildConfigField "String", "AUTHORITY", "\"${applicationId}.provider\""
        resValue "string", "account_type", "${applicationId}"
        resValue "string", "authority", "${applicationId}.provider"

        kapt {
            arguments {
                arg("room.schemaLocation", "$projectDir/schemas".toString())
            }
        }
    }
    buildTypes {
        //...

        /*Base*/
        debug {
            minifyEnabled false
            testCoverageEnabled true
            shrinkResources false
            signingConfig signingConfigs.DebugSigning
            buildConfigField INT, REALM_SCHEME, REALM_SCHEME_VERSION
            buildConfigField STRING, DEFAULT_COUNTRY, DEFAULT_COUNTRY_VALUE
        }
        release {
            shrinkResources true
            minifyEnabled true
            signingConfig signingConfigs.ReleaseSigning
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            buildConfigField INT, REALM_SCHEME, REALM_SCHEME_VERSION
            buildConfigField STRING, DEFAULT_COUNTRY, DEFAULT_COUNTRY_VALUE
        }
        Mock {
            initWith debug
            versionNameSuffix RELEASE_VERSION + INTERNAL_VERSION + "-" + "MOCK"
            buildConfigField STRING, ENVIRONMENT, MOCK
        }
        Dev {
            // ...
        }
        Automation {
            // ...
        }
        Staging {
            // ...
        }
        Prod {
            // ...
        }
    }
    android.variantFilter { variant ->
        if (variant.buildType.name == 'release' || variant.buildType.name == 'debug') {
            variant.setIgnore(true)
        }
    }
    //Fix for test assets
    applicationVariants.all { variant ->
        def productFlavor = variant.productFlavors[0] != null ? "${variant.productFlavors[0].name.capitalize()}" : ""
        def buildType = "${variant.buildType.name.capitalize()}"
        tasks["compile${productFlavor}${buildType}UnitTestSources"].dependsOn(tasks["merge${productFlavor}${buildType}Assets"])
    }
    lintOptions {
        abortOnError false
        textReport true
        textOutput 'linter-report.txt'
        warning 'InvalidPackage'
    }
    testOptions {
        unitTests.all {
            jacoco {
                includeNoLocationClasses = true
            }
        }
//        unitTests.includeAndroidResources = true
        unitTests.returnDefaultValues = true
    }
    subprojects {
        tasks.withType(Test) {
            maxParallelForks = Runtime.runtime.availableProcessors()
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    packagingOptions {
        pickFirst 'META-INF/*.kotlin_module'
        exclude 'META-INF/versions/9/module-info.class'
    }

    sourceSets {
        main {
            res.srcDirs =
                    [
                            // ...
                    ]
        }
    }
}

configurations {
    mockDebugCompile {}
    devDebugCompile {}
    stagingReleaseCompile {}
    prodReleaseCompile {}
}

dependencies {

    implementation fileTree(include: ['*.jar'], dir: 'libs')

    implementation "androidx.legacy:legacy-support-v4:$rootProject.androidx.legacy"
    implementation "androidx.appcompat:appcompat:$rootProject.androidx.appcompat"
    implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.androidx.lifecycle"
    implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.androidx.lifecycle"
    implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.androidx.lifecycle"
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"

    kapt "com.android.databinding:compiler:$rootProject.databindingCompiler"
    testImplementation "com.google.truth:truth:$rootProject.truthVersion"
    implementation "com.google.zxing:core:$rootProject.zxingVersion"
    implementation "android.arch.work:work-runtime:$rootProject.workRuntime"
    implementation group: 'com.google.android.material', name: 'material', version: "$rootProject.material"

    //Coroutines
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$rootProject.coroutinesVersion"
    implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$rootProject.coroutinesVersion"
    //implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$rootProject.coroutinesVersion"

    //Android X Views
    implementation "androidx.cardview:cardview:$rootProject.androidx.cardview"
    implementation "androidx.constraintlayout:constraintlayout:$rootProject.androidx.constraintlayout"
    implementation "androidx.multidex:multidex:$rootProject.androidx.multidex"
    implementation "androidx.recyclerview:recyclerview:$rootProject.androidx.recyclerview"
    implementation "androidx.viewpager2:viewpager2:$rootProject.viewpager2"

    // FLexLayout - UI used in AccountStatement
    implementation "com.google.android:flexbox:$rootProject.flexboxLayoutVersion"

    // Custom Activity On Crash
    implementation "cat.ereza:customactivityoncrash:$rootProject.customActivityOnCrash"

    //EventBus
    implementation "org.greenrobot:eventbus:$rootProject.eventBusVersion"

    //Services
    //Branch.io
    implementation "io.branch.sdk.android:library:$rootProject.branchIO"
    //BouncyCastle - ECHD encryption
    implementation "com.madgag.spongycastle:prov:$rootProject.bouncyCastle"
    //Segment
    implementation "com.segment.analytics.android:analytics:$rootProject.segment"
    //Apptimize via Segment
    implementation "com.apptimize.segment:apptimize-segment-integration:$rootProject.apptimizeSegment"
    //Braze
    implementation "com.appboy:appboy-segment-integration:$rootProject.braze"
    //SiftScience
    implementation "com.siftscience:sift-android:$rootProject.siftScience"
    // Custom Google Sign In Button
    implementation "com.shobhitpuri.custombuttons:google-signin:$rootProject.googleSignInButton"
    //QR Code Generator
    implementation "com.github.SumiMakito:AwesomeQRCode:$rootProject.QRCodeGenerator"
    //Bluetooth
    implementation "org.altbeacon:android-beacon-library:$rootProject.bluetooth"
    //PubNub
    implementation "com.pubnub:pubnub-gson:$rootProject.pubNub"
    //Realm Adapters
    implementation "io.realm:android-adapters:$rootProject.realmAdapters"
    //AppCenter - Beta Test
    implementation "com.microsoft.appcenter:appcenter-analytics:$rootProject.appCenterSdkVersion"
    implementation "com.microsoft.appcenter:appcenter-crashes:$rootProject.appCenterSdkVersion"
    //Joda-Time - Date & Time
    implementation "net.danlew:android.joda:$rootProject.jodaTime"
    //Glide - Image Loader
    implementation "com.github.bumptech.glide:glide:$rootProject.glide"
    //Crashlytics
    implementation 'com.google.firebase:firebase-crashlytics:17.3.0'

    //New Relic
    implementation "com.newrelic.agent.android:android-agent:$rootProject.newrelicVersion"
    //Lottie
    implementation("com.airbnb.android:lottie:$rootProject.lottieVersion") {
        exclude group: 'com.android.support', module: 'appcompat-v7'
    }
    //OnFido
    implementation "com.onfido.sdk.capture:onfido-capture-sdk-core:$rootProject.onFido"

    // Firebase
    implementation 'com.google.android.play:core:1.3.6'
    implementation 'com.google.android.gms:play-services-auth:16.0.1'
    implementation 'com.google.android.gms:play-services-location:16.0.0'
    implementation 'com.google.android.gms:play-services-base:16.0.1'
    implementation 'com.google.android.gms:play-services-vision:19.0.0'
    implementation 'com.google.firebase:firebase-messaging:17.3.4'
    implementation 'com.google.firebase:firebase-core:18.0.0'
    implementation 'com.google.firebase:firebase-auth:20.0.0'
    implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
    implementation 'com.google.firebase:firebase-config:20.0.0'

    // Dagger II
    implementation "com.google.dagger:dagger:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-compiler:$rootProject.daggerVersion"
    implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
    kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"

    //New Relic
    implementation "com.newrelic.agent.android:android-agent:$newrelicVersion"

    // JSON Parsing
    implementation "com.google.code.gson:gson:$rootProject.gson"

    // Tests
    testImplementation "junit:junit:$rootProject.junit"
    testImplementation "androidx.arch.core:core-testing:$rootProject.androidx.coreTesting"
    testImplementation "androidx.test:core:$rootProject.androidx.testCore"
    testImplementation "androidx.test.ext:junit:$rootProject.androidx.extJunit"
    testImplementation "android.arch.core:core-testing:$rootProject.coreTesting"
    testImplementation "io.mockk:mockk:$rootProject.mockk"
    testImplementation "org.robolectric:robolectric:$rootProject.robolectric"
    testImplementation "org.powermock:powermock-module-junit4:$rootProject.powermockVersion"
    testImplementation "org.powermock:powermock-api-mockito2:$rootProject.powermockVersion"
    testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$rootProject.coroutinesTestVersion"
    testImplementation "androidx.arch.core:core-testing:$rootProject.androidx.coreTesting"
    androidTestImplementation "androidx.arch.core:core-testing:$rootProject.androidx.coreTesting"
    androidTestImplementation("androidx.test.espresso:espresso-core:$rootProject.espressoCore", {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    shotDependencies "com.karumi:shot-android:5.5.1"

    implementation project(':service')
    implementation project(':business')
    implementation project(':view')
    implementation project(':helpcenter')
    implementation project(':util')
    implementation project(':core')
}

shot {
    useComposer = false
    showOnlyFailingTestsInReports = true
}

Project gradle file

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.61'

    ext.versions = [
            'compileSdk': 28,
            'minSdk'    : 19,
            'targetSdk' : 28
    ]

    ext.androidx = [
            appcompat       : '1.0.2',
            cardview        : '1.0.0',
            coreTesting     : '2.1.0',
            constraintlayout: '2.0.0-alpha2',
            fragment        : '1.1.0-alpha09',
            legacy          : '1.0.0',
            lifecycle       : '2.2.0',
            multidex        : '2.0.0',
            recyclerview    : '1.0.0',
            room            : '2.2.0',
            testCore        : '1.1.0',
            extJunit        : '1.1.2'
    ]

    ext.firebase = [
            core                    : '1.3.6',
            playServicesAuth        : '16.0.1',
            playServicesLocation    : '16.0.0',
            playServicesBase        : '16.0.1',
            playServicesVision      : '19.0.0',
            firebaseMessaging       : '17.3.4',
            firebaseCore            : '16.0.6',
            firebaseAuth            : '16.1.0',
            firebaseJobdispatcher   : '0.8.5',
            firebaseConfig          : '16.0.0'
    ]

    ext {
        coroutinesVersion = '1.3.2'
        gradleVersion = '3.5.3'
        kotlinVersion = '1.3.61'
        truthVersion = '1.0.1'
        zxingVersion = '3.4.0'
        coroutinesTestVersion = '1.2.1'
        daggerVersion = '2.26'
        powermockVersion = '2.0.2'
        retrofitVersion = '2.6.4'
        appCenterSdkVersion = '1.10.0'
        eventBusVersion = '3.1.1'
        newrelicVersion = '5.25.2'
        androidMaterialVersion = '1.1.0'
        flexboxLayoutVersion = '1.0.0'
        lottieVersion = '3.3.0'
        branchIO = '4.0.0'
        bouncyCastle = '1.58.0.0'
        segment = '4.3.1'
        apptimizeSegment = '+'
        braze = '+'
        siftScience = '0.10.4'
        googleSignInButton = '1.0.0'
        QRCodeGenerator = '1.2.0'
        bluetooth = '2.15.1'
        pubNub = '4.21.0'
        realmAdapters = '3.1.0'
        jodaTime = '2.9.5.1'
        glide = '3.7.0'
        onFido = '4.5.1'
        espressoCore = '3.3.0'
        mockk = '1.9'
        junit = '4.12'
        robolectric = '4.3.1'
        coreTesting = '1.1.1'
        gson = '2.8.1'
        customActivityOnCrash = '2.2.0'
        crashlytics = '2.9.6'
        databindingCompiler = '3.1.2'
        workRuntime = '1.0.0'
        viewpager2 = '1.0.0'
        material = '1.1.0'
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://zendesk.jfrog.io/zendesk/repo' }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:$gradleVersion"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.2.0'
        classpath 'com.google.firebase:firebase-plugins:1.1.5'
        classpath 'io.realm:realm-gradle-plugin:6.1.0'
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.3.0'
        classpath 'com.karumi:shot:5.5.1'

        // Boosts build time in Dev/Stg/Aut
        if (getGradle().getStartParameter().getTaskRequests().toString().contains("Prod")) {
            classpath "com.newrelic.agent.android:agent-gradle-plugin:$newrelicVersion"
        }

        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {
            url 'https://zendesk.jfrog.io/zendesk/repo'
        }
        flatDir {
            dirs 'libs'
        }
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Version of the library

5.5.1

svasquezm commented 3 years ago

Removing android.variantFilter block works.