简体   繁体   中英

Kotlin + Gradle Unresolved Reference

As per this question I'm trying to setup the following project structure

project/
   settings.gradle
   projectB/  # some common code (using spring-boot)
       build.gradle
       com/
          foo/
             bar/...
   projectA/  # an android app
       build.gradle
       com/
          foo/
             baz/...

settings.gradle looks like

rootProject.name = "project"
include ":projectB"
project(":projectB").projectDir = new File(rootDir, './projectB')
include ":projectA"
project(":projectA").projectDir = new File(rootDir, './projectA')

and in projectA/build.gradle I have

dependencies {
    implementation project(":projectB")
}

Android Stuido seems happy and will provide code completion and searching for code in projectB within projectA . However compilation fails with an error

Unsresolved reference: bar

on the line where I try to import com.foo.bar.whatever .

I have tried a number of different changes to the various gradle files but nothing has fixed this error.

What is the problem with this setup and how can it be resolved?

Thanks

in Android Studio & IntelliJ IDE, it is better to define these as "modules".

eg. with a settings.gradle alike:

include ":projectA", ":projectB"
rootProject.name = "project"

with a directory structure alike:

project/
   settings.gradle
   projectB/  # common code
       build.gradle
       src/
          test/
          debug/
          main/
             res/
             assets/
             java/
             kotlin/
                com/
                   foo/
                      bar/...


   projectA/  # android app
       build.gradle
       src/
          test/
          debug/
          main/
             res/
             assets/
             java/
             kotlin/
                com/
                   foo/
                      baz/...

when intending to use other directory-structure, one has the change the sourceSets configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM