是否可以将Android包导入到普通的Java代码中
我不是要创建一个Android项目,而只是一个常见的Java程序,我可以从Android SDK导入包以便使用一些有趣的方法并使用JDK中的java编译器进行编译吗?
谢谢。
not to create an Android project but just a common Java program, can i import packages from Android SDK in order to use some interesting methods and compile it using java compiler in JDK.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果包使用 Android 特定的 SDK,则不需要(无需进行一些移植)。如果它是通用 Java 那么可能是的。我已将为 BlackBerry 编写的包导入到 Android,反之亦然,但任何特定于 Android 的 API 调用都必须重写。
If the package uses Android-specific SDK's then no (without some porting). If it's generic Java then probably yes. I have imported packages I wrote for BlackBerry to Android and vice-versa, but any Android-specific API calls have to be rewritten.
下有 Android SDK JAR
在本例中,它是 API 级别 3。我曾经将此 .jar 复制到我正在编码的框架的构建路径 最近。
您可以在 Java 中使用它们,因为它们是 java 字节码并且您的 jvm 可以执行它。您的类可能会使用 Android SDK 的类,但是我认为由于它们中的大多数确实需要 Android 环境,因此它们不仅可以独立工作,而且需要部署到 Android 设备。如果您只是计划导入某些内容但根本不启动 Android 功能,那也没有问题。
There are Android SDK JARs under
In this case it is API Level 3. I used to copy this .jar to the buildpath of a framework that I am coding recently.
You can use those in Java since they are java bytecodes and your jvm can execute it. Your classes may use classes of Android SDK, however I think since most of them do need an Android environment, they will not just work standalone and will require deployment to an Android device. It is fine if you are just planning to import something but not start Android functionality at all.
您可以包含公共库。也就是说,将Android代码打包为库或.jar文件,并将这些库包含在Java应用程序的构建路径中。这应该是双向的。 Android 使用许多与 Java 相同的对象和原则,因此某些功能可以顺利运行。但要注意必须调整它。项目的结构不同
You can include common libraries. That is to say, package the Android code as a library or .jar file, and include the libraries in the build path of the Java application. This should work both ways. Android uses a lot of the same Objects and Principles as Java, so some things will work without a hitch. Beware of having to tweak it, though. Projects aren't structured the same way
也许在某些有限的情况下它可能会起作用,但我对此表示怀疑。 SDK 附带的 jar 文件是存根;它们不包含您在 android.git.kernel.org 浏览源代码时看到的大部分代码。 (例如,请参阅此线程。)
您对什么特别感兴趣使用?
Perhaps there are some limited cases where it might work, but I doubt it. The jar files that come with the SDK are stubs; they do not include much of the code that you see when browsing the source at android.git.kernel.org. (See this thread, for example.)
What in particular were you interested in using?