AndroidJUnitRunner cannot find extra class com.squareup.leakcanary.FailTestOnLeakRunListener - memory-leaks

I am trying to run leak canary along with my Android Instrumentation tests. I followed the LeakCanary documentation https://square.github.io/leakcanary/upgrading-to-leakcanary-2.0/#running-leakcanary-in-instrumentation-tests
However, the instrumentation test app fails to start with the following error:
java.lang.RuntimeException: Exception thrown in onCreate() of ComponentInfo{<app component>/androidx.test.runner.AndroidJUnitRunner}: java.lang.IllegalArgumentException: Could not find extra class com.squareup.leakcanary.FailTestOnLeakRunListener
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6709)
at android.app.ActivityThread.access$1300(ActivityThread.java:237)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I have the following in my build.gradle:
dependencies {
compileOnly 'org.projectlombok:lombok:1.18.12'
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.annotation:annotation:1.0.0'
implementation 'androidx.core:core:1.0.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.github.bumptech.glide:glide:4.6.1'
testImplementation 'junit:junit:4.12'
testImplementation 'org.robolectric:robolectric:4.2'
testImplementation 'org.robolectric:shadows-httpclient:4.2'
testImplementation 'androidx.test:core:1.1.0'
testImplementation 'org.mockito:mockito-core:2.25.0'
androidTestImplementation 'org.mockito:mockito-core:2.25.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.annotation:annotation:1.0.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test:rules:1.1.1'
androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.25.0'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.25.0'
testImplementation 'com.squareup.leakcanary:leakcanary-android:2.9.1'
androidTestImplementation 'com.squareup.leakcanary:leakcanary-android-instrumentation:2.9.1'
androidTestUtil 'androidx.test:orchestrator:1.1.1'
api "com.google.auto.value:auto-value-annotations:1.7"
api 'com.google.guava:guava:27.0.1-jre'
annotationProcessor "com.google.auto.value:auto-value:1.7"
annotationProcessor 'org.projectlombok:lombok:1.18.12'
}
android {
compileSdkVersion 31
ndkVersion "23.0.7599858"
buildToolsVersion "30.0.2"
defaultConfig {
minSdkVersion 22
targetSdkVersion 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments clearPackageData: 'true'
testInstrumentationRunnerArgument "listener", "com.squareup.leakcanary.FailTestOnLeakRunListener"
renderscriptTargetApi 22
}
}
Any help or pointers is greatly appreciated.

Related

Failed to resolve: com.google.android.gms:play-services-clearcut:12.0.1

when I implement google places dependency and sync the Gradle file then it shows an error
Failed to resolve: com.google.android.gms:play-services-clearcut:12.0.1
App-level build. Gradle file
apply plugin : 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.hatimtekri.googlemap"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
//noinspection UseOfBundledGooglePlayServices
implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.google.android.libraries.places:places:2.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
dependency
implementation 'com.google.android.libraries.places:places:2.0.0'
please please solve this error

Duplicate Class android.support

I'm new to android studio and programming. I am unable to build my project as there are currently certain overlapping classes, although I am not able to identify which are. Attached below is my the code in my Gradle app. When attempting to build, a string of error messages appear, and mention duplicate classes. Please help!!!
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.finalwallpaperapp"
minSdkVersion 16
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE-FIREBASE.txt'
exclude 'META-INF/NOTICE'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.google.firebase:firebase-core:10.0.1'
implementation 'com.google.firebase:firebase-database:10.0.1'
implementation 'com.google.android.gms:play-services-tasks:10.0.0'
implementation 'com.google.firebase:firebase-storage:10.0.1'
implementation 'com.google.firebase:firebase-auth:10.0.1'
implementation group: 'com.firebase', name: 'firebase-client-jvm', version: '2.5.2'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:recyclerview-v7:28.0.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
implementation 'co.gofynd.library:gravity-view:1.0'
}
You probably need to migrate to AndroidX:
To do that
Go to Refactor
Go to Migrate to AndroidX
Then Migrate
This should work

how to clear the error on the following code?

i got the warning msg while sync my app to firebase.
the warning msg is =>"Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'. " i don't know how to correct it .someone help me how to clear this error
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.selvakumar.firebase"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'//i got error in this line
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
compile 'com.google.firebase:firebase-core:16.0.0'
}
apply plugin: 'com.google.gms.google-services'
compile is deprecated from android studio 3.1 use implementation before all of libraries
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-vector-drawable:27.1.1'
implementation 'com.android.support:appcompat-v7:28.0.0-beta01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:28.0.0-beta01'
implementation 'com.android.support:recyclerview-v7:28.0.0-beta01'
implementation 'com.android.support:cardview-v7:28.0.0-beta01'
implementation 'com.android.support:support-v4:28.0.0-beta01'
implementation 'com.makeramen:roundedimageview:2.3.0'
implementation 'com.jakewharton:butterknife:8.8.1'
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
implementation 'com.blankj:utilcode:1.12.5'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
implementation 'com.firebase:firebase-jobdispatcher:0.8.5'
implementation 'com.google.firebase:firebase-crash:11.4.2'
implementation 'com.google.firebase:firebase-core:11.4.2'
implementation 'com.google.firebase:firebase-messaging:11.4.2'
implementation 'com.google.firebase:firebase-perf:11.4.2'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'com.google.dagger:dagger:2.13'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'io.reactivex.rxjava2:rxjava:2.1.7'
implementation 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
implementation 'com.github.pchmn:MaterialChipsInput:1.0.8'
implementation 'com.nineoldandroids:library:2.4.0'
implementation 'com.daimajia.slider:library:1.1.5#aar'
implementation 'com.daimajia.easing:library:2.0#aar'
implementation 'com.daimajia.androidanimations:library:2.3#aar'
implementation 'com.github.jkwiecien:EasyImage:2.0.4'
implementation 'com.droidninja:filepicker:2.1.5'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.airbnb.android:lottie:2.2.5'
implementation 'com.aurelhubert:ahbottomnavigation:2.1.0'
implementation 'com.github.mrengineer13:snackbar:1.2.0'
implementation 'agency.tango.android:material-intro-screen:0.0.5'
implementation 'org.greenrobot:eventbus:3.1.1'
implementation('com.crashlytics.sdk.android:crashlytics:2.9.3#aar') { transitive = true }
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
implementation 'com.github.sharish:ShimmerRecyclerView:v1.2'
implementation 'com.github.samanzamani.persiandate:PersianDate:0.3'
implementation 'com.stephentuso:welcome:1.4.1'
implementation 'com.yanzhenjie:permission:2.0.0-rc6'
implementation 'com.github.skydoves:powermenu:2.0.4'
implementation 'com.android.support:multidex:1.0.3'
implementation 'lib.kingja.switchbutton:switchbutton:1.1.7'
implementation 'com.github.pinball83:masked-edittext:1.0.4'

