Android intellij IDEA 11 merge assets directory when using library modules - android

I have an Android project(A) that uses one library module(B) in Intellij IDEA 11. In the main module(A) I have a database file into assets directory and it's working fine.
Let's name the project modules like this: Main module (Module A) and secondary module(Module B).
Now I have to create a database for the library module(B) too and I added the database file into B assets directory because I thought that after compiling the project will be formed of one project having merged the module A and B. But the problem is that the B's database is not copied into the project assets directory.
Is there a way to tell Intellij to merge the assets directory too?
PS: I also have different resources in B's res directory and the application is working properly...
Thank you!

I am not familiar with IntelliJ. But I think this is more related to the Android SDK constraints, other than a config setting from IDE. as it is stated in the official dev guide here:
Library projects cannot include raw assets
The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.
You should not use assets folder in library project, instead, put all db files into your main project's assets folder.

IntelliJ IDEA 11.1 already supports copying assets from Maven apklib dependencies and Android library modules in usual projects. http://youtrack.jetbrains.com/issue/IDEA-80771

You can define an artifact for the project settings for that.
To do so: Right click the Module B project then choose "Open Module Settings". Select Artifacts and press + button to define a new one. Choose the "Other" type and for "Output Layout" select "Add copy of File".

Related

Is there a way to clone an IntelliJ IDEA gradle project?

I'm trying to move my IntelliJ IDEA (2017.3) Android project to another computer just copying the files and it does not work. I am aware of this and this, but in the case of Android project it does not work. All the xml files inside .idea store paths relative to the home ($USER_HOME$) instead of project home ($PROJECT_DIR$). Oddly, Maven projects seem to generate paths relative to the project home and those ones can be copied. But not with gradle projects.
Anyone knows how to solve this ?
EDIT: Bear in mind that I want to copy ALL project settings included running configurations. I want that someone opens the project and find exactly what I have. I know I can reimport the project, but then I'll loose some configuration.
Here's the files and folders that need to be excluded from the copy (assuming that your project has a module called app), preferably if you copy the entire project folder to some where else on the same computer and then deleting the unneeded one by one:
folders .idea, .gradle or any folder who's name starts with a .. They are usually found within the root folder of the project and within the module root folder.
build folder found in the project root folder and in module root folder.
any file who's extension is .iml, found in the project root folder and in module root folder.
local.properties found in project root folder.
The rest of the files and folders need to be kept. With the above excluded, the project can be re-imported in Android Studio properly with the correct configurations relative to your second PC.
On a side note, these are the typical exclusions added in .gitignore of an Android Project Git Repo.
Ok, I found the problem. It is related to how gradle resolve symlinks. This is the issue. Summarizing, if you open your project with a path that contains a symlink, absolute paths will be created in the configuration files and your project won't be portable.
I have reopened the project again using an absolute path and then all the configuration files use PROJECT_DIR instead of USER_HOME

Where do I put assets in a PlayN project?

I've set up a new PlayN project, and it runs some trivial code. I want to add asset files and load them, but where do I put the assets? I found the documentation for the Assets class, but it doesn't say anything about where the actual files go, and how I know what path to request.
After some more digging, I found an article describing the migration from PlayN 1.5 to 1.6. That includes a description of where to put your asset files in versions 1.6 and up.
In the new app organization, games have a top-level assets submodule which contains all of their assets. The android and ios submodules do not depend (in the Maven sense) on the assets submodule, but instead symlink the assets directly into their respective project directories so that they can be found by the Android and iOS build systems. This ensures that the assets are not included twice into the project (once in the jar file and once via the custom Android and iOS build systems). The other backends (HTML, Flash, Java) still load assets via the classpath and do have a dependency on the new assets submodule (in addition to their existing dependecy on the core submodule).
When Maven creates the project skeleton, you should see a project called yourapp-assets with a folder src/main/resources/assets. Anything you put in there can be loaded with the Assets class. If you create a file src/main/resources/assets/images/smile.png, then you can load it with PlayN.assets().getImage("images/smile.png").

