Getting Runtime error while using ShadowOf() API of Robolectric 4.1 - robolectric

I am trying to use ShadowOf() API of Robolectric to verify if items in listview are displayed or not with changed data values when adapter's notifyDatasetChanged is called in development code.
For this, I am trying to get ShadowListView and verify:
ListView lv = myFragment.getView().findViewById(R.id.myActualListView);
ShadowListView shadowListView = Shadows.shadowOf(lv); // <-- fails at runtime
shadowListView.populateItems();
assertTrue(shadowOf(adapter).wasNotifyDataSetChangedCalled());
assertTrue(lv.getChildCount() > 0);
//more lines of code to access list item
However I keep getting errors for unrelated classes while running the test class.
Earlier, was getting error for:
error: cannot access EuiccManager class file for
android.telephony.euicc.EuiccManager not found
After including below line in build.gradle file:
testImplementation 'org.robolectric:robolectric:3.6.1'
Getting error for SliceManager, which I have not used anywhere in my code -
error: cannot access SliceManager class file for
android.app.slice.SliceManager not found
My gradle file below:
//Robolectric
testImplementation 'org.robolectric:robolectric:4.1'
// testImplementation ('org.robolectric:shadows-supportv4:4.1')
testImplementation 'org.robolectric:robolectric:3.6.1'
testImplementation 'androidx.test:core:1.1.0'
testImplementation 'org.mockito:mockito-core:2.8.9'
androidTestImplementation 'org.mockito:mockito-android:2.8.9'
testImplementation 'com.google.truth:truth:0.42'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-contrib:3.0.2'
androidTestImplementation 'junit:junit:4.12'
testImplementation 'com.google.code.findbugs:jsr305:1.3.9'
testImplementation 'org.powermock:powermock-api-mockito2:1.7.1'
testImplementation 'org.powermock:powermock-module-junit4:1.7.1'
Due to this error for missing class, I am not able to use Shadows.shadowOf() API.
Is there any way I can unit test if listview displays modified values of data on screen with respect to notifydatasetchange() called in development code?

Add 4.2 version of Robolectric.
All issues are solved in 4.2 version.
*testImplementation 'org.robolectric:robolectric:4.2'*
Note: Android SDK version 28

Upgrade you compileSdkVersion to API 28.
It happens because new versions of robolectric make use of android.net.wifi.rtt.WifiRttManager in the shadowOf function, and this was introduced in API 28, so you must upgrade it.

Related

ERROR: Failed to resolve: com.google.android.material:material-rc01: Affected Modules: app

After adding 'com.google.android.material:material-rc01' in place of com.android.support:design as per documentation, studio failed to detect the dependency.
Then I downgrade the version of dependency to
implementation 'com.google.android.material:material:1.1.0-alpha09'
and it works.
But why this problem arises? any explanation?
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-
jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'com.google.android.material:material-rc01'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso core:3.2.0'
}
ERROR: Failed to resolve: com.google.android.material:material-rc01:
Affected Modules: app
The error arises due to the fact that you're not specifying a version for the implementation; the program needs the following:
The group
The name of the dependency to implement
Version of the dependency
All this is covered in more detail here
When I got this error message, I solved it with the below line:
implementation 'com.google.android.material:material:1.0.0-rc01'
As you can see, the line above follows the implement 'compileGroup:name:version' pattern from the list, which in this case is 1.0.0-rc01; -rc01 seems to be a name for the version, just like -alpha09.
Note as well that you are not downgrading as you say if you didn't specify a version previously, which is why your app couldn't build.
I just had the same issue. I solved it by using the following dependency:
implementation "com.google.android.material:material:1.0.0"
To solve such issues you always can check if the lib you are looking for does really exists in Google's Maven repo: https://dl.google.com/dl/android/maven2/index.html
Hope that help, cheers!

E/FirebaseInstanceId: Token retrieval failed: AUTHENTICATION_FAILED Firebase

I've tried many solutions but none of them seem to work. I'm trying to setup firebase with my android project but I keep getting an error which states E/FirebaseInstanceId: Token retrieval failed: AUTHENTICATION_FAILED. Note: Google-services.json is installed into my app directory.
App:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'com.android.support:appcompat-v7:28.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'
implementation 'com.google.firebase:firebase-core:16.0.1'
}
apply plugin: 'com.google.gms.google-services'
My App:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}

Firebase Failed to resolve: firebase-messaging-15.0.0 (Previous solutions disconnect Firebase Connection)

