Java 如何在android studio中使用gradle访问依赖项的依赖项?
我是不是遗漏了什么?我正在使用android studio。我将开发两个具有共享代码库的应用程序,因此我在android studio项目中制作了三个模块。一个模块是带有共享代码的库项目,另外两个是应用程序。这是一个应用程序Java 如何在android studio中使用gradle访问依赖项的依赖项?,java,android,gradle,Java,Android,Gradle,我是不是遗漏了什么?我正在使用android studio。我将开发两个具有共享代码库的应用程序,因此我在android studio项目中制作了三个模块。一个模块是带有共享代码的库项目,另外两个是应用程序。这是一个应用程序build.gradle apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "omitte
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'])
}
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'
}
这是共享模块的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'])
}
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
而不是实现
我想要api'com.android.support:appcompat-v7:26.1.0'
而不是implementation'com.android.support:appcompat-v7:26.1.0'
Jaydip Kalani的评论和
然而,据我所知,没有什么东西可以代替testImplementation
检查this@JaydipKalkani哦,天哪,我不敢相信我在谷歌搜索的时候错过了这个。非常感谢。很高兴听到这对你有帮助。:)