0

How can I use an application from another project as a library, when that application depends on a library that I am already using?

Here’s what I have:

MyProject
  app
  libraries
    ExoPlayer
      demo
      library

Here's my current configuration as it pertains to this.

demo/build.gradle:

apply plugin: 'com.android.application'
...
dependencies {
    compile project(':library')
}

library/build.gradle:

apply plugin: 'com.android.library'

MyProject/settings.gradle:

include ':libraries:ExoPlayer:library'

MyProject/app/build.gradle:

dependencies {
    compile project(':libraries:ExoPlayer:library')
}

As you can see I’m using ExoPlayer library as a library (go figure) but I want to use demo application as a library as well (specifically for the DemoPlayer, I don't want the activities). But demo also has a dependency on library. What do I have to put in my gradle files to achieve this?

I tried to follow the library setup and apply it to demo but it broke the demo build:

Project with path ':library' could not be found in project ':libraries:ExoPlayer:demo'

I have tried following other similar threads such as this one but with no success.

I appreciate any help.

Community
  • 1
  • 1
rmp251
  • 5,018
  • 4
  • 34
  • 46
  • It's not constructive to downvote a question without saying why. What is wrong with this question? – rmp251 Aug 19 '15 at 11:29

1 Answers1

0

A long time ago I've use Exoplayer as a library project but it's not needed anymore : you can use gradle dependencies :

compile 'com.google.android.exoplayer:exoplayer:r1.4.2'

If you want to persist with library project, you will have to check your settings.gradle where all Android Studio referenced module are in. This file contain the name of module as you will use it after.

Example : (based on AndroidVuMeter)

settings.gradle

include ':app', ':vumeterlibrary'

project structure

Project/
   app/
   vumeterlibrary/

To use vumeterlibrary you will have to use compile project(':vumeterlibrary') in your app build.gradle

Hugo Gresse
  • 17,195
  • 9
  • 77
  • 119
  • That looks like exactly what I tried above, but with different project stucture. Can the argument to `compile project` be a path to a subproject or does it have to be in the root project folder? – rmp251 Sep 19 '15 at 17:14
  • You not need to use a sub-project pass, but the projet name like `yourlibrary` which is defined in your root `settings.gradle`. Dont hesitate to check out the AndroidVuMeter library Linked in my answer – Hugo Gresse Sep 19 '15 at 17:42