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?
This solution was helpful for me
EDIT: A .aar file is simply a zip file with the following contents:
AndroidManifest.xml (Required file)
classes.jar (required file)
Res / (compulsory folder)
R.txt (Required file)
Assets / (Optional folder)
libs/*.jar (folder option)
jni//*.so (optional folder)
proguard.txt (optional file)
lint.jar (optional file)
You see, within the .aar file you have everything you need to operate the library in eclipse.
to create library:
CREATE a new project (hereafter library project ) to your workspace. Do not forget to mark it as a library.
Leave empty src folder library project .
.aar Decompresses the file. You can rename it to .zip and unzip or
use any tools.
Copy the file classes.jar into the libs file folder library project .
Res folder replaces the library project with .aar res file folder.
You've created the project that contains almost everything you need.
Now let's see how to configure your project to reference the library project.
In the project you want to use the library (henceforth, project goal ) added as the dependency library project .
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 .
If there is, copy the entire contents of the folder assets .aar file in the assets folder target project .
If there is, copy the entire contents of the file .aar libs folder
in folder libs target project .
Make a Clean the workspace and recompiled.
http://www.iphonedroid.com/blog/utilizar-ficheros-aar-en-eclipse/#.Vh3krye1Gko
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:
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:
https://stackoverflow.com/a/21417599/1836870
The brunt of the work can be done by a wonderful script called deaar. The gist explains things, but basically you run:
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:
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!
Twitter Fabric(Crashlytics) has a kits-libs plugin for dependencies management http://docs.fabric.io/android/fabric/eclipse.html.
And there's another gradle plugin project https://github.com/ksoichiro/gradle-eclipse-aar-plugin.
Related
Would anyone happen to know or have documentation to what the transforms-1 folder is for gradle's caches? For instance on Mac the folders path is ~/.gradle/caches/transforms-1. It seems Android studio uses it but I was wondering what else it is used for?
This appears to be where gradle stores the results of unpacking all of the AAR (Android library files with .aar extension) that are listed as dependencies in your project. When gradle builds your project, it would seem that it creates a corresponding .gradle/caches/transforms-1/files-1.1[your dependency].aar directory for each AAR file you have listed as a dependency in your project's build.gradle file. Each subdirectory in there should contain the jar/classes.jar file (contains all of the dependency's java class files) as well as a res directory that contains all of the additional Android resources with which the jar file was packaged. My assumption is that all AAR files need to be deconstructed into the actual .jar file and associated resources in order for the java compiler to use them in building a project.
How do I extract code from aar file.[Accidentally my main project is on another system can't access only have aar file on my mail]
I need to extract the JNI code from aar file. I tried to change the extension to .jar but its extract .class only, Do anybody know how to extract that aar thing.
Example: libraryproject.aar
Change the file extension to ".jar" example: libraryproject.jar
Extract the jar file into a folder.
The folder will have AndroidManifest, resources and library files used in the android library project.
The folder will also have a classes.jar file, which will have all the classes in the library.
To open classes.jar, use jd-gui tool.
In the jd-gui tool, File ->Open, File->browse and select classes.jar file.
In android studio, open the Project Files view.
Find the .aar file and double click, choose "arhcive" from the 'open with' list that pops up. This will open a window in android studio with all the files, including the classes, manifest, etc.
Only two steps:
Rename the library file extension to ".jar", like: lib.jar
Extract the file in a folder with Winrar, Winzip, etc.
.aar file has zip format, but it contains compiled code of the module only. If your .aar includes JNI, it will be in form of a shared library. You can use it as a prebuilt shared library as long as you can keep it unchanged. You cannot decompile it as easily as the .class files.
Just open preferences, search for plugins and search Android Bundle Support plugin in the search bar. You need to install this plugin to open .aar and .jar files.
https://plugins.jetbrains.com/plugin/10310-android-bundle-support/
I have a project that is an Android Library. It uses two external jars (universal image loader and ksoap).
I need to create a jar from this project to distribute it, but when I do this and use this project, I always get a java.lang.NoClassDefFoundError, saying that the ksoap classes are not found.
When I open the jar file, I see the both jars included, but it seems that the final project does not see them.
How can I do this?
Thanks!
Create a regular Java library and do the following steps:
Add "android.jar" as a library in your project
How to locate it?
android.jar is located in Android SDK
<Android SDK path> / platforms / android-XX / android.jar (XX = API number)
It's simple to do, and it not requires to include "android.jar" in your JAR file, because "android.jar" is already included by default in Eclipse ADT / Android Studio.
NOTE:
For Android Studio, add the library uniquely in this way:
Add this on your build.gradle.
dependencies {
compile files('libs/your-jar-library.jar')
}
For include these two external jars, you need to do following steps:
Unzip both JARS
Unzip your JAR file
Copy the files of the unzipped libraries to your unzipped JAR (Only package folders)
Zip your JAR file with the external libraries included, you don't need to put a JAR inside JAR.
I want to use a svg-android library to work with *.svg files in Android. For the same, I've installed the apache ant, created a folder in workspace called: SVGAndroid and then added
android.library.reference.1=C:\Android\workspace\SVGAndroid
to project.properties file.
There were no documentation for functions in ReadMe, so I'm wondering if the installation correct or not, how to reinstall an external lib in the second case and where are the examples of using svg-android?
For your including of the project, just include the project into your workspace and in your respective application under the properties of that project just add a dependency on a library that references svgandroid. Make SURE to include the files and ensure that the compile class files are present in the final output of the apk. This typically means that you add the project to your build path/order.
Another approach is to just take the entire project and compile it into a jar file and then include that jar in your libs folder and add that dependency on the jar file of that respective project to your core application.
Useful links
How can I use external JARs in an Android project?
I would rather suggest to not add the path to the project manually, but from Project Properties -> Android and you will have a list with all the library projects in the workspace from which you can choose the desired project.
Also I suggest adding in project.properties the following line:
manifestmerger.enabled=true
in order to have all the AndroidManifest.xml files of the referenced library projects merged into the main project's manifest.
If you want to include a library file in to your project follow the below steps;
Download a jar file and save it in any folder.
open your project.
Right click--> Build path--> Add External Archives---> Add your external jar file to your project
I am creating an Android library and it has an assets folder with images.
When I use it in another project the assets doesn't get copied.
Anyone else had this issue?
The new Android Build System that is based on Gradle supports asset folders in library projects!
With ANT based builds it's still not possible:
Library projects cannot include raw assets. (See docs)
But you could
copy the assets manually
or even patch the aapt tool (see http://devmaze.wordpress.com/2011/06/26/enabling-assets-in-android-libraries/)
It is possible to put assets into resulting library jar by small fix:
Put "custom_rules.xml" into you library project home (near the build.xml):
<?xml version="1.0" encoding="UTF-8"?>
<project name="custom_rules">
<target name="-post-compile" if="${project.is.library}">
<echo>Post Compile: add assests from ${asset.absolute.dir} to ${out.library.jar.file}</echo>
<jar destfile="${out.library.jar.file}" update="true">
<zipfileset dir="${asset.absolute.dir}" prefix="assets" excludes="**/*.java ${android.package.excludes}"/>
</jar>
</target>
This will pack your library assets into you resulting library jar. As result, these assets will be included into resulting .apk of your application.
Checked on Android SDK Tools Revision 21.1.0 on OSX
From Eclipse and ANT you can reference the same "assets" folder from multiple projects.
This allows your source tree to have a single copy of the assets files, but have them included in multiple APKs.
See Android: targeted res folders for debugging in eclipse
From ProjectA I was able to reference ..\ProjectA\Assets from ProjectB.
On Eclipse (under Windows at least, I've not tried on Linux yet), I had to create a new variable to reference ..\ProjectA and use that variable in "Linked Folder Location". If I attempted to use ".." in "Linked Folder Location" eclipse wouldn't accept it.
For those using IntelliJ IDEA, you can make a change to your application module's packaging settings to include depedent assets. Note, this was done on version 14.0.2 of IntelliJ Community edition. My main application module now inherits files form my library project's assets folder as if they were right in the main project!
Right click application module > Open Module SEttings. Select Android tree node on module > Packaging Tab. Check "Include assets from dependencies into APK"
Note: I've never used Android Studio, but I would guess there is a similar setting for this in that application.
start by creating android lib project, close after creation. this'll prevert autobuild
use cmd terminal on windows android command is batch file
add tools to path
C:\Users\user_bss>PATH=%PATH%;C:\adt-bundle-windows-x86-20140321\sdk\tools
Generate build.xml for ant
android update project -p C:\Users\user_bss\Documents\Workspace\SDKAdvanced -n SDKAdvanced
notepad custom_rules.xml add the code from above don't forget end tag
run "ant debug" or "ant release" to build
you'll see classes.jar in bin dir this is your packed lib