简体   繁体   English

Android - 使用NDK构建Gradle

[英]Android - Gradle build with NDK

I'm not very familiar with NDK and I'm trying to add a project with a jni folder. 我对NDK不太熟悉,我正在尝试添加一个带有jni文件夹的项目。 I followed the Hello-JNI tutorial and I successfully built the apk and test on a device with Android v.5.0.2. 我按照Hello-JNI教程进行了操作,并成功构建了apk并在使用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). 但是当我尝试在4.4.2版本的设备上测试它时,我得到一个UnsatisfiedLinkError,我猜它是由非编译的JNI库造成的(我之前有过这个错误,而不是在应用Helloword-JNI的设置之后在build.gradle)。 What changes should I make to make the APK working on any device with API>16? 我应该做些什么更改才能使APK在任何API> 16的设备上运行? Thanks in advance. 提前致谢。

build.gradle(project) : 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 (module): 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'
}

I found the answer, apparently it's a common mistake when using ndk. 我找到了答案,显然这是使用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. 我在build.gradle中更改了设置,现在它可以工作了。 "ndk platforms aren't backward compatible, they're forward compatible!" “ndk平台不向后兼容,它们是向前兼容的!” http://ph0b.com/android-abis-and-so-files/ http://ph0b.com/android-abis-and-so-files/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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