简体   繁体   English

Android项目中的Java库

[英]Java Library in Android Project

I want to make a java library (so I can compile it into a jar) that makes calls to a server. 我想制作一个Java库(以便可以将其编译到jar中)来调用服务器。 I then want to share this amongst android application projects so that I can access those simple calls. 然后,我想在android应用程序项目之间共享它,以便我可以访问这些简单的调用。

Is using HTTPRequest the best way to do this? 使用HTTPRequest是执行此操作的最佳方法吗?

http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html http://docs.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html

Something about making web calls in the java way and sharing them in android apps seems odd to me. 对我而言,以Java方式进行网络通话并在android应用程序中共享网络通话似乎有些奇怪。 should this be an Android Library instead? 应该是Android库吗? (I believe those should only be used when resources are involved) (我认为只有在涉及资源时才应使用这些资源)

Sorry for the potentially simple question. 对不起,这个潜在的简单问题。

You can develop a common Java library that you can use with both android , and regular java projects. 您可以开发一个可以与android和常规java项目一起使用的通用Java库。

Take a look at OkHttp , it shows you how to achieve this. 看一下OkHttp ,它向您展示了如何实现这一点。 It is related to HTTP client, may be it already provides everything you need. 它与HTTP客户端有关,可能已经提供了您所需的一切。 You can extend it where needed. 您可以根据需要扩展它。

For a simpler example ( ~20 java classes ), take look at Okio , the underlying io library used by OkHttp. 对于一个简单的示例( 约20个Java类 ), 请看 Okio,它是OkHttp使用的基础io库。

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

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