Issue
I've got two Android applications (not libraries) on Android Studio:
- App A can be built and run on its own;
- App B can be built and run on its own, but needs App A as a dependency.
I've currently set up the hierarchy as instructed in this question (and similar ones), but the result is that the current state of App A was copied inside the App B project folder as a module, so any changes I make inside the actual source files in the project folder of App A are never visible from App B.
What I'd like to achieve is for App B to reference the source files in the App A project folder, and possibly take notice of the changes I make to App A source files in real time without having to manually rebuild/resync anything (i.e. if I delete a referenced variable in App A and save, Android Studio should immediately show the error in App B, etc...).
Basically how an extremely basic Ant project hierarchy you can set up with a couple clicks in Java IDEs would work.
How would I accomplish that in Android Studio?
Solution
I'm provisionally answering my own question, even though what I've got now feels more like a workaround than a good practice, but until someone more experienced chimes in here it is.
App B - settings.gradle:
[...]
include ':App_A'
project(':App_A').projectDir = new File('..\\App_A\\app')
[...]
App B - build.gradle:
dependencies {
[...]
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation fileTree(dir: '..\\App_A', include: ['*.jar'])
implementation project(path: ':App_A')
[...]
}
This is assuming both projects have the same root directory, as in:
C:\Android_Projects\App_A
C:\Android_Projects\App_B
Otherwise, you can input an absolute path in place of ".." in both gradle files.
With that done, your project view of App B in Android Studio will also show a tree structure of the project directory of App A, which is convenient for editing source files of App A while working on App B. But you can also open the App A project in a different window of Android Studio, and all changes made there will immediately be reflected in the App B window as well.
Answered By - sgdsgd
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.