简体   繁体   中英

JNI build gradle fails on finding ndk directory

I set ndk.dir in my local.properties file. But, when grade builds, this line

task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
        def ndkDir = android.ndkDirectory

throws an error saying that android.ndkDirectory is not set. How can I prevent myself to hard code the absolute path of ndkDirectory ?

This property has changed its name several times since NDK support was introduced. I am not sure it has stabilized now with the "experimental" plugin.

Therefore I would recommend a version independent approach, invented by Riccardo Ciovati in How do i read properties defined in local.properties in build.gradle :

Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkDir = properties.getProperty('ndk.dir')

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