简体   繁体   中英

Android - Gradle build with NDK

I'm not very familiar with NDK and I'm trying to add a project with a jni folder. I followed the Hello-JNI tutorial and I successfully built the apk and test on a device with Android v.5.0.2. But when I try to test it on a device with a 4.4.2 version I get a UnsatisfiedLinkError which I guess it caused by the non-compilation of JNI libs (I had this error before and not anymore after applying the settings of Helloword-JNI in build.gradle). What changes should I make to make the APK working on any device with API>16? Thanks in advance.

build.gradle(project) :

buildscript {
repositories {
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle-experimental:0.7.2'
}
}

allprojects {
     repositories {
         jcenter()
    }
}

task clean(type: Delete) {
delete rootProject.buildDir
}

build.gradle (module):

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

model {
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.name.appname"
        minSdkVersion.apiLevel 16
        targetSdkVersion.apiLevel 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles.add(file('proguard-android.txt'))
        }
    }
    ndk {
        moduleName "module 1.0"
    }
}
}

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

I found the answer, apparently it's a common mistake when using ndk. You have to compile with the minimum target instead of the last target. I changed the setting in build.gradle and now it works. "ndk platforms aren't backward compatible, they're forward compatible!" http://ph0b.com/android-abis-and-so-files/

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