2016-06-13 119 views
3

我對NDK不是很熟悉,我試圖用jni文件夾添加項目。我遵循Hello-JNI教程,併成功構建了apk並在Android v.5.0.2的設備上測試。但是,當我嘗試在4.4.2版本的設備上測試它時,我得到了一個UnsatisfiedLinkError,我猜它是由非JNI庫的非編譯引起的(我之前有這個錯誤,而且在應用Helloword-JNI在build.gradle)。我應該做些什麼改變才能讓APK在API> 16的任何設備上工作?提前致謝。Android - 使用NDK構建Gradle

的build.gradle(項目):

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(模塊):

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' 
} 

回答

2

我找到了答案,顯然是使用NDK時,這是一個常見的錯誤。你必須編譯最低目標而不是最後目標。我更改了build.gradle中的設置,現在它可以工作。 「ndk平臺不向後兼容,它們向前兼容!」 http://ph0b.com/android-abis-and-so-files/