Considerations for adding third-party libraries to Android studio
preface
When many people start learning about Android, they will choose Google's official Android studio as the development tool. Because it is different from the previous eclipse, there are many problems. The main problems are the import problem and the problems caused by the Android SDK of Android studio.
First, let's talk about the method of importing third-party libraries into Android studio. Taking xutils as an example, the way of importing jar packages is relatively simple. I won't introduce it again. We mainly talk about the introduction of library library files.
The first step is to put the package to be introduced into our project directory, as shown in the following figure
Then you can see this third-party library in our project directory
However, this is not enough. We also need to build in the app directory of the project (there is one in the project root directory and one in the app directory of the project. Here we configure the one in the app directory) Some things are configured under the gradle
Here we let our engineering team rely on this third library
At the same time, add the setting of xutils in the setting file under the project root directory
Then we need to build. Net under the third-party library Gradle file
The main settings are the three places marked above. Just make sure they are consistent with the environment you use.
The general setting of third-party libraries ends here.
However, the xutils framework is due to Android 6.0 after Android 6.0 Version 0 removes support for the HTTP client of Apache. If the target version of your app is Android 2 3 (API level 9) or higher, please use httpurlconnection class to replace, so there will be a problem error: (20,32) error: package org apache. http. When the protocol does not exist, our solution is to build in the xutils framework Add the usage of legacy Library in gradle directory as follows
Adding this step to other online materials often works, but I found other errors in the process of my actual operation
Error: (39,32) error: unable to access httprequestbase
Org.org not found apache. http. client. methods. Class file for httprequestbase
The final solution is
Build. In the app directory of the project Add the use of this library again in gradle
The above is the whole content of this article. I hope it will bring some help to your study or work. If you have any questions, you can leave a message.