How to define multiple modules with the new NDK gradle constructor?

I am trying to learn and try to use the new ndk build support based on Android Studio gradle.

I find it difficult to determine how to define the PREBUILT_SHARED_LIBRARY ndk modules so that my main ndk module can use it. I have this setting using Android.mk but can't figure out how to convert it to gradle.:/

// SHARED LIBRARY
android.ndk {
    moduleName = "skia_android"
    cppFlags += "-I${file("src/main/jni/skia/skia/out/config/android-nexus_4/Debug/lib/libskia_android.so")}".toString()
    cppFlags += "-I${file("src/main/jni/skia/skia/include/core")}".toString()
    cppFlags += "-I${file("src/main/jni/skia/skia/include/utils")}".toString()
    cppFlags += "-I${file("src/main/jni/skia/skia/include/gpu")}".toString()
    cppFlags += "-I${file("src/main/jni/skia/skia/include/private")}".toString()
    ldLibs += ["EGL", "GLESv2"]
    stl    = "c++_static"
}

// MAIN LIBRARY
android.ndk {
    moduleName = "smasher"
    cppFlags += "-I${file("src/main/jni/smasher/include")}".toString()
    cppFlags += "-I${file("src/main/jni/smasher/src")}".toString()
    cppFlags += "-I${file("src/main/jni/smasher")}".toString()
    ldLibs += ["skia_android", "log", "android", "EGL", "GLESv2"]
    stl    = "c++_static"
    abiFilter "armeabi-v7a"
}
+4
source share
2 answers

Update (February '16): an experimental plugin allows you to create your own modules! Not basically yet.


, gradle. , . Android.mk, .

, NDK buildNative:

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkBuild = properties.getProperty('ndk.dir') + '/ndk-build'

import org.apache.tools.ant.taskdefs.condition.Os
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
    ndkBuild += '.cmd'
}

task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
    commandLine '$ndkBuild', 'NDK_PROJECT_PATH="$jniSrc/..'
}

task cleanNative(type: Exec, description: 'Clean JNI object files') {
    commandLine '$ndkBuild', 'clean', 'NDK_PROJECT_PATH="$jniSrc/..'
}

clean.dependsOn 'cleanNative'

tasks.all {
    task ->
        if (task.name.startsWith('compile') && task.name.contains('MainC')) {
            task.enabled = false
        }
        if (task.name.startsWith('link')) {
            task.enabled = false
        }
        if (task.name.endsWith("SharedLibrary") ) {
            task.dependsOn buildNative
        }
}
+1

. , , ( , gradle).

http://tools.android.com/tech-docs/new-build-system/gradle-experimental

root
+ lib -> apply plugin: 'com.android.model.native'
+ app -> apply plugin: 'com.android.model.application'

/build.gradle

model {
    android.sources {
        main {
            jni {
                dependencies {
                    project ":lib" 
                    // optional: 
                    // buildType "debug" productFlavor "flavor" linkage "static"
                }
            }
        }
    }
}
0

Source: https://habr.com/ru/post/1607545/


All Articles