[英]What's the difference between principles of useLibrary and compile files('') in build.gradle?
After Android 6.0 releases, Support for the Apache HTTP client is removed. 在Android 6.0发行之后,将删除对Apache HTTP客户端的支持。 If our app is using this client and targets Android 2.3 (API level 9) or higher ,
HttpURLConnection
class is recommended. 如果我们的应用程序正在使用此客户端,并且定位到Android 2.3(API级别9)或更高版本 ,则建议使用
HttpURLConnection
类。 It's said that this API is more efficient because it reduces network use through transparent compression and response caching, and minimizes power consumption. 据说此API效率更高,因为它通过透明压缩和响应缓存减少了网络使用,并最大程度地降低了功耗。 If we want to continue using the Apache HTTP API s, you must first declare the following compile-time dependency in our
build.gradl
e file: 如果要继续使用Apache HTTP API ,则必须首先在
build.gradl
e文件中声明以下编译时依赖项:
android {
useLibrary 'org.apache.http.legacy'
}
The legacy jar is in Android SDK , whose path is sdk/platforms/android-23/optional/
. 旧版jar位于Android SDK中 ,其路径为
sdk/platforms/android-23/optional/
。 So, it is nearly independent. 因此,它几乎是独立的。 Meanwhile, this apache legacy jar is putted into
optional/
in Android SDK, so what is optional/
? 同时,此apache旧版jar放在Android SDK中的
optional/
中,那么什么是optional/
? What does that mean? 这意味着什么?
Also we know, we can put this jar into libs
and then declare it in our build.gradle
file like this: 我们也知道,我们可以将这个jar放入
libs
,然后在build.gradle
文件中声明它,如下所示:
dependencies {
compile files('libs/org.apache.http.legacy.jar')
}
Both methods worked as expected when I tested. 测试时,这两种方法均按预期工作。
But why? 但为什么?
What's the difference between useLibrary
and compile files('')
in build.gradle
? useLibrary
和compile files('')
有什么build.gradle
? Only because the legacy jar file is in android SDK so I can declare useLibrary
in build.gradle
to use it? 只是由于传统的jar文件采用的是Android SDK,所以我可以声明
useLibrary
中build.gradle
使用它呢? Could I use other jars in this way? 我可以这样使用其他罐子吗?
Could somebody provide some ideas about this? 有人可以提供一些想法吗?
useLibrary
adds the library to classpath while compiling but does not bundle the library with the application. useLibrary
在编译时将库添加到类路径中,但不会将库与应用程序捆绑在一起。
compile
dependencies are in classpath at compile time and additionally they get shipped with your APK. compile
依赖项在编译时位于classpath中,此外,它们还随APK一起提供。
For the Apache HttpClient support, use useLibrary
when compiling with SDK 23+. 为了获得Apache HttpClient的支持,在使用SDK 23+进行编译时,请使用
useLibrary
。 The library is already there in the target platform. 该库已经在目标平台中了。 It is just not there in the compile SDK.
它只是在编译SDK中不存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.