简体   繁体   English

在eclipse中替换android.jar

[英]replace android.jar in eclipse

I need make changes in the android source code(android.jar). 我需要在android源代码(android.jar)中进行更改。

I know I can make changes and compile a new android.jar file. 我知道我可以进行更改并编译一个新的android.jar文件。 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. 但是我要做的是,为了使我的项目在eclipse上运行,而不是创建android.jar,我想分别添加framework.jar,common.jar,core.jar等,并删除android.jar Eclipse中构建路径中的库。

Is it even possible. 可能吗

I tried it, but it is not working. 我试过了,但是没有用。 I added the jar files as system user libraries. 我将jar文件添加为系统用户库。 I even set the jar files as exported in build path configuration. 我什至将jar文件设置为在构建路径配置中导出的文件。 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. Afaik android.jar库只是一个骨架,是运行中的Android系统上存在的android.jar库的模型。

If you decompile it, I think that most methods in classes are implemented with just a throw UnsupportedOperationException and a return null if needed. 如果您对其进行反编译,我认为类中的大多数方法仅通过throw UnsupportedOperationException即可实现,并且在需要时return null

This has been done so that compiling/deploying your application is faster and the resulting .apk uses less space. 这样做是为了使应用程序的编译/部署更快,并且生成的.apk使用更少的空间。

Thus changing source code in that .jar would be useless, as it would not get deployed to the device/emulator. 因此,更改该.jar源代码将是无用的,因为它不会被部署到设备/仿真器中。

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. 如果您有兴趣更改Android源代码,则应确实查看Android源代码文档并从源代码构建整个操作系统。

EDIT: 编辑:

Re-read the part of your question about adding the .jar as a user library. 重读有关将.jar添加为用户库的问题部分。

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. 如果您将android.jar部署为用户库(即未共享),则当尝试多次(从不同来源)加载类时,应用程序将在运行时崩溃,因为这些类已经存在于android.jar 。设备。

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. 也就是说,您将无法加载自己的Application实现,因为它会与启动应用程序时由Android初始化的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. 在启动应用程序时,在加载Application类之前,将不会运行您的代码,因此,您将无法“覆盖”该代码。

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. 关于此问题 ,还有一些信息,我想在添加:afaik,您无法在使用它时卸载类:如果您想使用自定义类加载器来加载系统类,则必须停止正在使用您要使用的类的实例的应用程序的所有线程,保留有关该类的现有实例和该类的静态数据的信息,卸载Android系统类,加载您的自定义实例,重新创建您保留了有关信息的所有实例(还还原静态数据),然后恢复已停止的所有线程。 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. 另外,也希望其他地方也会出现问题,因为您将不会覆盖的所有其他类/库可能都依赖于您所更改的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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