Robolectric - Package targetSdkVersion=30 > maxSdkVersion=29 - android

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

Related

Android Webview Chromium UnitTests fail with java.lang.NoSuchMethodError

We are currently facing this NoSuchMethod Error when we want to create the unit test with Robolectric version 4.3.1 and Mockito version 2.18.3
Exceptions:
java.lang.NoSuchMethodError: 'void com.android.webview.chromium.WebViewChromium.<init>(com.android.webview.chromium.WebViewChromiumFactoryProvider, android.webkit.WebView, android.webkit.WebView$PrivateAccess, boolean)'
Here is the code we did:
mWebView = Mockito.spy(
new WebviewChromium(
mockWebViewChromiumProvider, webView, webView.new PrivateAccess(), false));
In BUILD.gn, we have included the "//android_webview/glue:glue_java" as dependency, we can successfully compile the code but it sounds like in the runtime, it refers to the another wrong jar, does someone know how to config the build file to use the correct jar or any ideas about how to solve this error?
did you check this followjng thread https://github.com/robolectric/robolectric/issues/5092 and this one I think you need open jdk 11 or 13 I recently had the same issue after adding open jdk 13 to android studio it solved my problem robolectric started working fine you can check following thread as well https://github.com/robolectric/robolectric/issues/5092

Error with tests in Android Studio when using ReLinker to load libraries

When I try to run my unit tests, ReLinker is complaining.
I've added Bugsnag, and it works as it should. Later I add ReLinker like here: https://docs.bugsnag.com/platforms/android/faq/
After adding those two lines I am no longer able to run my tests.
My application onCreate contains:
ReLinker.loadLibrary(this, "bugsnag-ndk")
ReLinker.loadLibrary(this, "bugsnag-plugin-android-anr")
Bugsnag.start(this, config)
Whenever I try to run my tests using RobolectricTestRunner, I get the following errors:
[Robolectric] WARN: Android SDK 29 requires Java 9 (have Java 8). Tests won't be run on SDK 29 unless explicitly requested.
[Robolectric] WARN: Android SDK 30 requires Java 9 (have Java 8). Tests won't be run on SDK 30 unless explicitly requested.
Could not find 'bugsnag-ndk.dll'. Looked for: [armeabi-v7a], but only found: [java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 10
lib\([^\\]*)\bugsnag-ndk.dll
^].
com.getkeepsafe.relinker.MissingLibraryException: Could not find 'bugsnag-ndk.dll'. Looked for: [armeabi-v7a], but only found: [java.util.regex.PatternSyntaxException: Unmatched closing ')' near index 10
lib\([^\\]*)\bugsnag-ndk.dll
^].
at com.getkeepsafe.relinker.ApkLibraryInstaller.installLibrary(ApkLibraryInstaller.java:173)
at com.getkeepsafe.relinker.ReLinkerInstance.loadLibraryInternal(ReLinkerInstance.java:180)
at com.getkeepsafe.relinker.ReLinkerInstance.loadLibrary(ReLinkerInstance.java:136)
at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:70)
at com.getkeepsafe.relinker.ReLinker.loadLibrary(ReLinker.java:51)
at com.roardam.vvitas.Vvitas.onCreate(Vvitas.kt:19)
at org.robolectric.android.internal.AndroidTestEnvironment.lambda$installAndCreateApplication$0(AndroidTestEnvironment.java:288)
at org.robolectric.util.PerfStatsCollector.measure(PerfStatsCollector.java:86)
at org.robolectric.android.internal.AndroidTestEnvironment.installAndCreateApplication(AndroidTestEnvironment.java:288)
at org.robolectric.android.internal.AndroidTestEnvironment.setUpApplicationState(AndroidTestEnvironment.java:171)
at org.robolectric.RobolectricTestRunner.beforeTest(RobolectricTestRunner.java:319)
at org.robolectric.internal.SandboxTestRunner$2.lambda$evaluate$0(SandboxTestRunner.java:269)
at org.robolectric.internal.bytecode.Sandbox.lambda$runOnMainThread$0(Sandbox.java:89)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I've added ReLinker and Bugsnag with:
implementation 'com.github.KeepSafe:ReLinker:1.4.3'
implementation 'com.bugsnag:bugsnag-android:5.+'
I am not entirely sure the problem is ReLinker, but I am able to run the tests when I remove the two lines loading libraries.
Please let me know if I haven't shown enough code, and I'll update my post with whatever code needed.
Thank you.
This looks to be a Relinker problem as it occurs when loading various other native libraries not just Bugsnag.

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

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/

