Using NDK in Android Studio with external C ++ sources

So far in my foray using the NDK with Android Studio, I've written a Java Wrapper, generated a header file, and filled in some functionality in the appropriate C ++ file in the JNI folder.

What I'm trying to do right now is to do a simple assembly so I can check that everything works. My project is based on some C ++ source files located outside of my entire Android project. Am I building these source files somehow from Android? How can I access them? Is there anything I need to do from Gradle?

I'm incredibly new to creating multi-source projects, so I have no idea what to do. Sorry if the questions don't make sense. Any help is greatly appreciated (:

+3


source to share


1 answer


http://ph0b.com/android-studio-gradle-and-ndk-integration/

User ph0b has many SO posts on the NDK.

read this person various posts on subj (AS + NDK)

IMO. You can follow the "import NDK proj" strategy from src dirs used for eclipse / NDK android project and AS 0.8. + you get almost all the way there with the usual File / Import Project dialog.

After the AS import is complete, the NDK material will look like this:

./root/module/SRC/Main/JNI

Java packages will be in

./root/module/SRC/Main/Java



Make sure that the import to AS is NOT auto-updated in the Android.mk file you enter into the import process, because you will need it, not the auto gen'd file from AS.

In the AS gradle.build file ...

Make sure that

buildToolsVersion "19.1.0"

and add the following according to the previous links:

   ndk {
        moduleName "audioboo-ogg"
    }
}
flavorDimensions "abi"
productFlavors {
    x86 {
        ndk {
            abiFilter "x86"
        }
    }
    armv7 {
        ndk {
            abiFilter "armeabi-v7a"
        }
    }
}
sourceSets {
    main {
        jni.srcDirs = [] /*disable automatic ndk-build call */
    }

}

task ndkBuild(type: Exec) {
    commandLine '$NDK_HOME/android-ndk-r9[a-z]/ndk-build', '-C', file('src/main/jni').absolutePath
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn ndkBuild
}

      

Then you will have the option to build the CLI NDK in the jni folder or simply with the built-in gradle build which will use the "ndkBuild" task from the gradle file.

+4


source







All Articles