1

Let's say I have 5 different apps. They all need to implement a feedback form.

I'm thinking to write a new generic app that has a feedback form and few other activities so all my apps will able to utilize it. My final goal would be something like calling startActivityForResult() then have the feedback form app takes care of everything.

I'm stuck on how to setup all this. I've tried to create a new module from one of the apps but ended up all 5 apps have a different copy of the module which makes future modification hard. I've also tried to create a new project then reference it as described here. Android studio complaints

Unable to resolve dependency for ':app@debugAndroidTest/compileClasspath': Could not resolve project :feedbackform. Open File Show Details

What exactly steps should I do?

EDITED

my settings.gradle:

include ':feedbackform'
project(':feedbackform').projectDir = new File('../FeedbackForm/app')

after adding the above, Android studio will create compile project(path: ':feedbackform') in my gradle

One thing I forgot to mention is that I do not want to upload any of them to cloud. Everything should be kept local.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96
user1865027
  • 3,505
  • 6
  • 33
  • 71
  • You could post the common library to Github, and include as a dependency using [JitPack](https://jitpack.io/) – OneCricketeer Dec 13 '17 at 00:09
  • Or you can add `:feedbackform` to the `settings.gradle`, then `compile project(:feedbackform)` to the `build.gradle`. https://stackoverflow.com/questions/38877989/intellij-gradle-add-module-dependency/38878290#38878290 – OneCricketeer Dec 13 '17 at 00:10
  • Create an AAR file, and share it accross the projects. You can also use Apache Archiva, or Nexus to host your artifacts if you would rather add and upgrade via Gradle – Sam Dec 13 '17 at 00:14
  • @cricket_007 that's what ive done. please see my edited post. – user1865027 Dec 13 '17 at 00:14
  • I forgot to mention that I want to keep everything local – user1865027 Dec 13 '17 at 00:16
  • Do you need them in a separate folder outside the current project? If so, you need to compile `:feedbackform:app` – OneCricketeer Dec 13 '17 at 01:02
  • Check out my solution on [Automating synchronization when developping several libraries and projects at the same time](https://stackoverflow.com/questions/49875198/automating-synchronization-when-developping-several-libraries-and-projects-at-th). – Protean Apr 17 '18 at 13:22

2 Answers2

0

One thing I forgot to mention is that I do not want to upload any of them to cloud. Everything should be kept local.

Given your constraints, why not have the feedback form as a standalone app and then invoke it from your other 5 apps using Intents like this? That way you can avoid the hassle of dealing with local project files since you don't want to upload them to the cloud.

Another option if you have a local repository is use something like Git Submodules or SVN Externals, that way whenever you make changes to your Feedback forms repo you can rely on the source control tools to update them in your other projects.

Filipe Silva
  • 220
  • 4
  • 10
  • because this is a feedback form and will be called multiple times. switching between apps isnt ideal. it also makes no sense to ask user to install 2 separate apps. – user1865027 Dec 13 '17 at 01:34
  • From a technical point of view that would be the "easiest" solution for you, if not this then you might want to review the other suggestions given such as: using a local maven to distribute your forms project as a library, using git submodules or svn externals, generating an AAR file to use across the projects or targeting local files from an external project. If none of these can solve your issue then you might have to duplicate your code. – Filipe Silva Dec 14 '17 at 02:53
0

You can create a module and install it to your local maven as a library by using Gradle Android Maven plugin.

How to do?

First, add the maven plugin to your library module build.gradle:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
    }
}

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

android {
 ...
}

Second, add the group name to your library module build.gradle:

group = 'com.your.packagename'
version = '1.0.0'

It will be like this:

apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'

group = 'com.your.packagename'
version = '1.0.0'

android {
  ...
}

To install the library to your local maven, you can run:

./gradlew install

Or use Gradle tool on the right sidebar of Android Studio:

Gradle->YourLibraryProject->Other->Install

It will be installed as:

com.your.packagename:librarymodulename

Third, to use it in your app, you need to add mavenLocal() to your root build.gradle:

allprojects {
  repositories {
    jcenter()
    mavenCentral()
    mavenLocal() // for local maven.
  }
}

then add the library as dependencies with:

implementation "com.your.packagename:librarymodulename:1.0.0"

Fourth, finished.

ישו אוהב אותך
  • 28,609
  • 11
  • 78
  • 96