Declaring dependencies in settings.gradle and build.gradle between Android and Java project

I’m trying to declare a dependency between 2 subprojects. My Android java project named ‘myapp’ is intended to be dependent on my Java project named ‘PC’. I followed the instrunctions from the official gradle site by adding implementation project(':PC') in build.gradle, under dependencies{} . In settings.gradle I added include ':'PC' . After doing both I got error

> Could not resolve all task dependencies for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve project :PC.
     Required by:
         project :app
      > No matching configuration of project :PC was found. The consumer was configured to find a runtime of a component, preferably optimized for Android, as well as attribute 'com.android.build.api.attributes.BuildTypeAttr' with value 'debug' but:
          - None of the consumable configurations have attributes.

also tried adding

project(':PC').projectDir = new File(settingsDir, '..\\user\\PC')

to settings.graddle, but that didn’t work either, received a syntax error message:

Illegal char <:> at index 43:

Try include 'PC'

AFAIK you shouldn’t use \\ but / (same in Java and Kotlin)

Why are there .. in you file path. Usually subprojects are in the same directory.

Project
  |--SubProject1
      |--src/...
  |--SubProject2
  ...

My guess is, that PC is an independent project actually.
So you should not use include and project(...), but a composite build instead.

I thought I was supposed to write the entire directory. What do I put in build.graddle? I tried with

compile project(‘PC’)

and

implementation project(‘PC’)

Try: implementation project(':PC')

If PC is an independent project it probably should be a composite build (as Vampire mentioned).

yea they are independent, but but 1 invokes a method from the other. I added

includeBuild ‘PC’

to settings.graddle and

tasks.register(‘run’) {
dependsOn gradle.includedBuild(‘app’).task(’:app:run’)
}

to build.gradle. I get no errors, but I can’t do the package import, it stil doesn’t find the package.

Because your includeBuild is wrong, you need the path to it, read the documentation.

Also if you name your files *.graddle I wonder anything works at all anyway. :stuck_out_tongue:

Also the dependsOn you wrote there is absolutely wrong in so many regards.
Read about composite builds in the docs.

https://docs.gradle.org/current/userguide/composite_builds.html