Reputation: 371
Sorry this is my first time facing this kind of issue, i have no idea about what to do.
I am working on a project that contains two java Modules ( Module1 , Module2)
build.gardle for main project:
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig {
applicationId "com.client.howara"
minSdkVersion 24
targetSdkVersion 29
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation project(':Module1')
implementation project(':Module2')
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.13'
implementation .....
}
build.gardle for Module1:
apply plugin: 'java'
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':Module2')
}
build.gradle for Module2:
apply plugin: 'java'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
}
When i try to add an android package to Module1, i get the following error:
Example:
error: package android.os does not exist
import android.os.Build;
Did i need to modify module1 build.gradle? if yes how ?
Thank you for your help and sorry for my ignorance
Upvotes: 0
Views: 631
Reputation: 1234
You have defined module1
as a java
library. So importing any android
artifact will be prohibited to keep it a java
library.
If you really want to add android
artifacts in module1
, then you need to convert module1
to an android
library by doing the following:
// Remove this
apply plugin: 'java'
// Instead add this
apply plugin: 'com.android.library'
I think what you are doing is fine, however you are not able to state your problem efficiently.
What is happening currently in your Gradle
BuildScripts
is this:
Your App
depends on Module1
and Module2
, your Module1
depends on Module2
and your Module2
doesn't depends on either app
or Module1
.
App
/ \
Module1 \
\ \
\ \
\ \
Module2
Upvotes: 3