0

我花了无数个小时试图在 Android Stuio 1.1 中的项目中添加一个简单的 JAR (HTMLCleaner),但无济于事。我通过接口(文件 > 新模块 > 导入 JAR ...)将 JAR 作为模块导入,将其添加为我的应用程序模块的依赖项,甚至在我的 AndroidManifest.xml <uses-library 等中引用它... >。

当我尝试“导入 org.htmlcleaner;”时 在我的任何课程中,我都会收到“无法解决符号错误”。我已经研究并尝试了每一个排列和组合中的每一个建议。任何人都可以提供有关正确方法的其他方向或分步教程吗?

4

3 回答 3

2

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.

于 2015-02-22T06:49:18.280 回答
2

您可以按照 Rodrigo Ayala 的回答添加 jar 文件。此外,除了使用 jar 文件,您还可以通过将以下行添加到项目中来添加依赖项build.gradle

  dependencies {
            // your other dependencies
            compile 'net.sourceforge.htmlcleaner:htmlcleaner:2.16'
  }
于 2016-05-09T03:10:48.610 回答
0
  1. 在您的“app”模块中创建一个新文件夹“libs”。
  2. 将您的 jar 文件粘贴到 libs 文件夹中。
  3. 右键单击 jar 文件并选择“添加为库”。
    完毕。
于 2016-05-09T03:56:52.037 回答