AAR in Eclipse ANT project

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.

Use already developed android project [with its resources(xml, images, layout)] into another project directly as .xyz file

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.

how to reference an asset in a library project

In a class belonging to a Library project I call:
webview.loadUrl("file:///android_asset/info.html", null);
Unfortunately, this only works if I duplicate the file info.html into the Application's project asset folder as well.
Is there a way to tell an Android library code: "look for this file in the library's assets folder, not in the application's assets folder" ?
This answer is out of date, the gradle build system and AAR files support assets.
From the Android Docs:
Library projects cannot include raw assets
The tools do not support the use of raw asset files (saved in the assets/ directory) in a library project. Any asset resources used by an application must be stored in the assets/ directory of the application project itself. However, resource files saved in the res/ directory are supported.
If you want to include files from a Library project, you'll need to put it in the resources instead of the assets. If you're trying to load HTML files from your library project into a WebView, this means that you'll have to go a more roundabout method than the usual asset URL. Instead you'll have to read the resource data and use something like loadData.
This is now possible using the Gradle build system.
Testing with Android Studio 0.5.0 and v0.9 of the Android Gradle plugin, I've found that files such as
MyLibProject/src/main/assets/test.html
are correctly packaged in the final application and can be accessed at runtime via the expected URL:
file:///android_asset/test.html
You can achieve this by creating a symbolic link in the project's asset folder that points to the directory in the library project.
Then you can access as below:
webview.loadUrl("file:///android_asset/folder_in_a_libary_project/info.html", null);
Okay. Ive been stressing out and losing sleep about this for a while. Im the type of person that loves API creation, and HATES complicated integration.
There arent many solutions around on the internet, so im quite proud of what Ive discovered with a bit of Eclipse Hackery.
It turns out that when you put a file in the Android Lib's /assets folder. The target apk will capture this and place it on the root of the APK archive. Thus, making general access fail.
This can be resolved by simply creating a Raw Java Library, and placing all assets in there, ie (JAVALIB)/assets/fileX.txt.
You can in turn then include this as a Java Build Path Folder Source in
Project > Properties > Java Build Path > Source > Link Source.
Link Source
Click on Variables. and Add New Variable, ie VAR_NAME_X. location : ../../(relative_path_to_assets_project)
Click Ok
Now, when you build and run your app, the assets folder in the APK will contain your (GLOBAL Library) files as you intended.
No need to reconfigure android internals or nothing. Its all capable within a few clicks of Eclipse.
I confirm that Daniel Grant's approach works for at least the following situation: target project does NOT have an asset folder (or the folder is empty, so you can safely delete it).
I did not setup any variable.
Simply setup a LinkSource as follows (just an example)
Linked folder location: /home/matthew/workspace_moonblink/assetsForAdvocacy/assets
Folder name : assets
The "assetsForAdvocacy" is a Java project, (created with New- Project - Java Project) with empty src folder, and a new folder named "assets", which now provides the entire assets folder for the target project.
This is a fairly straightforward way within Eclipse to provide assets re-use across many different projects IF they do not already have assets, good enough to get going with. I would probably want to enhance it to become a content provider in the long run, but that is a lot more development.
My project accesses the assets with the following code:
String advocacyFolderInAssets = "no_smoking/"; //a folder underneath assets/
String fn =advocacyFolderInAssets+imageFilename;
Bitmap pristineBitmapForAdvocacy = getBitmapFromAsset(context, fn);
I use Motodev Studio 3.1.0 on Ubuntu. It would not let me 'merge' a new assets folder in the new assets-only project onto an existing assets folder in the target project.
If you want to use a setup where multiple derivate products are created from one library you might consider using svn:externals or similar solution in your SCM system. This will also do the trick that static assets like online help may be versioned seperately from the android source code.
I found this older question, it might help you, too.
This is the official way Google uses to archive this (from the above post): Link

Categories

Resources