6

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?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Bhavana Vadodariya
  • 2,287
  • 1
  • 19
  • 26
  • Set the already existing project as an [Android Library Project](http://developer.android.com/tools/projects/index.html). Then you can add it as a library to other projects. – Sound Conception Nov 20 '13 at 13:03
  • hi @SoundConception, read the first paragraph, I have already mentioned this approach, but what i want to use just a single file – Bhavana Vadodariya Nov 20 '13 at 13:10

3 Answers3

6

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.

j__m
  • 9,392
  • 1
  • 32
  • 56
2

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.

RajaReddy PolamReddy
  • 22,428
  • 19
  • 115
  • 166
  • tried.... give the one line code in which you can access resource of first(library) project's into second one – Bhavana Vadodariya Nov 20 '13 at 13:24
  • yeah checked, again same asking same thing.... **give the one line code in which you can access resource of first(library) project's into second one** – Bhavana Vadodariya Nov 20 '13 at 13:26
  • check this http://stackoverflow.com/questions/17063826/how-to-create-jar-for-android-library-project/17064024#17064024 – RajaReddy PolamReddy Nov 20 '13 at 13:30
  • earlier i have came to this answer.. but what i m asking **how to access your resources??** giving you one example.. your library's package name in com.package.lib, you have copied its jar and all that like you have completed the steps which has been mentioned in you last comment's link, now how you will get resources for eg. **_setContentView(com.package.lib.R.layout.layout_comes_from_lib_not_from_your_current_project));_** this is just an eg, if you have any other way...please mention, it will be really helpful to me – Bhavana Vadodariya Nov 20 '13 at 13:43
1

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.

johntheripp3r
  • 989
  • 6
  • 15
  • yes...but that is hard job :( I wud prefer to use another project as library instead of going to merge and to be careful like no resource has same name or by mistake they override...etc solution should be available in future – Bhavana Vadodariya Nov 29 '13 at 14:04
  • @BhavanaVadodariya Its a good idea for you to make a tool for that ;) – johntheripp3r Nov 29 '13 at 14:15