Linked android modules generate unwanted .iml files - android

I'm ussing the usual way to link android studio modules to a project:
include ':app'
include ':coretools'
project(':coretools').projectDir = new File(settingsDir, '../base/CoreTools/app')
This works as expected but the problem is that this generates a coretools.iml file in the used module folder. I mean, in the above example a coretools.iml is generated under base/CoreTools/app.
The main concern is that this coretools.iml generated file has references to the project that used this module and it is a nightmare to use the module in different projects by different users with a CVS like git.
The question is: Is there any way to avoid this .iml creation? Is this "as designed" and can't be avoided?
Thanks

Please refer to the module documentation:
A module is a discrete unit of functionality which you can compile,
run, test and debug independently.
Modules contain everything that is required for their specific tasks:
source code, build scripts, unit tests, deployment descriptors, and
documentation. However, modules exist and are functional only in the
context of a project.
Configuration information for a module is stored in a .iml module
file. By default, such a file is located in the module's content root
folder.
Development teams, normally, share the .iml module files through
version control.
As you can see there is a lot of useful project-related information in the .iml files but the documentation doesn't state that you always must share those files though a CVS. If the .iml files are a pain for your development team just add them to your .gitignore file.

I finally ended just ignoring all *.iml in the library module but the one belonging go the module. Something like this in the .ignore file did it:
*.iml
!app.iml
being the app.iml the real/original module iml file.
Cheers.

Related

Can a .iml file pull data into project without a corresponding gradle dependency?

I inherited someone's Android project and am trying to remove any unused code to streamline it.
In the process, I found a module with a .iml file but in the build.gradle file there is no corresponding gradle import/implementation naming that module. Would this .iml file actually import a module into my project?
Also, if no code is added because of the .iml, is it safe to say that I can count it as unused code?
Thanks.
No. An .iml file is the IntelliJ IDEA project file.
if you did not find any build.gradle - then it may not be a gradle based project!
How are you determining that it is gradle based ? are there any other gradle related files ?
if there are no other gradle files - it may have been project setup directly via IntelliJ with out any build tool.
you can attempt to open the whole project in IntelliJ and see if works

Why so many metadata files in Android studio?

I created a new project in Android studio and got many files generated, where as my actual code is found in just one folder - src.
Why the so complicated structure? Please explain the motivation of putting meta-files at the root of the project instead of some inner folder named gradle.
Android build system consists of an Android plugin for Gradle. Gradle
is an advanced build toolkit that manages dependencies and allows you
to define custom build logic. Android Studio uses a Gradle wrapper to
fully integrate the Android plugin for Gradle.
Android Studio projects contain a top-level build file and a build file for each module. The build files are called build.gradle, and they are plain text files that use Groovy syntax to configure the build with the elements provided by the Android plugin for Gradle.
Gradle is an automated build toolkit that allows the way in which projects are built to be configured and managed through a set of build configuration files. This includes defining how a project is to be built, what dependencies need to be fulfilled for the project to build successfully and what the end result (or results) of the build process should be. The strength of Gradle lies in the flexibility that it provides to the developer.
For more info you may visit
Gradle Tutorial
Android Application Modules
First of all if you don't want to see those metadata... you can change it(see Image)..
gradle is required to compile your project. for example: In gradle file we specify minsdk version,maxsdk version and dependencies etc
To Know more about gradle go to http://gradle.org/the-new-gradle-android-build-system/
Why the so complicated structure?
IMHO the structure you are referring to is pretty straightforward but your assumption that all those meta-files are related with gradle is wrong.
Meta-files related with your android application are located inside the "app" sub-folder. You have some gradle files there because those are for the purpose of building that specific module.
As pointed out before in a previous answer the best resource to understand the file tree structure for this part is here.
You also have some metadata generated by the IDE (.idea sub-folder):
IntelliJ IDEA stores the configuration data for projects and their
components in plain text XML files making it easy to manage and share
project configuration data with others.
And .iml files:
A module is a discrete unit of functionality which you can compile,
run, test and debug independently.
Modules contain everything that is required for their specific tasks:
source code, build scripts, unit tests, deployment descriptors, and
documentation. However, modules exist and are functional only in the
context of a project.
Configuration information for a module is stored in a .iml module
file. By default, such a file is located in the module's content root
folder.
More info about can be found here.
Please explain the motivation of putting meta-files at the root of the
project instead of some inner folder named gradle.
As mentioned before in some previous answers some metadata is related with the configuration of your project itself and some is module-specific. One example is the build.gradle files. The global file has this comment:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
About the motivation I only assume it was for simplicity and to keep the semantics of the project structure. Other possibility is that it was just by convention.

What are app.iml and proguard-rules.pro doing in my Android app directory?

I am studying the file/directory structure of an Android Studio project.
I don't understand the purpose of two files in /app directory:
app.iml
proguard-rules.pro
May I have some explanation on these files? If I want to share my project with other programmers, then do I have to include these files or just whatever that goes under /src plus build.gradle is enough?
May I have some explanation on these files?
app.iml is an Android Studio-generated file, based on the contents of your build.gradle files, that is used internally by the IDE. Android Studio is based on IntelliJ IDEA; .iml files are IDEA's project metadata files. Android Studio does not consider them to be the system of record — the build.gradle files are — but presumably it was simpler to generate .iml files rather than rework IDEA to not need them.
proguard-rules.pro contains module-specific rules for configuring code obfuscation and shrinking. Presently, that is handled through a tool named ProGuard, which is why the file is named as it is.
If I want to share my project with other programmers, then do I have to include these files or just whatever that goes under /src plus build.gradle is enough?
app.iml is output; it isn't in build/ for technical reasons, I presume. You should not distribute this.
proguard-rules.pro is input. You should distribute this, even if it is largely empty at the moment.
app.iml is a file generated by Android Studio holding information about your project
It is the usual file format for IntelliJ.
proguard-rules.pro is used, if you enable proguard (minifyEnabled true) in your build.gradle file. It helps improving performance and keeping your app small.
To read more about proguard, read here:
http://developer.android.com/tools/help/proguard.html
From intelliJ documentation what I understand is you SHOULD share the iml files to for smooth collaboration with other developers who use android studio, I'm pasting the following text from their documentation, link here https://intellij-support.jetbrains.com/hc/en-us/articles/206827587-How-to-manage-projects-under-Version-Control-Systems
If you decide to share IDE project files with other developers, follow these guidelines:
Directory based project format (.idea directory)
This format is used by all the recent IDE versions by default. Here is what you need to share:
All the files under .idea directory in the project root except the workspace.xml and tasks.xml files which store user specific settings.
All the .iml module files that can be located in different module directories (applies to IntelliJ IDEA)
Be careful about sharing the following:
Android artifacts that produce a signed build (will contain keystore passwords)
In IDEA 13 and earlier dataSources.ids, datasources.xml can contain database passwords. IDEA 14 solves this problem.
You may consider not to share the following:
gradle.xml file
user dictionaries folder (to avoid conflicts if other developer has the same name)
XML files under .idea/libraries in case they are generated from Gradle project
Legacy project format (.ipr/.iml/.iws files)
Share the project .ipr file and all the .iml module files, don't share the .iws file as it stores user specific settings
Android studio will generate a .gitignore with the following values if you integrate git version control integration with the IDE
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build

Android Studio 1.2 migration?

I am following some posts/questions about AndroidStudio-1.2 and it seems that there is a different project structure: app/src/main; while my old 1.0 project looked like: src/main (no app).
Not sure if this is causing this, but I am not able to get gradle to identify any test files, while running tests.
You probably have to rename src/test to src/androidTest.
The app directory is a subproject directory. By default AndroidStudio generate a structure ready for multi-module project. i.e. :
a root directory with the root build.gradle + gradle.settings (listing all modules in your project)
a subdirectory (named "app") where you can put all the sources for your application.
Later it is more easy to add a library module (just create a directory myLib in the root folder).
This structure is just proposed by AndroidStudio: you can also use AndroidStudio with only one level of directory and one single build.gradle.

Android intellij IDEA 11 merge assets directory when using library modules

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".

Categories

Resources