I have been trying to set up Firebase Cloud Messaging on an app. Everything runs ok until I add FCM dependencies to the app. I immediately get this error:
Failed to resolve: firebase-messaging-15.0.0
Open File
Here are the dependencies;
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-core:16.0.1'
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'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.google.firebase:firebase-messaging:17.0.0:15.0.0'
}
apply plugin: 'com.google.gms.google-services'
I have been reading answers like this all day and the only solution that works involves deleting everything from ": - 0" in the last line of the code.
The problem is that it immediately removes the connection to FCM. New to android programming, so forgive any obvious oversight. Thanks
This happens because the version of the dependencies conflict. You can remove one of the version and select the preferred one. In this case your
implementation 'com.google.firebase:firebase-messaging:17.0.0:15.0.0'
seems to have double version. You should choose whether to use 17.0.0 or 15.0.0 one.
The detail can be found in this video
https://youtu.be/NN_Ch5qzFWQ
cheers !

Migration to androidx.databinding on AndroidStudio 3.0

I'd like to ask if it's possible to migrate to androidx.databinding in AndroidStudio 3.0.
I don't want to upgrade to AndroidStudio 3.2 just yet, and it seems that I can only import android.databinding instead of the androidx version.
I have added this in my app gradle file:
kapt "androidx.databinding:databinding-compiler:3.2.0-alpha16"
Project gradle dependency:
classpath 'com.android.tools.build:gradle:3.1.0'
All the other androidx libraries I added on gradle can be imported in code, but not databinding. Has anyone here still using AndroidStudio 3.0 successfully used androidx.databinding?
Thanks.
UPDATE:
In the app build.gradle, I updated the dependency from -jre8 to -jdk8:
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
This is the app build.gradle dependencies:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:$rootProject.supportLibVersion"
implementation "com.google.android.material:material:$rootProject.supportLibVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.github.bumptech.glide:glide:4.8.0'
kapt 'com.github.bumptech.glide:compiler:4.8.0'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
// architecture components
implementation "androidx.lifecycle:lifecycle-extensions:$rootProject.archLifecycleVersion"
implementation "androidx.lifecycle:lifecycle-runtime:$rootProject.archLifecycleVersion"
implementation "androidx.room:room-runtime:$rootProject.roomVersion"
implementation "androidx.paging:paging-runtime:$rootProject.pagingVersion"
kapt "androidx.lifecycle:lifecycle-compiler:$rootProject.archLifecycleVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
kapt "androidx.databinding:databinding-compiler:3.2.1"
testImplementation 'junit:junit:4.12'
}
configurations {
all {
exclude group: 'com.android.support'
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
}
And this is the project build.gradle versions:
ext {
archLifecycleVersion = '2.0.0'
roomVersion = '2.1.0-alpha02'
pagingVersion = '2.1.0-beta01'
supportLibVersion = '1.0.0'
}
I executed this to find out more about the issue on my project:
./gradlew :app:kaptDebugKotlin
and I got this error:
e: error: cannot access NonNull
class file for android.support.annotation.NonNull not found
Consult the following stack trace for details.
com.sun.tools.javac.code.Symbol$CompletionFailure: class file for android.support.annotation.NonNull not found
e: [kapt] An exception occurred: java.lang.UnsatisfiedLinkError: org.sqlite.core.NativeDB._open_utf8([BI)V
at org.sqlite.core.NativeDB._open_utf8(Native Method)
at org.sqlite.core.NativeDB._open(NativeDB.java:71)
at org.sqlite.core.DB.open(DB.java:174)
at org.sqlite.core.CoreConnection.open(CoreConnection.java:220)
at org.sqlite.core.CoreConnection.<init>(CoreConnection.java:76)
at org.sqlite.jdbc3.JDBC3Connection.<init>(JDBC3Connection.java:25)
at org.sqlite.jdbc4.JDBC4Connection.<init>(JDBC4Connection.java:24)
at org.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:45)
at org.sqlite.JDBC.createConnection(JDBC.java:114)
at androidx.room.verifier.DatabaseVerifier$Companion.create(DatabaseVerifier.kt:81)
So it seems that the underlying sqlite library is still using android.support.annotation.NonNull. Any idea on how to solve this?
Thanks.

Failed to resolve: com.google.firebase:firebase-firestore:11.0.4

I looked at some articles on Stack Overflow regarding the problem but they haven't worked. The problem is that my build failes to resolve:
com.google.firebase:firebase-firestore:11.0.4
I'm using android studio to make my app and I'm trying to implement the Firebase Firestore into it.
Here is the code in my build.gradle for my Module:App file:
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:support-media-compat:27.1.1'
implementation 'com.android.support:customtabs:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.google.firebase:firebase-core:11.0.4'
implementation 'com.google.firebase:firebase-auth:11.0.4'
implementation 'com.google.firebase:firebase-storage:11.0.4'
implementation 'com.google.firebase:firebase-firestore:11.0.4'
implementation 'de.hdodenhof:circleimageview:2.2.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'
compile 'com.android.support:design:27.1.1'
compile 'com.android.support:support-annotations:27.1.1'
compile 'com.theartofdev.edmodo:android-image-cropper:2.7.+'
}
I have no idea what's going on. Help would be very much appreciated!
The initial release of Firestore was 11.4.2 in October 2017. See the Release Notes.

Resources