简体   繁体   English

useLibrary的原理与build.gradle中的compile files('')的原理有什么区别?

[英]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 ? useLibrarycompile 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,所以我可以声明useLibrarybuild.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.

相关问题 React Native:gradle-wrapper.properties 中的 gradle 引用和 build.gradle 有什么区别? - React Native: What's the difference between gradle references in gradle-wrapper.properties and build.gradle? React Native:build.gradle 文件中的 Android Gradle 插件和 ZE84E30B9390CDB64DB6DB2C9D 有什么区别? - React Native: what's the difference between Android Gradle Plugin in build.gradle file and Android Studio? "build.gradle(项目)和 build.gradle(模块)之间的区别" - Difference between build.gradle (Project) and build.gradle (Module) Gradle依赖项:编译项目和编译名称有什么区别? - Gradle dependencies: What's the difference between compile project and compile name? 在build.gradle中编译具有useLibrary'org.apache.http.legacy'的项目时出现'app:transformClassesWithDexForDebug'错误 - Getting 'app:transformClassesWithDexForDebug' error on compiling the project having useLibrary 'org.apache.http.legacy' in build.gradle android build.gradle中testImplementation和androidTestImplementation的区别 - android difference between testImplementation and androidTestImplementation in build.gradle Build.gradle 文件损坏 - Build.gradle files corrupted 一些 build.gradle 文件的语法与其他文件不同? - Some build.gradle files have different syntax's then others? build.gradle编译不建议使用的警告 - build.gradle compile deprecated warning Android Studio build.gradle编译错误 - Android Studio build.gradle compile error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM