W
W
wutiarn2014-08-09 21:51:41
Java
wutiarn, 2014-08-09 21:51:41

How to set up gradle to work with multiple modules?

Good afternoon. Recently I decided to deal with Android and write one application for myself. And in the process, it became necessary to connect this library .
As you can see, this is not just a jar, but a full-fledged grandle module. In addition, this library depends on another - Silk. What should I do. I started trying to put it on. Well, as you may have guessed, it did not start with a half-kick. First I had to deal with such things as:
apply plugin: 'com.android.library'
or
applicationId "com.afollestad.cardsui"
in build.gradle. It ended up turning into this:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
}

Idea picked up all this, compiled it. I was overjoyed, but no. It turns out that other modules (in the main library / my application) do not resolve imports (both the idea and the compiler swear) from Silk. Moreover, with the dependencies of the module that tries to access Silk, everything is fine:
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.9.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.+'
    compile project(':slik')
}

The error is thrown by the Java compiler itself. Gradle does not swear at this import. So he will resolve.
Everything that came to my mind was done with the Slik module. Clean and subsequent Compile run without errors.
In general, I've been struggling with this for the fifth hour, probably. It's scary enough. Does anyone have any ideas?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wutiarn, 2014-08-10
@wutiarn

So. Clear.
After a day of googling, I found the cause of my troubles. The build.gradle of all android libraries should use the android-library plugin, not android.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question