简体   繁体   中英

Android Studio / Gradle can't find imported component

A project I'm developing at work has the following component imports going on. Names changed to protect proprietary info.

~/.gradle/gradle.properties

lib_includedLibrary=/home/myuser/includedLibrary/lib_includedLibrary

Project's settings.gradle

include 'includedLibrary'
project (':includedLibrary').projectDir = new File(lib_includedLibrary)

include ':myAppModule'

In the module's build.gradle

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile project(':includedLibrary')
}

Problem

Android Studio doesn't seem to be finding my gradle.properties file. No matter what I do to point it at this dependency, it can't find it.

Gradle 'MyProject' project refresh failed
    Error: Could not find property 'lib_includedLibrary' on settings 'MyProject'.

When it fails in this way, the project's settings.gradle gets marked up in the IDE as if none of the syntax or symbols is correct.

Cannot resolve symbol 'include'

I have already verified that it's really at that location, and I've even opened the library (we develop it, too) in AS and it opens successfully.

This same setup works fine on my work laptop (running AS 1.5.1) but fails on the development VM I set up at home (running AS 2.1).

I have been beating my head against this for a couple of days now and still can't figure out why it works in one place and not in another.

Anyone have any ideas of "gotchas" to check, or environmental differences that might be a factor here?

So I finally figured it out and now I just feel stupid.

I had installed a separate Gradle instance and had put its location into the "Service directory path" configuration screen in Android Studio. When comparing to my working instance on my work laptop, this was still set to /home/myuser/.gradle . Changing this back to /home/myuser/.gradle on the non-working VM instance caused it to pick up the gradle.properties file properly and import the dependency.

Sigh.

please try to import you Library the Android studio "way" :

go to File > New > Import Module >>> select your Library folder from your Computer and name it includedLibrary

keep compile project(':includedLibrary') in you dependencies

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