New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NoClassDefFoundError: ... R$styleable when using Robolectric with Android Library (AAR) #1796
Comments
Are you using 3.0-rc2 or 3.0-SNAPSHOT? |
I've tried it with both and the behavior is the same.
|
Oh, and strike the comments about using a custom runner. That is no longer necessary as of gradle 1.2 and 3.0-rc2.
|
I have an example for this kind which shows what is necessary to get this work https://github.com/nenick/AndroidStudioAndRobolectric/tree/library-with-aar |
That seems to work as a workaround. Any chance of an actual fix? |
What's the actual cause? If I knew that, I'd be happy to fix it :) |
@nenick What I wound up using is below. It seems to play better with Android Studio and seems to get things build more reliably:
@erd As far as the actual cause, I'm really not sure, new to much of this, but it seems like the R.java file isn't being handled correctly in the case of com.android.library. It seems to work fine in the com.android.application case, as 2 R.java files get generated, one in android... and one in com... With seemingly very different contents. In the com.android.library case, it doesn't work, only one R.java is generated (in com...) The workaround above just copies the generated R.java file into the test source tree, which means it has the wrong contents, but at least it has something that seems to start things working. I'm quite willing to believe it's actually a defect in gradle, just a pain in the ass to work around, especially since, apparently generated java files for tests don't get picked up, so you have to put it in the src tree, not the build/generated tree. |
Is this a Robolectric issue, a gradle issue, or an android gradle-plugin issue? @dwb357 's work around is very helpful, but only gets us so far because it doesn't have any of the actual resources from src/test/res. |
We are having the same problem in 3.0-RC3. The R file from the appcompat library is not found. |
I am seeing the same with
|
Here's some code that works for arbitrary libraries by scanning exploded-aar. It also does the same magic for /assets dirs.
|
I'm getting the below error, I tried all the possible options. any suggestion. java.lang.NoClassDefFoundError: android/support/design/R$styleable |
@jcogilvie It worked !!!!!!!!!! thank you.. I added the below line which is missing |
Have you actually tried this scenario without using Robolectric? I mean reference library resource in Android Unit Test but without Robolectric support? I have created a minimal test project to try it out and I am seeing exactly same issues. So it might be that this one is not on Robolectric. You can check out more here: https://groups.google.com/d/msg/adt-dev/RacBvzBTq9M/5fEv9QD2BwAJ |
Same issue with Robolectric 3.0
|
We've revamped resources in Robolectric 4.0 to process the binary resource files + arsc table produced by aapt and the resource handling code is now much closer to that of the framework. This includes changes to parse the merged manifest using the Android platform code. Mind giving this a try with 4.0 + binary resources by configuring your gradle.build as follows:- testImplementation "org.robolectric:robolectric:4.0"
android {
enableUnitTestBinaryResources=true
testOptions {
unitTests {
includeAndroidResources = true
}
}
} We're doing a big bug scrub and trying to be aggressive about it so apologies if this was closed in error, in which case feel free to reopen. If this is still an issue an example project with failing test would be most helpful. |
We are developing a library that provides an Activity, and I would like to be able to perform some functional testing on the Activity.
My
build.gradle
contains:And my
LibraryActivityTest
includes:Finally, my robolectric.properties:
MyRobolectricGradleTestRunner
overridesgetAppManifest
to restore the ability to specify a test-specific AndroidManifest.xml instead of using the application version.When I attempt to run
testOnCreate
from Android Studio or gradle command line, I get a class def not found error forandroid/support/v7/appcompat/R$styleable
:How can I resolve this error?
The text was updated successfully, but these errors were encountered: