I've been pulling out my hair over this in the past two days and searched 
the Internet for best practices when it comes to organizing reusable code 
in an Android Studio project. Coming from an Eclipse development background 
it's not really all that intuitive to understand. This post is a bit 
longer, so bear with me.

*TL;DR:* *What's your best practice when it comes to module organization 
and version control?*

The way I organized code so far using Eclipse for development and Apache 
Ant for building projects allowed me to easily keep the app project 
separate from its library projects. They could reside in different 
directories that belong to different version control system repositories. 
Now with Android Studio and my limited understanding of Gradle and the new 
build process I am basically forced to have all so-called library 
*"modules"* arranged as sub-directories of the main app project directory. 
In terms of code organization I have the following options:

   - *I use only a single massive repository *that is basically an Android 
   Studio project that hosts all my Android app modules and custom library 
   modules
      - This is not going to happen
      - I keep app projects in separate repositories and *I import my 
   custom library modules*
      - 
*Importing a module creates a copy of the original *
      - This means *redundancy* and *code synchronization issues*. I may 
      forget to merge back changes I've done to one of the library modules
      - Unfortunately this is the "official" solution provided by the 
      IntelliJ IDEA documentation 
      
<https://www.jetbrains.com/idea/help/sharing-android-source-code-and-resources-using-library-projects.html#d806616e254>
      - I keep app projects in separate repositories and *check out my 
   library modules from a separate repository as a Git submodule 
   <http://git-scm.com/book/en/v2/Git-Tools-Submodules>*
      - I *cannot cherry-pick the needed library modules* from the Git 
      repository. Git submodule checks out the whole library repository
      - It does not play nicely with that one level deep project/module 
      directory structure for Android Studio projects
   - I set up a *Maven repository for my library modules* and add the 
   needed modules as dependencies to my app project
      - Very elegant, but...
      - Every single tiny change in my library code requires rebuilding and 
      deploying the module.
      - I also fear that I need to increase the version code / build number 
      every single time so the local Maven cache gets updated? I have no 
      experience with this. :-/
      
*Here is what I am currently doing* and I'm not sure if it's good enough or 
can be considered a best practice:

This is my directory structure for app projects:
\ projects
    \ my-android-libs   (checked out from library modules repository)
        \ module-1
        \ module-2
        \ ...
    \ App-1             (checked out from App-1 repository)
        \ app
        \ ...
    \ App-2             (checked out from App-2 repository)
        \ app
        \ ...

As suggested in this post <http://stackoverflow.com/a/17490233/1473663>, in 
any of those app projects I need to alter the settings.gradle file and add 
the desired module dependency like this:

include ':app'
include ':module-1'

project(':module-1').projectDir = new File(settingsDir, 
'../my-android-libs/module-1)

Then I also need to add to the app module's build.gradle file a "compile 
project" statement to the dependencies list:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile project(':module-1')
}

This workaround works so far and right now it's the "lesser evil" for me. 
However, I'm still totally new to Android Studio, Gradle and Maven and I'd 
like to hear if you guys know some best practices when it comes to module 
organization, project setup and version control. I'm especially interested 
if anyone of you goes with the private Maven repository solution and how 
that works for you.

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to