Remove unit tests from distribution JAR
Embedded unit tests make up 50% of the rxjava-core JAR size. Factoring these out into a separate source tree would allow for a more manageable library size for distribution in size-constrained applications. Removing the unit tests from the JAR dropped the size from 600K to 315K.
+1
I noticed a line that was put in comments which excluded unit tests in the build.gradle. I do know that there are unit tests residing in src/main/java, so you would need to move those first.
The unit tests are internal classes of the objects they test. Separating them out would eliminate the junit and mockito dependencies in the core source.
... just read the reasoning for that: http://benjchristensen.com/2011/10/23/junit-tests-as-inner-classes/
This article brings up some interesting topics. Obviously this decision was well thought out.
Indeed. Some very good points in that article.
The one problematic unforeseen consequence that I currently see is that the Scala compiler actually checks for the existence of those internal classes. In contrast to Java, It doesn't allow them to just be absent, even if they're not used anywhere. This means that the idea of simply removing all those inner test classes during packaging doesn't work anymore for any libraries that want to be usable in Scala, which is a pity.
This was also discussed at: https://groups.google.com/forum/#!topic/rxjava/b4DYjvUTazI
For Android specifically, is it not common to use tools such as Proguard (http://proguard.sourceforge.net/index.html and http://developer.android.com/tools/help/proguard.html) to reduce jars to only include classes used by an app? I have been told that is the case (but I don't developer for Android so can't speak to this).
Unfortunately due to Groovy/Scala (and possibly other languages) the general solution of stripping the $UnitTest classes before creating the jar has been disabled, otherwise the issue of Jar file size would not exist.
At this time however the intent is to leave things as they are.
What dependencies? They are 'provided' and not runtime.
RxJava has 0 dependencies beyond the JVM and is a single jar library.
You're right. I missed this thing about "provided" dependencies. Then checked my own build and found no unit test dependencies, understood the idea and removed my comment. Sorry about that.
It's okay, it's what I get for doing something unconventional :-)
@benjchristensen To give you some background on the proguard/Android development practices:
- The testing tools for Android are really shoddy. You cannot run POJO unit tests** without running it through the android framework.
- So running unit tests are pretty slow, as that implies compiling your apk (application package), deploying it on the device, and then having your unit tests run on them. It's a couple of seconds, but still extremely slow for unit tests standards.
- Adding proguard to the mix increases that time by a few more seconds, which makes the possibility of fast testing even less likely. This is why people avoid using proguard (during development).
Ok, so you may then ask: Why not disable proguard for development builds alone? Well, that's what most of us do. However:
- Android has a hard dex method limit of 64k. This basically means, that if you hit this limit (by virtue of having many referenced methods in your app or referencing external libraries that do the same), you are stopped from compiling an apk.
- This means that you cannot compile an app (even on development builds) if you've crossed that limit (it's actually pretty bad, because-as mentioned before- this means you can't even run basic unit tests because of this).
In sum, Android developers (should) use proguard for release builds, but prefer having very small libraries as that helps in avoiding other problems during development.
** Well that is not entirely true, since you can run POJO unit tests, but you have to place them in a different project, and reference them like libraries from within your main project. It's not hard, but not easy enough.
Thanks for the info, it was educational for me on things I didn't know. However, what triggered this since this issue has been closed for 10 months?
hah apologies for waking the dead.
I noticed my apk size increased by about an MB after adding in RxJava, so I started looking around for strategies on minimizing the library size (or if that even made sense). I ran across these two threads, and thought i'll add my two cents for posterity, since the question was raised in both threads.
On Fri, Aug 8, 2014 at 8:17 PM, Ben Christensen [email protected] wrote:
Thanks for the info, it was educational for me on things I didn't know. However, what triggered this since this issue has been closed for 10 months?
— Reply to this email directly or view it on GitHub https://github.com/Netflix/RxJava/issues/297#issuecomment-51675620.
Ah, makes sense :-) Other than removing functionality from rxjava-core, I am not aware of anything more we can do to reduce the size of the Jar at this point. It has zero dependencies, no testing code and only contains core functionality.
Thanks for the background on Android. The 64k limits sound very painful!