Where is com.android.support:animated-vector-drawable located? (Android Studio)

In build.gradle (Module:app) my implementation 'com.android.support:appcompat-v7:27.1.1' is underlined with red saying version mismatch with com.android.support:animated-vector-drawable (which apparently is v24). I cannot find anything named vector-drawable anywhere in the project though. The app won't start as long as the red marking remains, stating that it is unable to merge dex.
App grade looks like this:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.healthandchocolate.sjostedtafzelius.healthchocolateandroid"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
//FIREBASE
implementation 'com.google.firebase:firebase-database:10.0.1'
implementation 'com.google.firebase:firebase-core:10.0.1'
//GLIDE for images
/*
compile 'com.github.bumptech.glide:glide:4.2.0'
kapt 'com.github.bumptech.glide:compiler:4.2.0'
compile 'com.android.support:support-compat:27'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
*/
compile 'com.master.android:glideimageview:1.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//FORCES 27. RESOLVES VERSION CONFLICT
configurations.all {
resolutionStrategy {
force 'com.android.support:support-annotations:26.+'
}
}
}
apply plugin: 'com.google.gms.google-services'
apply plugin: 'kotlin-kapt'
It's probably because of dependencies, (most probably your com.master.android:glideimageview:1.0, or maybe other).
So, just add another implementation that refer to animated-vector-drawable:
implementation 'com.android.support:animated-vector-drawable:27.1.1'
Make sure to include google() repository in your top-level build.gradle

Duplicate zip entry [classes.jar:android/support/test/filters/RequiresDevice.class]))

This issue is ligtly connected with the others that i started here:
Instrumentation run failed due to 'java.lang.NoClassDefFoundError' after adding multidex to my application
Unable to merge dex - how to exclude proper jar?
I added multidex support, then also added suport for tests.
I also added exlude to my packagingOptions, but it is not working as i thought.
Here is my build.gradle now:
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
packagingOptions {
exclude 'protobuf.meta'
exclude 'android/support/test/filters/RequiresDevice.class'
}
testOptions {
unitTests {
includeAndroidResources = true
}
}
sourceSets {
test.java.srcDirs += ['build/generated/source/apt/test/debug']
}
defaultConfig {
multiDexEnabled true
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
// testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext.daggerVersion = '2.11'
ext.roomVersion = '1.0.0-rc1'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation ('com.android.support.test.espresso:espresso-core:2.0') {
exclude group: 'javax.inject'
}
testImplementation "org.robolectric:robolectric:3.4.2"
kaptTest "com.google.dagger:dagger-compiler:$daggerVersion"
kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion"
// RxJava
implementation 'io.reactivex.rxjava2:rxjava:2.1.0'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
// Room
implementation "android.arch.persistence.room:runtime:$roomVersion"
implementation "android.arch.persistence.room:rxjava2:$roomVersion"
kapt "android.arch.persistence.room:compiler:$roomVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.1.51"
androidTestImplementation "android.arch.persistence.room:testing:$roomVersion"
// Dagger
implementation "com.google.dagger:dagger:$daggerVersion"
implementation "com.google.dagger:dagger-android:$daggerVersion"
implementation "com.google.dagger:dagger-android-support:$daggerVersion"
kapt "com.google.dagger:dagger-compiler:$daggerVersion"
kapt "com.google.dagger:dagger-android-processor:$daggerVersion"
implementation 'pl.charmas.android:android-reactive-location2:2.0#aar'
implementation 'com.google.android.gms:play-services-location:11.4.2'
implementation 'com.google.android.gms:play-services-places:11.4.2'
//Jackson
implementation 'com.fasterxml.jackson.core:jackson-core:2.9.1'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.0'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.1'
implementation 'com.android.support:multidex:1.0.2'
}
Here is the error:
FAILURE: Build failed with an exception.
Execution failed for task ':location:transformClassesWithMultidexlistForDebugAndroidTest'.
java.io.IOException: Can't write [C:\TempAndroidProj\location\build\intermediates\multi-dex\androidTest\debug\componentClasses.jar] (Can't read [C:\Users\k.s.gradle\caches\transforms-1\files-1.1\testing-support-lib-0.1.aar\59aec2a639c884ff422cd31cc6e68cad\jars\classes.jar(;;;;;;**.class)] (Duplicate zip entry [classes.jar:android/support/test/filters/RequiresDevice.class]))
So how can i exclude properly the duplicate zip entry?

Resources