I Have aar project and I want to add license to jar file.
I add licence to .pom file, but I want add it to jar and get structure like this:
Is it possible add LICENSE.txt to .jar by gradle?
if you want add LICENSE.txt into your android library (aar). you should do two things:
add your LICENSE.txt to your project, path: src/main/resources/META-INF(other resources folders are acceptable as well)
add "android {packagingOptions{ merge '**/LICENSE.txt'}" into your xxx(sdkname)/build.gradle file.
the keyword merge means add all matching files to your aar
here is the jar document describes:
JAR file is a file format based on the popular ZIP file format and is used for aggregating many files into one. A JAR file is essentially a zip file that contains an optional META-INF directory
the META_INF function is that:
The META-INF directory, if it exists, is used to store package and extension configuration data, including security, versioning, extension, and services.
so I think you should put it int the META_INF files. you can see this answer get some solution.
Related
I have cross compiled the native code for different architectures for android and have its corresponding jni wrapper class working in android studio. Now I want to make it available as a library. I have two questions:
1)Can I just jar the .so file and jni files to make the library?(not .aar because my library contains only the pure java and native code, no android related stuff such as .xml,res,etc) If so what should be its structure?
2) If I cannot create .jar file, then all I am left with is creating the .aar file. That would include the use of android studio. Can I do it without the android studio?
Edit 1:
If I jar the files, then I don't want to extract .so and then use it. If I jar the files, then add it(the .jar) as a dependency in my project then it should automatically put .so into libs/jni folder in my apk so that jni can find it. Question is how do I do that?(if possible)
Fortunately found a way. As .aar is itself a simple zip file with structure as specified here. What I did is "jar" all the .class files (inside proper package folder) into classes.jar, created an empty folder "res", put all .so files in jni folder (with proper architecture) and made a simple AndroidManifest.xml containing basic tags. Then I jar them into file with extension .aar (like mylib.aar). I have tested it by copying .aar into another project's libs folder and putting a dependency on it in app's build.gradle( like compile(name:'mylib',ext:'aar')). And it works great.
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/
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.
I have read lots of questions on this site and come to the decision that if you wish to use your already developed code with its resources in android then you have to use it as a library.
But from the Building Android applications with Gradle tutorial I read something like...
Gradle supports a format called Android ARchive (AAR) . An AAR is similar to a JAR file, but it can contain resources as well as compiled bytecode. This allows that an AAR file is included similar to a JAR file**.
Does it means that we can use .aar file as an .jar file but with facility of using resources also?
Then I have tried to crate .aar file with the help of Android Studio, but .aar file doesn't contain layout XMLs or images -- it contains some layout and resources but it doesn't contain projects other resources file.
At last I am having the only same, annoying, stupid question: Can we use whole project with its resources with only one file like .jar or .aar or any other file format?
RajaReddy is quite mistaken. The JAR contains only code; you cannot access resources that way.
Google distributes their own "Google Play Services Library" as an Android library project, containing the binary code in a JAR file in the lib directory, the resources in the res directory, and an UnusedStub class in the src directory. If a better approach were viable yet I think they'd be using it.
UPDATE: While Android Studio is still in beta, it includes (buggy) support for AAR files. Seems this will eventually be the way to go.
Library projects bin folder contains jar file, copy that jar file in your main Application ( project ) libs folder we can get all the resource folders like this.
Follow these steps !
1) make your library project a normal project by deselecting IsLibrary flag.
2) Execute your project as Android Application. (It will not show any error)
3) you'll find a .jar file in bin folder..
4) Copy .jar in libs folder of your main application.
this will works fine with all the resources.
I was looking for the same thing for years. Combining byte code of java and resources (xml and other files) into one package. Currently I don't think its possible because even google has to include add resources separately in google play services lib available in the SDK .
What you can do best is generate a .aar or .jar file and add a folder of missing resource files.
I have a JAR library which includes some non source code files in a couple different /src packages (JSON files in this case)
When I add that JAR as a dependency on one of my Android projects and build the apk file, those JSON files are not in the apk or the classes.dex (I ran dex2jar and saw that the files are missing)
How can I tell dex to also include those json files in the output?
AFAIK, a dex file is only designed to hold .class files (and strings). Here is an (old) description of the dex file format. (I was unable to find one on google's site) http://retrodev.com/android/dexformat.html
When google parses your dependency jars at compile time it only pays attention to .class files, since that is what dependencies are for - classes you want to use in your code which aren't defined in your code. I'm not sure it even pays attention to anything else you might have in those jars.
The question you want to ask is not how to tell dex to include the json files (it can't) but how to get those json files into your apk. Unfortunately, if they are stored in a jar I don't know of a way to do this short of setting up something in ant to manually unpack the jar and move the files yourself. Compile-time jar dependencies are not designed to simply copy files into your project package.