简体   繁体   中英

Using NDK in Android Studio with outside C++ sources

So far into my foray with using NDK with Android Studio, I've written the Java Wrapper, generated the header file, and filled in some functions in the corresponding c++ file in JNI folder.

What I'm trying to do right now is to get a simple build going so that I can verify things work. My project relies on some c++ source files located outside of my entire android project. Do I build those source files somehow from within Android? How do I access them? Is there anything I need to do from Gradle?

I'm incredibly new to building projects with across multiple sources, so I have no idea what to do. Apologies if the questions don't make sense. Any help is greatly appreciated (:

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

user ph0b has many SO posts on NDK.

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

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

After the AS import is done, the NDK stuff will be at:

./root/module/src/main/jni

Java packages will be at

./root/module/src/main/java

Verify that the import to AS did NOT do auto-update on the "Android.mk" file that you input to the import process because you will need it and not any auto gen'd file from AS.

In AS gradle.build file ...

make sure

buildToolsVersion "19.1.0"

and add following as per the earlier 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
}

You then will have option of doing CLI NDK build in the jni folder, OR just using gradle integrated build that will use the "ndkBuild" task from gradle file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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