[android-developers] Reusable code organization with Android Studio

2015-01-23 Thread Nobu Games
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.


[android-developers] Reusable code

2011-05-25 Thread Tommy
Hi,

I'm new to android development and I've (not unexpectedly) run into a
smal problem. The answer is out there, but it has not been clear to
me.

I'm making an application with four activities. Activity one spawns
the other three into a tabview. Each of these three activites use two
methods that are common among them. For instance a method that
analyzes a string. So far I have copied this method-code into each
activity, but there must be a way to make such a method accessible to
all three activities within this application? Or do I need to
diveintoandroidbooks to understand why this isn't possible?

--
Tommy

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


Re: [android-developers] Reusable code

2011-05-25 Thread TreKing
On Wed, May 25, 2011 at 12:26 PM, Tommy tommy.myrv...@gmail.com wrote:

 So far I have copied this method-code into each activity, but there must be
 a way to make such a method accessible to all three activities within this
 application?


Of course. You could have a base class that does function that the others
extend from. Or have some helper object that does the work and have the
others create an instance of it to do the work. Or a static function that
does the work requiring a single call from the other classes.

These are general programming concepts that are not specific to Android. Get
yourself some books that discuss good programming practices and just keep
hacking - this is the kind of stuff you learn with experience over time.

-
TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago
transit tracking app for Android-powered devices

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