简体   繁体   English

Gradle(android实验插件)忽略项目依赖

[英]Gradle (android experimental plugin) ignores a project dependency

I'm using Gradle Android Experimental plugin in the following project structure: 我在以下项目结构中使用Gradle Android Experimental插件:

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

settings.gradle settings.gradle

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

build.gradle 的build.gradle

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

allprojects {
    repositories {
        jcenter()
    }
}

app/build.gradle 应用程序/的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 我的图书馆/的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. 在Android Studio中,它不会显示任何错误。 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. 但是,当尝试使用Gradle构建此项目时,它将仅尝试构建app项目,并且实际上将忽略my-library依赖项,从而使类未找到错误。

How to solve this? 怎么解决这个?

Apparently it's a bug/feature not implemented in the build plugin. 显然,这是一个未在构建插件中实现的错误/功能。

I only found a dirty workaround to link the generated aar directly. 我只找到了一个肮脏的解决方法来直接链接生成的aar。

build.gradle (someappname) 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
}

I faced the exact same problem, and finally found out that the path to the ndk sources in my library project was wrong, and that I had to add: 我遇到了完全相同的问题,最后发现我的库项目中的ndk源路径是错误的,我必须添加:

dependencies {
    project ":myHybridLib"
}

in the android.sources.main.jni of the main project. 在主项目的android.sources.main.jni中。

After correcting those errors, everything compiles just fine. 在纠正这些错误后,一切都编译得很好。

change my_library/build.gradle to something like this : my_library/build.gradle更改为以下内容:

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

model {

android {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.1"

    defaultConfig.with {
        minSdkVersion.apiLevel = 15
        targetSdkVersion.apiLevel = 23
    }
}

android.ndk {
    moduleName = "FlatBuffersParser"
    cppFlags.addAll(['-std=c++11', '-fexceptions', '-Wall', '-Wno-literal-suffix'])
    cppFlags.add("-I${file("src/main/jni/flatbufferslib")}".toString())
    ldLibs.addAll(["android", "log"])
    stl = "gnustl_shared"
   }
}

for more info about structure see this project in github, it uses experimental v0.4.0 in two android module : 有关结构的更多信息,请参阅github中的这个项目,它在两个android模块中使用实验性的v0.4.0:

https://github.com/frogermcs/FlatBuffs https://github.com/frogermcs/FlatBuffs

Faced the same issue. 面对同样的问题。 I workaround it by renaming app submodule to something else. 我通过将app子模块重命名为其他东西来解决它。 So the project structure will be 所以项目结构将是

Root Project
|-- someappname
|-- my-library

settings.gradle : settings.gradle

include ':my-library', ':someappname'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM