Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle (android experimental plugin) ignores a project dependency

I'm using Gradle Android Experimental plugin in the following project structure:

Root Project
|-- app
|-- my-library

settings.gradle

include ':my-library', ':app'

build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.2.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

app/build.gradle

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.0"

        defaultConfig.with {
            applicationId = "a.bundle.id"
            minSdkVersion.apiLevel = 15
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = "1.0"
        }
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles += file('proguard-rules.pro')
        }
    }
}

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

my-library/build.gradle

apply plugin: 'com.android.model.library'

model {
    android {
        compileSdkVersion = 'android-23'
        buildToolsVersion = '23.0.1'

        defaultConfig.with {
            minSdkVersion.apiLevel = 15
        }
    }

    android.buildTypes {
        release {
            minifyEnabled = false
            proguardFiles += file('proguard-rules.txt')
        }
    }

    android.ndk {
        moduleName = "xxx"
        CFlags += "-I" + "${project.buildDir}".toString() + "/../src/main/jni/libabecs/include"
        CFlags += "-std=gnu99"
    }
    android.sources {
        main {
            jni {
                source {
                    srcDir 'src/main/jni/libxxx/src'
                }
            }
        }
    }
    android.productFlavors {
        create("arm") {
            ndk.abiFilters += "armeabi"
        }
        create("arm7") {
            ndk.abiFilters += "armeabi-v7a"
        }
        create("arm8") {
            ndk.abiFilters += "arm64-v8a"
        }
        create("x86") {
            ndk.abiFilters += "x86"
        }
        create("x86-64") {
            ndk.abiFilters += "x86_64"
        }
        create("mips") {
            ndk.abiFilters += "mips"
        }
        create("mips-64") {
            ndk.abiFilters += "mips64"
        }

        create("all")
    }
}

The library project builds perfectly fine. In Android Studio, it doesn't show any error. However, when attempting to build this project with Gradle, it'll only attempt to build the app project and will practically ignore the my-library dependency, rendering class not found errors.

How to solve this?

like image 615
Matoe Avatar asked Sep 22 '15 21:09

Matoe


People also ask

How do I add a dependency in Gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build. gradle file. This declares a dependency on an Android library module named "mylibrary" (this name must match the library name defined with an include: in your settings.

What is testImplementation in Gradle?

For example the testImplementation configuration extends the implementation configuration. The configuration hierarchy has a practical purpose: compiling tests requires the dependencies of the source code under test on top of the dependencies needed write the test class.

How does Gradle resolve transitive dependencies?

Transitive dependencyBy default, Gradle resolves transitive dependencies automatically. The version selection for transitive dependencies can be influenced by declaring dependency constraints.

What is flatDir in Gradle?

flatDir(configureClosure) Adds an configures a repository which will look for dependencies in a number of local directories. flatDir(args) Adds a resolver that looks into a number of directories for artifacts. The artifacts are expected to be located in the root of the specified directories.


1 Answers

Apparently it's a bug/feature not implemented in the build plugin.

I only found a dirty workaround to link the generated aar directly.

build.gradle (someappname)

repositories {
    flatDir {
        dirs '../my-library/build/outputs/aar'
    }
}

dependencies {
    compile project(':my-library')
    compile(name:'my-library-{flavour}', ext:'aar')
    //the rest
}
like image 109
blebleble Avatar answered Nov 05 '22 01:11

blebleble