3

I have two separate android app projects that were made in android studio I am trying to combine project 1 into project 2 to make it all one app how would I go about doing this? I know how to do it in eclipse but not in android studio. Please note they are both of these projects are android applications none of them are android libraries.

Any help would be amazing!

When I import project 1 into project module I get this error on grade build:

Warning:Dependency School Tools Calc lib.gz:SchoolTools:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: /Users/chrisdebrodie/Documents/School Tools Calc lib.gz/SchoolTools/build/outputs/apk/SchoolTools-release-unsigned.apk

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Phoneswapshop
  • 1,367
  • 8
  • 24
  • 47
  • 2
    Possible duplicate of [AndroidStudio - Module Dependencies in Gradle](http://stackoverflow.com/questions/18656023/androidstudio-module-dependencies-in-gradle) – 323go Nov 04 '15 at 17:51
  • It happnes because you are trying to add a dependency which has a plugin com.android.application. You can't do it. – Gabriele Mariotti Nov 07 '15 at 06:09

3 Answers3

5

You cannot have two "projects" as a single project in Android Studio.

Convert one (or both) project into libraries. Then create a "shell" project to build each app. The shell project is basically empty, or it may have build specific value overrides. The advantage here is that you can modify the library and changes will be immediately reflected in both/all versions. The drawback is that you will have to fix any issues in all projects that result from any change to any library. But you can then create the "combined" project in a similar manner.

After you convert one or both to a library you can create an aar file. This gives you the option to then include that aar as a gradle dependency. Be careful to remember that you will need to re-build the aar every time you modify that project - so if you have an indication as to which is the more stable codebase, go with that for the aar. This gives you the ability to "version control" the main project dependency so that you can make changes to one project without impacting the stability of the other.

Additionally, you can write scripts and use tools like Bamboo or Jenkins to do real-time updates to the aar - but that is like using a "snapshot" dependency. When you change the aar it may compile, but it may break the build of the second project without you knowing it until you do a build on that project. (And yes, you can include a build on that project as a part of the Bamboo or Jenkins script, but it isn't easy.)

There may be other alternatives, but these seem to offer enough options to produce a wide variety of build options.

Jim
  • 10,172
  • 1
  • 27
  • 36
  • thank you for the awesome guide i will try this and let you know how it goes! – Phoneswapshop Nov 06 '15 at 14:08
  • i was able to combine app 2 into app 1 thank you for your help! :) – Phoneswapshop Nov 07 '15 at 16:28
  • @Jim how to convert my android studio project into .aar file. https://stackoverflow.com/questions/48001755/is-it-possible-to-show-multiple-apps-in-my-android-app?noredirect=1#comment82972324_48001755 – Ana Dec 28 '17 at 07:40
0

I write a repo to handle this staff safely and easily: Jacksgong/android-project-combine.

Characteristics:

  • Just a developing env wrapper, it can't modify projects, safe to use. Different Android projects develop together at the one Android Studio window.
  • Find References and Jump into source code rather than .class file on jar package.
  • Jump out of the each projects compile system and using the official compile system.
  • Very light, very fast for each time you want to refresh combine project.
Jacks Gong
  • 694
  • 8
  • 18
-1

Add one project as a module of the another's. This answer explains how to do it. Note that this answer is in response to adding a library dependency, but it will work for your situation as well.

Community
  • 1
  • 1
davehenry
  • 1,026
  • 9
  • 24
  • Thanks I have tried doing this and get this error: Warning:Dependency School Tools Calc lib.gz:SchoolTools:unspecified on project app resolves to an APK archive which is not supported as a compilation dependency. File: /Users/chrisdebrodie/Documents/School Tools Calc lib.gz/SchoolTools/build/outputs/apk/SchoolTools-release-unsigned.apk – Phoneswapshop Nov 04 '15 at 17:52
  • Hmm ok. Do you have control over both of the projects? Can you just modify the gradle file of the module dependency to be a library instead of an application? – davehenry Nov 04 '15 at 17:58
  • I have the source code to both projects the problem is that the app i'm trying to add to my other project can not be used as a library any other thoughts? – Phoneswapshop Nov 04 '15 at 18:04