Adding android project dependency fails

ScottF :

I am trying to add a dependency to my Android gradle project, and keep getting the following error when building...

A problem occurred evaluating project ':app'.
> Project with path 'externalproject' could not be found in project ':app'.

I have an external java gradle project that I would like to be built before my android app builds.

I have added this new project to my settings.gradle as follows...

include ':app' , ":externalproject"
project(':externalproject').projectDir = new File(settingsDir, '../externalproject')

rootProject.name = 'mayapp'

My build.gradle in the app folder looks as follows...

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.androidapp1"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:appcompat-v7:26.0.0'
    compile project('externalproject')
}
shizhen :

change below

compile project('externalproject')

to

compile project(':externalproject') 

Or better to use implementation

implementation project(':externalproject')

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=101539&siteId=1