Gradle experimental android library module depende

2019-07-17 18:43发布

I am using the gradle experimental plugin 0.7.3. In my project i have several native modules which are statically linked to my android library module where a shared library is built from them and used in the library java code. The library module is then used as a dependency for an app. The dependency is added like this:

dependencies {
    compile project(path: ':library-module')
}

When i run the app with android studio it fails because the methods of the library are not found. I checked it in the gradle console and it only builds the app itself without building the library as it only executes ':app-module:assembleArm7Debug'.

I guess this is a bug of the experimental plugin since it worked fine with the non-experimental version. I already tried a workaround and added the following to the app build.gradle:

project.afterEvaluate{
    assembleArm7Debug.dependsOn(':library-module:assembleArm7Debug')
}

but this only resulted in a gradle error saying the app does not have the property assembleArm7Debug even though i can call it with ./gradlew. Are there any other possible ways to make this work.

EDIT: The library module looks like this:

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

model {
    android {
        compileSdkVersion 24
        buildToolsVersion "24.0.0"

        defaultConfig {
            minSdkVersion.apiLevel 19
            targetSdkVersion.apiLevel 24
            versionCode 1
            versionName "1.0.0"
        }

        ndk {
            moduleName = 'android_lib'
            toolchain = 'gcc'
            stl "gnustl_static"
            platformVersion "android-19"

            ldLibs.addAll(['android_libs'])

            cppFlags.addAll([
                    'more_flags',

                    "-I" + "includes",
            ])
        }

        buildTypes {
            release {
                minifyEnabled false
            }
            debug {
                ndk {
                    debuggable true
                }
                minifyEnabled false
            }
        }

        abis {
            create("armeabi-v7a") {
                CFlags.addAll([
                        'some_flags'
                ])
            }
            create("arm64-v8a") {
                CFlags.addAll([
                        'some_flags'
                ])
            }
            create("x86") {
            }
        }

        sources {
            main {
                java {
                    source {
                        srcDir "/src/main/java"
                    }
                }
                res {
                    source {
                        srcDir "res"
                    }
                }
                assets {
                    source {
                        srcDir "assets"
                    }
                }
                jni {
                    source {
                        srcDirs += [
                                "src_dirs"
                                ]
                    }

                    dependencies {
                        project ":native-lib" linkage "static" buildType "debug"

                        library "prebuilt_lib" linkage "static"
                    }

                    exportedHeaders {
                        srcDirs = [
                                "src_dirs"
                        ]
                    }
                }

            }
        }

        productFlavors {
            create("arm7") {
                ndk.abiFilters.add("armeabi-v7a")
            }
            create("arm8") {
                ndk.abiFilters.add("arm64-v8a")
            }
            create("x86") {
                ndk.abiFilters.add("x86")
            }
        }
    }

    repositories {
        libs(PrebuiltLibraries) {
            prebuilt_lib {
                binaries.withType(StaticLibraryBinary) {
                    staticLibraryFile = file("/lib/${targetPlatform.getName()}/liblib.a")
                }
            }
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-annotations:24.1.1'
}

Edit: The issue seems to be caused by the product flavors which could not be resolved by the app module correctly. My current workaround for this is to remove the product flavors for this module and just add ndk.abiFilters for all my architectures. It resolves the dependency issue at the cost of more compile time.

0条回答
登录 后发表回答