簡體   English   中英

如何在Android Studio中使用Gradle訪問依賴項的依賴項?

[英]How to access dependencies of dependencies with gradle in android studio?

我在這里想念什么嗎? 我正在使用android studio。 我將使用共享的代碼庫開發兩個應用程序,因此我在android studio項目中制作了三個模塊。 一個模塊是帶有共享代碼的庫項目,另外兩個是應用程序。 這是一個應用程序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'])
}

這是共享模塊的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'
}

我的期望是我的應用程序應該可以訪問共享代碼模塊的依賴項(例如'com.android.support:appcompat-v7:26.1.0' )。 錯了嗎 我找不到任何將這些依賴關系傳遞給依賴應用程序的方法。

答案是在共享模塊的'build.gradle依賴項中使用api而非implementation

即。 我想要api 'com.android.support:appcompat-v7:26.1.0'而不是implementation 'com.android.support:appcompat-v7:26.1.0'

由Jaydip Kalani的評論提供,以及如何共享Android模塊之間的依賴關系

但是據我所知有是沒有這樣的事情testApi更換testImplementation

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM