0

I am trying to create a separate project to hold some common files that I use in multiple apps.

I am following this SO question, answer 3 by Aqib Mumtaz, to include the library project in my new app.

I want the ability to edit the shared project as needed and publish to GitHub so that other projects will benefit from my changes.

I created two brand new projects to test out this answer. I created a libraryapp project and set its plugin to apply plugin: 'com.android.library'. I then removed its applicationID as suggested in the same questions answer by Jinbom Heo.

The Library Project

enter image description here

The Dummy App Project

enter image description here

Secondly, I created a dummy app and followed the instructions in the the above answer and a comment about including the library as a module dependency.

enter image description here

I then did a Gradle Sync and received the below errors.

enter image description here

According to this SO question both build.gradle projects should match the buildTypes.

Both of these are brand new project, with nothing in them other than the changes above. So the buildTypes match.

The settings.gradle for the DummyApp.

include ':app'
include ':libraryapp'
project(':libraryapp').projectDir = new File("../MyTestLibrary/libraryapp/")

Both projects are on the desktop.

How do I resolve the dependency issues so that I can work on both projects simultaneously?

user-44651
  • 3,924
  • 6
  • 41
  • 87
  • add `settings.gradle` to the question – Zoe Jan 16 '18 at 20:05
  • @Zoe please see updated question. – user-44651 Jan 16 '18 at 20:09
  • for a 1k user, I'd expect you'd know [not to add screenshots of code and errors](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors), but instead add them as text. Checking now though – Zoe Jan 16 '18 at 20:15
  • Go to project view instead and find `settings.gradle` in the root project. If there are other settings.gradle files in the different modules, **remove them**. Settings.gradle belongs in the root of the project, not in a specific module (when you're dealing with multiple modules) – Zoe Jan 16 '18 at 20:17
  • @Zoe thanks for the screenshot notice. I was attempting to show the file structure of the project too. I updated the `settings.gradle` file with the root `settings.gradle` of the dummy project. – user-44651 Jan 16 '18 at 20:21
  • First off, delete the library module in DummyApp. Since the source is retrieved elsewhere, it's just noise. And make sure you update the project structure so it isn't included – Zoe Jan 16 '18 at 20:29
  • @Zoe I removed the library from DummyApps dependencies.and the Library Module is gone. While the DummyApp sync's correctly, I can't import any of the library's packages. – user-44651 Jan 16 '18 at 20:35
  • Try cleaning and rebuilding, and invalidating caches and restarting – Zoe Jan 16 '18 at 20:39
  • @Zoe that didn't work either. Oddly, the IDE now no longer contains an "Android" project view. – user-44651 Jan 16 '18 at 20:46
  • Are all the modules correctly configured? – Zoe Jan 16 '18 at 20:50
  • In the settings.gradle with new File("../MyTestLibrary/libraryapp/") make sure to refer to the library folder inside the library project and not the root folder of the library project. Check: https://stackoverflow.com/a/46100715/2016562 – Gabriele Mariotti Jan 16 '18 at 20:51
  • Make sure the app module still is an Android module, and try replacing the plugin from library to app in the library project. Clean and rebuild both projects after that – Zoe Jan 16 '18 at 20:55
  • @Zoe I appreciate your help but I can't seem to get this to work. The library shows up now in the project structure of the DummyApp and I can see and edit those files. But my DummyApp can't seem to access any of the library files. Nor can I import the package into any DummyApp file. – user-44651 Jan 16 '18 at 21:27
  • If I add a `public static String A_STRING = "hello";` to the library, the DummyApp can only see it if I do an intention action and it imports `import static com.mycompany.mylibrary.TestActivity.A_STRING;` – user-44651 Jan 16 '18 at 21:31

0 Answers0