简体   繁体   中英

replace android.jar in eclipse

I need make changes in the android source code(android.jar).

I know I can make changes and compile a new android.jar file. I found some links on SO too regarding this.

But what I want to do is, for getting my project running on eclipse, rather than creating an android.jar, I want to add framework.jar, common.jar, core.jar, etc. individually, and remove the android.jar library from the build path in eclipse.

Is it even possible.

I tried it, but it is not working. I added the jar files as system user libraries. I even set the jar files as exported in build path configuration. My code gets compiled, but it gives a launching error for the emulator.

Can anyone give me any inputs regarding this error.

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 (ie 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.

Ie 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM