1

I have some application modules who's sharing some same content (Adapters,Layouts,etc..) when i include the shared module dependency i get the error below

gradle error

Notice: that i want my shared module to be application type in order to put in it some shared layout resources

shared build.gradle

apply plugin: 'com.android.application'

android  {
compileSdkVersion 27
buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.hassan.shared"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
    implementation 'com.android.support:appcompat-v7:27.0.2'
}

adminbuild.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '26.0.2'

defaultConfig {
    applicationId "com.hassan.admin"
    minSdkVersion 18
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    vectorDrawables.useSupportLibrary = true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:27.0.2'
implementation 'com.android.support:design:27.0.2'
implementation 'com.android.support:recyclerview-v7:27.0.2'
implementation 'com.android.support.constraint:constraint-layout:1.1.0-beta3'
implementation 'com.google.code.gson:gson:2.8.1'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.0'
implementation project(':shared')
 }

project build.gradle

buildscript {
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
    classpath 'com.android.databinding:dataBinder:1.0-rc1'
    classpath 'com.google.gms:google-services:3.1.1'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    jcenter()

 maven {
        url "https://maven.google.com"
    }
    google()
}
}

settings.gradle

include ':shared', ':admin'
Hassan
  • 407
  • 5
  • 22

2 Answers2

0

compileSdkVersion and buildToolsVersion should be of same version

try changing like this

compileSdkVersion 27
buildToolsVersion '27.0.0'
  • thank you i updated my `build tools` and also `platform-tools` to the latest but the problem still
    Note: its not necessary that `complieSdkVrersion` and `buildToolsVresion` to be the same lint didn't tell about that but i give it a shot
    – Hassan Dec 28 '17 at 12:02
0

i solved it, there are three types of android modules :

  • Application module : contains code, resources and the build produces .Apk file
  • Android Library : contains code, resources and the build produces .AAR file
  • Java Library : contains code and the build produces .JAR file

    Application module can depend on the other two, i converted my shared module to android library type that solved it.
Hassan
  • 407
  • 5
  • 22