How Android Studio imports third-party class libraries

Source: Internet
Author: User

How Android Studio imports third-party class libraries

I have just started to try to do Android app development, I heard that Android Studio is Google supported Android app development tools, so think it should be better than eclipse, anyway, no previous Java development experience, simply from Android Studio began to learn, has been to do. NET development, recently used eclipse,android Studio after the discovery of Visual Studio.NET formally too good, have to say that Microsoft's development tools to do better than anyone else. Here's what I did when I started using the Third class library with Android studio, so write it down for beginners like me and share it.

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.

How Android Studio imports third-party class libraries

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.