简体   繁体   中英

How to Add JAR (HTMLCleaner) to Project in Android Studio 1.1?

I've spent countless hours trying to add a simple JAR (HTMLCleaner) to my project in Android Stuio 1.1 to no avail. I imported the JAR as a module through the interface (File > New Module > Import JAR...), added it as a dependency on my app module, and even reference it in my AndroidManifest.xml <uses-library etc...>.

When I try to "import org.htmlcleaner;" in any of my classes I get a "cannot resolve symbol error." I've researched and tried every suggestion in every permutation and combination. Can anyone offer additional direction or a step-by-step tutorial on the proper way to do this?

Remember that Android Studio uses Gradle as a build tool, and part of the build flow is to handle dependencies. That being said, you have to specify to Gradle that includes your external jar files, making the following modifications:

  • Open build.gradle file of your module project (generally called "app")
  • Inside "dependencies", add compile fileTree(dir: 'libs', include: ['*.jar'])
  • Create a folder called libs inside your module app.
  • Copy your jar file inside of it

Run the build process of Gradle clicking in the "Sync now" link of Android Studio, and now your library should be recognized.

You can add jar file by following Rodrigo Ayala answer. Also Instead of using jar file you can also add the dependency in your project by add the following lines to build.gradle

  dependencies {
            // your other dependencies
            compile 'net.sourceforge.htmlcleaner:htmlcleaner:2.16'
  }
  1. Inside your "app" module create a new folder "libs".
  2. Paste your jar file inside libs folder.
  3. Right Click on the jar file and select "Add as library".
    DONE.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM