How to reference the jar package (not gradle) and androidgradle in Android Studio

Source: Internet
Author: User

How to reference the jar package (not gradle) and androidgradle in Android Studio

This is a big difference from eclipse. It is estimated that many people are very worried about this setting when using Android Studio.

Open the project structure interface through File-> Projcet structure, or use the shortcut icon.

For example, select Libraries, and then click "+" and select Java.

After you select Java, a dialog box will pop up, select the libs folder where your jar package is located, and click OK (it is best to create a libs directory under the project, put all the jar packages you want to reference in this directory ):


After clicking OK, the following dialog box appears, asking you to select the module to be associated with the imported jar package, select the module you want to associate, and click OK. Then, the jar package is successfully introduced, your project can also be compiled successfully.


Note: In fact, there are still some content in the project structure. I will write an article dedicated to analyzing the functions of the project structure options later.


How to add and use third-party jar packages in android studio

1. Put the jar package in the libs folder of the project.
2. Right-click "Add as library" in the jar package selected in the project ".
3. These two steps are relatively easy to find on the Internet, but the project still cannot be compiled normally. In this case, you need to add dependencies to the dependencies section in the build. gradle file of the project.
{
Compile files ('libs/android-support-v4.jar ')
Compile files ('libs/xxxx. jar ')
}
4. At this time, the project is compiled and running normally. However, when the class instance in the referenced jar is created in your code, the system may throw an exception NoClassDefFoundError, follow these steps:

Then, enter the Command Prompt window.
Locate to the project root directory, that is, the directory where build. gradle is located.
 Run "{android studio installation directory} \ sdk \ tools \ templates \ gradle \ wrapper \ gradlew. bat" clean
Compile re-compile and run the project

The above operations can solve the problem.

How to import jar files and so files during android studio development

Android Studio was just released. I believe many of my friends started to use its development project like me, but new things will always encounter one or another problems, in this case, the third-party jar package cannot be compiled, because it is a new thing and the related information is relatively small. It took me a long time to solve the problem, to avoid further detours, We will list the solutions here.
1. Put the jar package in the libs folder of the project.
2. Right-click "Add as library" in the jar package selected in the project ".
3. These two steps are relatively easy to find on the Internet, but the project still cannot be compiled normally. In this case, you need to add dependencies to the dependencies section in the build. gradle file of the project.
{
Compile files ('libs/android-support-v4.jar ')
Compile files ('libs/xxxx. jar ')
}
4. At this time, the project is compiled and running normally. However, when the class instance in the referenced jar is created in your code, the system may throw an exception NoClassDefFoundError, follow these steps:

Then, enter the Command Prompt window.
Locate to the project root directory, that is, the directory where build. gradle is located.
 Run "{android studio installation directory} \ sdk \ tools \ templates \ gradle \ wrapper \ gradlew. bat" clean
Compile re-compile and run the project

The above operations can solve the problem.

My.oschina.net/zhibuji/blog/147441

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.