Import *.jar Package
Create a new Android project, add a third-party already packaged jar file into your project, the following has added a odata4j package
Add a libs file to your project
Add your downloaded jar file to the Libs folder directly via Copy/past
Then in the Libs folder and add the *.jar file under the mouse click menu Add as Library
Then, in the Select item, click Open Module Settings, select Add File in dependencies
This completes the JAR file addition
Open the App directory has a build.gradle file should be the project structure file, the above action is just to add under the file
dependencies {
Compile files (' Libs/android-support-v13.jar ')
Compile files (' Libs/odata4j-0.7.0-clientbundle.jar ')
}
Importing third-party Java class libraries with source code packages
The following shows how to import a third-party source code class library in this project, here is an example of importing httpzoid a JSON HTTP client class library
Download the zip package from GitHub and copy the Httpzoid directory to your project directory
This directory will appear automatically when you add a project under Android studio
Next you need to manually modify the project and directory under Settings.gadle add
Include ': App ', ': httpzoid '
There must be manual modification here no other way
Then in the open app/build.gradle this file, add
dependencies{
Compile project (': Httpzoid ')
}
This is the class library that you have imported into the httpzoid, as you can see in opening the Open Module settings
But compiling must still be wrong.
You must also add a Build.gradle file under the project Httpzoid directory, which reads as follows
Buildscript {
repositories {
Mavencentral ()
}
dependencies {
Classpath ' com.android.tools.build:gradle:0.6.+ '
}
}
Apply plugin: ' Android-library '
repositories {
Mavencentral ()
}
Android {
Compilesdkversion 18
Buildtoolsversion "17.0.0"
Defaultconfig {
Minsdkversion 14
Targetsdkversion 18
}
sourcesets {
Main {
Manifest.srcfile ' Androidmanifest.xml '
Java.srcdirs = [' src ']
Resources.srcdirs = [' src ']
Aidl.srcdirs = [' src ']
Renderscript.srcdirs = [' src ']
}
}
}
dependencies {
Compile ' com.android.support:appcompat-v7:+ '
Compile files (' Libs/gson-2.2.4.jar ')
}
This is a post-compilation, and it can be an error.
In this case, you may need to modify the Androidmanifest.xml file in the Httpzoid directory may exist and the file in your project conflict or the version span is too large to cause the syntax error modification
After all these steps, you can basically be cheap and successful.
Android Studio uses a third-party class library