maxbfuer
maxbfuer

Reputation: 859

How to access dependencies of dependencies with gradle in android studio?

Am I missing something here? I'm using android studio. I will be developing two apps with a shared code base, so I made three modules in my android studio project. One module is a library project with shared code, and the other two are apps. This is an app build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "omitted"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation project(':lib')
    implementation fileTree(dir: 'libs', include: ['*.jar'])
}

this is the shared module's build.gradle

apply plugin: 'com.android.library'

android {
    compileSdkVersion 26
    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

My expectation is that my app should have access to the dependencies of the shared code module (for example 'com.android.support:appcompat-v7:26.1.0'). Is this wrong? I cannot find any way to pass on these dependencies to the dependent app.

Upvotes: 2

Views: 1293

Answers (1)

maxbfuer
maxbfuer

Reputation: 859

The answer is to use api instead of implementation in my shared module's 'build.gradle dependencies.

ie. I want api 'com.android.support:appcompat-v7:26.1.0' instead of implementation 'com.android.support:appcompat-v7:26.1.0'

Courtesey of Jaydip Kalani's comment and How do I share dependencies between Android modules

However as far as I'm aware there is no such thing as testApi to replace testImplementation.

Upvotes: 3

Related Questions