Robolectric - How to clean up message: "WARNING: unknown service autofill" - android

During my tests with Robolectric, I always get a warning message in console (no LogCat) with says: "WARNING: unknown service autofill".
Does Anyone know what to do to clean it up?
Thanks in advance.

You can set the sdk version to 25. Thereby the tests will run against api level 25. The warnings should be removed/implemented in future robolectric versions.
To set the sdk version see: http://robolectric.org/configuring/

The following configurations worked for me,
#Config(sdk = 21)
public class MyClassTests {
/* testCodeHere */
}
Other sdk Config that worked fine =
#Config(sdk = 22)
#Config(sdk = 23)
#Config(sdk = 24)
#Config(sdk = 25)
This error happens when running tests against sdk = 26.
Therefore, as #Moritz suggested,
change the sdkVersion in your tests or create a robolectric.properties file, Configuring Robolectric.

I upgraded from SDK 24 to 26 and began seeing this error. Going back to SDK 25 didn't seem like a good solution so I tried upgrading Robolectric to its latest stable version.
At time of writing this is version 3.8.
https://mvnrepository.com/artifact/org.robolectric/robolectric/3.8
This fixed the problem for me.
From the sounds of it, they fixed this in 3.7
https://github.com/robolectric/robolectric/releases/

Related

Robolectric - Package targetSdkVersion=30 > maxSdkVersion=29

