java.lang.NoClassDefFoundError when instantiating classes from android project
When running the tests I am getting java.lang.NoClassDefFoundError when trying to instantiate a class in the main Android Project.
I have my project setup in the exact same fashion as the sample project. My only though on this is that since I can't seem access library files inside of the specifications, is that libraries aren't being loaded into the second project, and the class I am trying to use throws this exception when the dependency can not be loaded.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
Can you print out the full stack-trace and perhaps the file & repository where the error comes from?
Here is that stacktrace
com.andrewreitz.tiles.StateTileStateManagerSpec > get default state FAILED java.lang.NoClassDefFoundError at StateTileStateManagerSpec.groovy:8 Caused by: java.lang.ClassNotFoundException at StateTileStateManagerSpec.groovy:8
The line it's failing on looks like def a = new StateTileStateManager() It is package protected but when I change that to public it doesn't seem to change anything. The constructor has @javax.inject.Inject on it for use with dagger. In the specificiation I can't access @Inject which is what is leading me to believe that the dependencies are not being loaded into this project correctly.
I can however create other simple classes that do not require any library dependencies.
Unfortunately I can't link the repo. I will try to setup a test one in a bit.
Seems like this is actually being caused by rxandroid
Here is the application I created that causes the error. https://github.com/pieces029/robospock-test
Ok, never used that framework before, so I don't know how much I can help.
I'm guessing it's not the specific library and probably something it does. I will keep playing with it and report back the findings.
I think it could be due to the provided dependency to android in the project.
I tried a few other libraries that do the same thing, and get the same results.
https://github.com/ReactiveX/RxAndroid/blob/0.x/build.gradle for reference.
Ah, that explains it...
Only compile dependencies are added currently...
I'm thinking that since test projects usually are not exposed as artifacts, maybe I can just add the provided dependencies as compile to the tester project.
What do you think?
The provided dependency is android, so I'm not sure how that should be pulled in. I'm guessing if it's switched to compile it would cause more issues.
I'll keep playing with it and see what else I can find.
I know =)
Checkout: https://github.com/Centril/gradle-plugin-robospock/blob/master/plugin/src/main/groovy/se/centril/robospock/RoboSpockConfigurator.groovy
As you can see from the code, the project dependencies of the android project is turned into a .jar and then added to the tester project as a testCompile dependency...
Does that grab all the dependencies of other dependencies? I can seem to find the output jar to inspect the class files.
It grabs transitive project dependencies - but only project dependencies.
So if a library has a dependency it never gets those. I'm guessing that there in lies the problem.
Are you applying the groovy plugin somewhere? If so is there a way to just copy over all the dependencies from the app project into the dependencies section of the test app? I'll pull down the code and actually start learning what's going on sometime today.
Ok, I found the issue. Only aars are being pulled in, so any time you reference library code you will get this exception. I am attempting to fix this now.
Just updated to include my work around in the project. https://github.com/pieces029/robospock-test
If you remove the groovy plugin and the dependency section you will see the exception again. Still trying to figure out a way to have this be fixed in the plugin.
For whatever reason both the groovy and java plugins don't pick up any of the dependencies if you do compile project(':app')
Just realized Timber also has transitive dependencies so that wasn't really a good test in that sample app.