Android Eclipse ANT 项目中的 AAR

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23777423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:26:03  来源:igfitidea点击:

AAR in Eclipse ANT project

androideclipseantaar

提问by czajna666

is there any way to use .aar library (with resources) in eclipse ant project? I know that there is no simply way to use .aar format like in gradle, but maybe there is some workaround to unzip it and import it manually?

有没有办法在eclipse ant项目中使用.aar库(带资源)?我知道没有像在 gradle 中那样使用 .aar 格式的简单方法,但是也许有一些解决方法可以解压缩它并手动导入它?

采纳答案by Ahmed Mostafa

This solution was helpful for me

这个解决方案对我很有帮助

EDIT:A .aar file is simply a zip file with the following contents:

编辑:.aar 文件只是一个包含以下内容的 zip 文件:

  1. AndroidManifest.xml (Required file)
  2. classes.jar (required file)
  3. Res / (compulsory folder)
  4. R.txt (Required file)
  5. Assets / (Optional folder)
  6. libs/*.jar (folder option)
  7. jni//*.so (optional folder)
  8. proguard.txt (optional file)
  9. lint.jar (optional file)
  1. AndroidManifest.xml(必需文件)
  2. classes.jar(必需文件)
  3. Res /(必填文件夹)
  4. R.txt(必填文件)
  5. 资产/(可选文件夹)
  6. libs/*.jar(文件夹选项)
  7. jni///*.so(可选文件夹)
  8. proguard.txt(可选文件)
  9. lint.jar(可选文件)

You see, within the .aar file you have everything you need to operate the library in eclipse.

您会看到,在 .aar 文件中,您拥有在 eclipse 中操作库所需的一切。

to create library:

创建库:

  1. CREATE a new project (hereafter library project ) to your workspace. Do not forget to mark it as a library.
  2. Leave empty src folder library project .
  3. .aar Decompresses the file. You can rename it to .zip and unzip or use any tools.
  4. Copy the file classes.jar into the libs file folder library project .
  5. Res folder replaces the library project with .aar res file folder.
  6. You've created the project that contains almost everything you need.
  1. 为您的工作区创建一个新项目(以下称为库项目)。不要忘记将其标记为库。
  2. 保留空的 src 文件夹 library project 。
  3. .aar 解压缩文件。您可以将其重命名为 .zip 并解压缩或使用任何工具。
  4. 将文件 classes.jar 复制到 libs 文件夹 library project 中。
  5. Res 文件夹将库项目替换为 .aar res 文件夹。
  6. 您已经创建了包含几乎所有您需要的所有项目的项目。

Now let's see how to configure your project to reference the library project.

现在让我们看看如何配置您的项目以引用库项目。

  1. In the project you want to use the library (henceforth, project goal ) added as the dependency library project .
  2. Open AndroidManifest.xml .aar within the file and make sure to copy everything it takes (permits, activities, services, receivers ...) in the file AndroidManifest.xml project objective .
  3. If there is, copy the entire contents of the folder assets .aar file in the assets folder target project .
  4. If there is, copy the entire contents of the file .aar libs folder in folder libs target project .

  5. Make a Clean the workspace and recompiled.

  1. 在您要使用的项目中,作为依赖库项目添加的库(以下称为项目目标)。
  2. 打开文件中的 AndroidManifest.xml .aar 并确保复制文件 AndroidManifest.xml 项目目标中的所有内容(许可证、活动、服务、接收器...)。
  3. 如果有,复制assets文件夹target project中文件夹assets .aar文件的全部内容。
  4. 如果有,将文件 .aar libs 文件夹的全部内容复制到文件夹 libs target project 中。

  5. 清理工作区并重新编译。

http://www.iphonedroid.com/blog/utilizar-ficheros-aar-en-eclipse/#.Vh3krye1Gko

http://www.iphonedroid.com/blog/utilizar-ficheros-aar-en-eclipse/#.Vh3krye1Gko

回答by PedroCactus

Indeed, aar files are just archive files. So you can unzip it and find jar files along with ressources files. The question have already been partially answered here:

实际上,aar 文件只是存档文件。所以你可以解压缩它并找到 jar 文件和资源文件。这里已经部分回答了这个问题:

https://stackoverflow.com/a/21485222/1836870

https://stackoverflow.com/a/21485222/1836870

If you want to get the ressources inside your jar, you could try repackage like it's suggested in this answer:

如果你想在你的 jar 中获取资源,你可以尝试像这个答案中建议的那样重新打包:

https://stackoverflow.com/a/21417599/1836870

https://stackoverflow.com/a/21417599/1836870

回答by goobliata

The brunt of the work can be done by a wonderful script called deaar. The gist explains things, but basically you run:

首当其冲的工作可以通过一个名为deaar的精彩脚本来完成。要点解释了事情,但基本上你运行:

ruby deaar.rb [path/to/aar] [output_directory] 

It outputs an almost ready to use library. Next, you need to run:

它输出一个几乎可以使用的库。接下来,您需要运行:

cd [output_directory]
android update lib-project -p . -t android-xx 

Replace xx with the Android version you're targeting. Now put that directory where your build.xml and project.properties are. Finally, add a line like this to your project.properties:

将 xx 替换为您要定位的 Android 版本。现在将该目录放在 build.xml 和 project.properties 所在的位置。最后,将这样的一行添加到您的 project.properties 中:

android.library.reference.1=./output_directory 

Replace the directory name with the one you created. You can use ".2" and so on for additional libraries. And that's it!

将目录名称替换为您创建的名称。您可以将“.2”等用于其他库。就是这样!

回答by javamonk

Twitter Fabric(Crashlytics) has a kits-libs plugin for dependencies management http://docs.fabric.io/android/fabric/eclipse.html.

Twitter Fabric(Crashlytics) 有一个用于依赖管理http://docs.fabric.io/android/fabric/eclipse.html的 kits-libs 插件。

And there's another gradle plugin project https://github.com/ksoichiro/gradle-eclipse-aar-plugin.

还有另一个 gradle 插件项目https://github.com/ksoichiro/gradle-eclipse-aar-plugin