Error:
java.lang.IllegalArgumentException: failed to configure :
Package targetSdkVersion=30 > maxSdkVersion=29
at
org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:247)
at
org.junit.runners.ParentRunner.getFilteredChildren(ParentRunner.java:534)
at
org.junit.runners.ParentRunner.getDescription(ParentRunner.java:400)
at
androidx.test.ext.junit.runners.AndroidJUnit4.getDescription(AndroidJUnit4.java:149)
at
org.junit.runners.model.RunnerBuilder.configureRunner(RunnerBuilder.java:81)
at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:72)
at
org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:37)
at
org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:70)
at
org.junit.internal.requests.ClassRequest.createRunner(ClassRequest.java:28)
at
org.junit.internal.requests.MemoizingRequest.getRunner(MemoizingRequest.java:19)
at
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:50)
at
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: java.lang.IllegalArgumentException: Package
targetSdkVersion=30 > maxSdkVersion=29 at
org.robolectric.plugins.DefaultSdkPicker.configuredSdks(DefaultSdkPicker.java:118)
at
org.robolectric.plugins.DefaultSdkPicker.selectSdks(DefaultSdkPicker.java:69)
at
org.robolectric.RobolectricTestRunner.getChildren(RobolectricTestRunner.java:213)
... 13 more
How to fix this issue?
Found this post with the same issue, with a different error message.
This answer helped me to solve the issue.
Posting the same here.
Create a robolectric.properties file inside the app/src/test/resources directory with the following line:
sdk=29
This will force Robolectric to use API 29 instead of 30.
Note: Robolectric supports up to SDK 29 now (As on Sep 4th, 2020).
There are two ways to achieve this:
Creating prop file (mentioned in Abhimanyu's answer)
Create robolectric.properties in app/src/test/resources
Add sdk=29 in it
Limit your test target SDK using Config annotation. This makes you consider different configs for different tests or avoid creating extra config files.
#Config(sdk = [29])
class Test {
// ...
}
Both the above answers work fine, but the latest version of robolectric supports android sdk 30.
So just upgrade the robolectric dependency to fix the issue.
At the time of writing, the latest version was 4.5.1.
For the up to date version please refer the official github site.
Just update your robolectric version to 4.5 or newer, their repo notified this change:
Robolectric 4.5 adds support for Android API 30 (R final) and contains
many bug fixes and other enhancements.
Source: https://github.com/robolectric/robolectric/releases
failed to configure com.example.android.architecture.blueprints.todoapp.tasks.TasksViewModelTest.addNewTask_setsNewTaskEvent: Package targetSdkVersion=31 > maxSdkVersion=30
java.lang.IllegalArgumentException: failed to configure com.example.android.architecture.blueprints.todoapp.tasks.TasksViewModelTest.addNewTask_setsNewTaskEvent: Package targetSdkVersion=31 > maxSdkVersion=30
Had an almost similar error as above. The error was generated when I was using AndroidX Test and Robolectic APIs to execute my local unit tests. I also had included the below code to allow The testing API use the right Android manifest file during testing:
testOptions.unitTests {
includeAndroidResources = true
}
I solved the above error by downgrading my compile and target sdk from 31 to 30

Android Studio minSdkVersion check for Java 1.8 (API level 24) specific features

My project uses Array#sort that requires API level 24 (Android 7.0)
_tmp.sort((left, right) -> { ... };
But I have also minSdkVersion 21 (Android 5.0)
When I run that code on Android 6.0 Emulator, the following exception is thrown:
... Caused by: java.lang.NoSuchMethodError: No interface method sort(Ljava/util/Comparator;)V in class Ljava/util/List; or its super classes (declaration of 'java.util.List' appears in /system/framework/core-libart.jar)
I have found that other users asked about this exception: java.lang.NoSuchMethodError: No interface method sort(Ljava/util/Comparator;) exception in sorting arraylist android
Any good way to Android Studio warns that .sort is not workable on OSes earlier than Android 7.0? like APIs having #RequiresApi?
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { ... }
Android studios on my computers warns my about this out of the box, not to sure why yours doesn't. Maybe you made changes to your lint warning configuration? If not, you should still be able to enable that there.
Sort method is annotated as #since 1.8
You can change Android Studio errors and warnings levels in Settings->Editor->Inspections
Try change Java->Java language level migration aids->usages of API which isn't available at her configure (description of it: "This inspection finds all usages of methods that have #since tag in their documentation.")

Android Lint - NewApi check still fails despite suppression with #TargetApi

Following an unsuccessful Lint run, I attempted to fix an error by adding the #TargetApi(Build.VERSION_CODES.HONEYCOMB) attribute, but the next time Lint is run, the following error still shows for the getScaleX() function:
Can anyone shed some light on this?
The call to getScaleX() requires API level 11 (Honeycomb), as mentioned in the message window. The message also indicates that the minimum API level is 9 (as per the minSdkVersion setting).
The Lint tool is warning you that you are using a method supported only in newer SDK versions (11+), but have set to allow the application to run on devices that don't support this method (SDK versions 9 and 10).
See a more detailed description of what the NewApi Lint check does here: (search for NewApi) http://tools.android.com/tips/lint-checks
Suppress such warnings with caution, I'd suggest protecting the code with something like this:
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
...getScaleX()...
}

android lint still give "Call requires API ..." error after I put check there

I have the following code:
if(android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1){
enter_pos.callOnClick();
}
But I still get error from Lint:
Call requires API level 15 (current min is 12): android.widget.Button#callOnClick
Why Lint is still giving error even after I put a check for the API version? I am using
Android Developer Tools
Build: v22.0.5-757759
Under Windows 8. Thanks in advance for any suggestions!
You should put #SuppressLint("NewApi") above the method you are using this. Lint cannot decide if you do your check right by looking at your code
In your eclipse Window -> preferences -> Android -> Lint error checking uncheck the two check boxes and apply changes and then clean the project.

Robolectric compilation error while using shadowOf method

I am using Robolectric 1.2 in an Andorid 2.3.3 project (API 10)
It throws the below compilation error, when using shadowOf method
ShadowView shadowView = Robolectric.shadowOf(view);
error: cannot access ObjectAnimator
But the error is gone, if I change the android sdk to API 11 and above
I'm still having this issue with 2.2. I got around this by
import static org.robolectric.Robolectric.shadowOf_;
...
ShadowView shadowView = Robolectric.shadowOf_(view);
If anyone could provide some insight why this works, that would be awesome!
After some analysis, found that it is a bug in robolectric.
For now, using 2.0-alpha-1 seems to fix the issue.
Here is the github issue created for the issue
https://github.com/pivotal/robolectric/issues/431

Categories

Resources