Getting error when running Invoke-AppWrappingTool with Android App Wrapping Tool

I am unable to wrap my Android app using Wrapping tool.
When I run the following command:
Invoke-AppWrappingTool -InputPath C:\...... -OutputPath C:\output.... -KeyStorePath ......
I am getting the following error:
Application wrapping in progress. App Wrapping Tool Version:
1.0.1933.1
Failed to package app.
com.microsoft.intune.mam.apppackager.utils.AppPackagerException:
Failed to update this app's supported SDK versi
ons.
com.microsoft.intune.mam.apppackager.utils.YamlManifestUtils.updateAppSupportedSdkRange(YamlManifestUtil
s.java:324)
com.microsoft.intune.mam.apppackager.v2.V2WrapperAgent.wrapManifest(V2WrapperAgent.java:86)
com.microsoft.intune.mam.apppackager.AbstractWrapperAgent.wrap(AbstractWrapperAgent.java:68)
com.microsoft.intune.mam.apppackager.AppPackager.packageApp(AppPackager.java:132)
com.microsoft.intune.mam.apppackager.PackagerMain.mainInternal(PackagerMain.java:198)
com.microsoft.intune.mam.apppackager.PackagerMain.main(PackagerMain.java:56)
com.microsoft.intune.mam.apppackager.utils.AppPackagerException: This
app's target SDK is above the MAM target S
DK. Please upgrade to the newest version of the App Wrapping Tool.
com.microsoft.intune.mam.apppackager.utils.YamlManifestUtils.updateAppSupportedSdkRange(YamlManifestUtil
s.java:305)
com.microsoft.intune.mam.apppackager.v2.V2WrapperAgent.wrapManifest(V2WrapperAgent.java:86)
com.microsoft.intune.mam.apppackager.AbstractWrapperAgent.wrap(AbstractWrapperAgent.java:68)
com.microsoft.intune.mam.apppackager.AppPackager.packageApp(AppPackager.java:132)
com.microsoft.intune.mam.apppackager.PackagerMain.mainInternal(PackagerMain.java:198)
com.microsoft.intune.mam.apppackager.PackagerMain.main(PackagerMain.java:56)
The application could not be wrapped.
I am using targetSdkVersion 26 & compileSdkVersion 25.
It reads: Please upgrade to the newest version of the App Wrapping Tool.
... which can be found here.

error: cannot find symbol method getColor(Context,int) after adding Sugar ORM to project

I would like to use SugarOrm in my app.
If I add the followings:
compile 'com.github.satyan:sugar:1.4'
to the gradle file
and
android:name="com.orm.SugarApp"
to my mainfest's application name
I get the following error on build:
Error:(75, 55) error: cannot find symbol method getColor(Context,int)
at this line:
holder.bg.setBackgroundColor(ContextCompat.getColor(ctx, R.color.primary_move));
If I checkout to a previous version without these 2 lines, my application builds and runds without error.
Any suggestions?
From the Android Documentation:
Helper for accessing features in Context introduced after API level 4
in a backwards compatible fashion.
Do you really need that backward compatibility? Try accesing getColor from the context. You can also still useContext.getColor() while you resolve the main issue however
I have updated to compile 'com.github.satyan:sugar:1.6' and error is gone.

Categories

Resources