Reputation: 4802
This project in compound of the 3 modules (app, datecs e volley). The datecs
module is an interface between the library libs/com.datecs.api.jar
. The issue is that the library classes/package isn't visible in the app module.
Here are the gradle files:
project.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
app.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 16
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
checkReleaseBuilds false
abortOnError false
}
}
allprojects {
repositories {
google()
jcenter()
}
}
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
}
dependencies {
implementation files('libs/gson-2.3.1.jar')
implementation project(':volley')
implementation 'com.android.support:support-v4:21.0.3'
implementation 'com.android.support:appcompat-v7:21.0.3'
implementation project(':datecs')
}
datecs.gradle
apply plugin: 'com.android.library'
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
android {
compileSdkVersion 21
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 16
targetSdkVersion 21
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'com.android.support:support-v4:21.0.3'
implementation 'com.android.support:appcompat-v7:21.0.3'
testImplementation 'junit:junit:4.12'
implementation files('libs/com.datecs.api.jar')
}
allprojects {
repositories {
google()
jcenter()
}
}
How can I make the library classes accessible in the app module?
Upvotes: 1
Views: 636
Reputation: 13019
Since I don't have access to your specific library (datecs), I tested with an app module and a library module where the app module needs to "import" the 'com.android.support:appcompat-v7:28.0.0'
dependency from the library module.
Using api
instead of implementation
did the trick for me.
Dependencies closure in build.gradle of the app module:
dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation project(':mytestlibrary')
}
Dependencies closure in build.gradle of the library module:
dependencies {
api 'com.android.support:appcompat-v7:28.0.0'
}
See also the documentation on Dependency Configurations for api
:
Gradle adds the dependency to the compile classpath and build output. When a module includes an api dependency, it's letting Gradle know that the module wants to transitively export that dependency to other modules, so that it's available to them at both runtime and compile time.
Upvotes: 2