Afaik the android.jar
library is just a skeleton, a mock-up of the android.jar
library present on a running Android system.
If you decompile it, I think that most methods in classes are implemented with just a throw UnsupportedOperationException
and a return null
if needed.
This has been done so that compiling/deploying your application is faster and the resulting .apk
uses less space.
Thus changing source code in that .jar
would be useless, as it would not get deployed to the device/emulator.
If you are interested in changing Android source code, you should really check the documentation for the Android source code and build the entire OS from source.
EDIT:
Re-read the part of your question about adding the .jar
as a user library.
If you deploy android.jar
as a user library (i.e. not shared), then your application will crash at runtime when trying to load classes multiple times (from different sources), as the classes are already present in the android.jar
present on the device.
I.e. you wouldn't be able to load your own implementation of Application
, because it would conflict with the Application
classes that are initialized by Android when starting your application. Your code will not be run until the Application
class is loaded when starting your application and, thus, you wouldn't be able to "override" that.
You can check this question for a bit more info (esp. the answer that has been awarded a bounty).
There's also some info on this question, to which I'd like to add here that, afaik, you can't unload a class while you're using it: if you'd like to use a custom class loader to load your system classes, you'd have to stop all threads of the application that are using instances of the class that you're trying to use, retain information about the existing instances of the class and the class' static data, unload the Android system class, load you custom one, re-create all the instances you retained information about (also restore static data) and then resume all the threads that you have stopped. Also, expect things to break in other places, too, as all the other classes/libraries that you will not override might rely on code that you're changing.