exportedHeaders DSL does not seem to include the h

2019-07-24 13:36发布

I am trying to make use of the "Multiple NDK Projects" feature of the experimental gradle plugin. I am using Android Studio 2.1 and gradle plugin 0.7.0 stable. The blog seems to say that the header files specified in the exportedHeaders section of the native library will be included during compilation

exportedHeaders {
                        srcDir "src"
                    }

This does not seem to work for me. Say for example I have the following folder structure, I would expect Addition.h to be available in native.cpp, ie I should be able to say

#include <Addition.h>

but only

#include "../../../../../../../Framework/Addition/src/Addition.h" 

works. Adding cppFlags to include the headers makes no difference.

Folder structure

Here's how some relevant files look for an example project. The example project module "app" depends on a native library module "addition" to add 2 numbers. The native library uses the new native plugin.

settings.gradle

include ':app'
include ':Addition'
project (":Addition").projectDir = new File("../../../Framework/Addition")

gradle-wrapper.properties

#Mon Dec 28 10:00:20 PST 2015
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip

build.gradle (:app)

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

model {
    android {
        compileSdkVersion 23
        buildToolsVersion "23.0.2"

        ndk {
            moduleName = 'native'
            platformVersion = 17
            toolchain "clang"
            cppFlags.addAll(['-I' + file('src/main/jni'),
                             '-I'  + file('../../../Framework/Addition')])
        }

        sources {
            main {
                jni {
                    dependencies {
                        project ':Addition' linkage 'static'
                    }
                }
            }
        }

        defaultConfig {
            applicationId "com.harkish.nativepluginexample"
            minSdkVersion.apiLevel 21
            targetSdkVersion.apiLevel 23
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
            }
        }
    }
}

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

build.gradle (:Addition)

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

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = '23.0.2'

        defaultConfig {
            minSdkVersion.apiLevel = 21
            targetSdkVersion.apiLevel = 23
            versionCode = 1
            versionName = '1.0'
        }
        ndk {
            moduleName = 'addition'
        }
        sources {
            main {
                jni {
                    source {
                        srcDir "src"
                    }
                    exportedHeaders {
                        srcDir "src"
                    }
                }
            }
        }
    }
}

Anyone solved this problem? ideas?

0条回答
登录 后发表回答