Question

I am currently starting on quite a huge Android project which will include up to 5 different Apps. Each of these will be dependent of an android library.

This can easily be done by building the shared android library into .jar file and reference this from each App. But the problem is this project is really on the early stages, therefore the code of the library will change just as often as the Apps. It will be quite a pain to always have the library open in a different project, and build it everytime a change has been made.

  1. First question is how to setup a workspace where you can an App and the library open at the same time, and referencing directly to the library. Without any concern about a .jar file.
  2. If it's not possible any ideas? I can't be the first guy starting quite a large android project with multiple Apps.
Was it helpful?

Solution

In Android Studio do the following:

Create a new project. The project will hold all the different APK projects and the shared library. Use "File -> New Project" or select New Project from the splash screen for AS.

In the project, create a new module for each separate APK. Use "File -> New Module -> Android Application". I'm refering to these types of modules as APK modules.

In the project, create a new module for the shared library. Use "File -> New Module -> Android Library" to create the shared library.

Associate the shared library with each APK module by modifying the "build.gradle" file to add a dependency for the shared library. You must change the "build.gradle" file in each of the APK modules.

dependencies {
    compile project(':aaa')
}

Be sure to replace "aaa" with the name of the shared library.

You can have multiple shared libraries if you like.

The code for all the APK modules and the shared library is now accessible under one AndroidStudio project. Another advantage of this approach is that the single project directory that can be turned into a single git repo for the combined APK modules and shared library.

OTHER TIPS

First, IntelliJ doesn't have the same concept of workspace as Eclipse. In a nutshell, the model is as follows: You have one window for each IntelliJ project. An IntelliJ project has one or more IntelliJ modules, which are linked by source. Modules from different projects cannot be linked by source.

Regarding your specific question, I think the easiest solution is to have a single source repo and (multi-project) Gradle build comprising all apps and libraries. This will translate to a single IntelliJ project with one IntelliJ module for each app/library, all linked by source.

If you absolutely need to have separate Gradle builds, and still want a fast turnaround in the IDE, then as far as I know, IntelliJ 13 can add another Gradle build to the same IntelliJ project with the push of a button, and perhaps Android Studio can do the same (not sure). Last but not least, remember that both Android Studio and the Gradle Android plugin are early access previews.

I have tried fiddling with Android Studio and IntelliJ Idea for sometime and the best bet I had was to export everything from eclipse. You could follow the steps below(which is what I usually do.. Does not seem to be a good idea, but it works for sure :) )

  1. Open up ADT or Eclipse and setup a new workspace.

  2. Create the apps and add the library project as a library to those apps. The library project needs to be imported to workspace again(I'm not detailing as I presume you know it)

  3. From File > Export > Android > Generate Gradle Build Files which would generate the gradle build files for the entire workspace. And this then can be opened up in IDEA.

Please do reply if this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top