用javac编译android应用 [英] compile android app with javac

查看:34
本文介绍了用javac编译android应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试调整和测试 Android 应用程序的一部分.所以我提取了两个文件,并尝试使用 javac 编译器制作一个快速的可执行文件,以便快速测试-调整-重新测试周转.我只想通过传递单独的参数来测试这一段代码.如果我可以只用 javac 编译它然后运行我的测试,这将更快地工作.

I have a portion of an android app that I am trying to tweak and test. So I have pulled out two files and am trying to make a quick executable for quick test-tweak-retest turnarounds using the javac compiler. I just want to test this one section of code with handing it separate parameters. This would be FAR quicker to work with if I could just javac compile it and then run my tests.

但是我很难让 javac 编译器找到 Android 库.

But I'm having a hard time getting the javac compiler to find the Android libraries.

谁能帮我用 javac 将这两个文件编译成一个可执行文件?仅供参考,这两个文件实际上只使用主要导入 android.os.Environment;图书馆.

Can anyone help me compile these two files into one executeable using javac? FYI right now these two files really only use the main import android.os.Environment; library.

感谢任何人可以提供的任何建议/帮助.

Thanks for any advice/help anyone can provide.

推荐答案

但是我很难让 javac 编译器找到 Android 库.

But I'm having a hard time getting the javac compiler to find the Android libraries.

无论如何那对你没有帮助.安卓是一个操作系统.它不仅仅是少数 Java 类.而且,android.jar 文件中的 Java 类无论如何都不是真正的实现,只是在每个方法上抛出 RuntimeException 的存根.

That would not help you anyway. Android is an operating system. It is not just a handful of Java classes. And, the Java classes that are in the android.jar files are not real implementations anyway, merely stubs that just throw a RuntimeException on every method.

谁能帮我把这两个文件用 javac 编译成一个可执行文件?

Can anyone help me compile these two files into one executeable using javac?

你不能,因为:

这两个文件...使用...android.os.Environment

these two files... use... android.os.Environment

相反,修改这些文件以消除它们对 Android 类的依赖,因此它只是纯 Java 代码.

Instead, modify those files to remove their dependency upon Android classes, so it is just pure Java code.

或者,尝试 Robolectric 并使用它创建这两个类的单元测试.我不能保证你的代码会工作(我不知道 Robolectric 的模拟 Environment 会为你调用的方法返回什么),但它很有可能会工作.

Or, try Robolectric and create a unit test of those two classes using it. I cannot guarantee that your code will work (I have no idea what Robolectric's mock Environment will return for the methods you are invoking), but there's a decent chance that it will work.

这篇关于用javac编译android应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