I'm starting with NDK, and want to compile my first hello-world app with it.
My application is just a simple application with an Activity, and my MainActivity is in com.example.myapplication2.app
I would like to use a native method in it, and here is what I did :
MainActivity.java
#Override
protected void onCreate(Bundle savedInstanceState) {
TextView tv = new TextView(this);
tv.setText(stringFromJNI());
setContentView(tv);
}
public native String stringFromJNI();
static {
System.loadLibrary("hello-jni");
}
in my jni folder :
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := hello-jni
LOCAL_SRC_FILES := hello-jni.c
include $(BUILD_SHARED_LIBRARY)
Application.mk
APP_ABI := all
hello-jni.c
#include <string.h>
#include <jni.h>
JNIEXPORT jstring JNICALL Java_com_example_myapplication2_app_MainActivity_stringFromJNI(JNIEnv* env, jobject thiz)
{
return (*env)->NewStringUTF(env, "Hello from native code!");
}
And here, my gradle :
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
productFlavors {
x86 {
versionCode Integer.parseInt("6" + defaultConfig.versionCode)
ndk {
abiFilter "x86"
}
}
mips {
versionCode Integer.parseInt("4" + defaultConfig.versionCode)
ndk {
abiFilter "mips"
}
}
armv7 {
versionCode Integer.parseInt("2" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi-v7a"
}
}
arm {
versionCode Integer.parseInt("1" + defaultConfig.versionCode)
ndk {
abiFilter "armeabi"
}
}
fat
}
}
def getVersionCodeFromManifest() {
def manifestFile = file(android.sourceSets.main.manifest.srcFile)
def pattern = Pattern.compile("versionCode=\"(\\d+)\"")
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
return Integer.parseInt(matcher.group(1))
}
task copyNativeLibs(type: Copy, dependsOn: 'buildNative') {
// TODO fix deprecated
dependsOn 'buildNative'
from(new File('src/main/libs')) { include '**/*.so' }
into new File(buildDir, 'native-libs')
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn copyNativeLibs }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>();
pkgTask.jniFolders.add(new File(projectDir, 'native-libs'))
}
task buildNative(type: Exec) {
if (System.env.ANDROID_NDK != null) {
def ndkBuild = new File(System.env.ANDROID_NDK, 'ndk-build')
workingDir "src/main/jni"
commandLine 'cmd', '/c', '%ANDROID_NDK%\\ndk-build'
//executable ndkBuild
} else {
doLast {
println '##################'
println 'Skipping NDK build'
println 'Reason: ANDROID_NDK not set.'
println '##################'
}
}
}
task nativeLibsToJar(
type: Zip,
description: 'create a jar archive of the native libs') {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
extension 'jar'
from fileTree(dir: 'libs', include: '**/*.so')
into 'lib/'
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
When I want to run my project, I have no C error (I had before, that's why I'm sure compilation is done, and OK).
But, when I want to run the application, I have the error :
java.lang.UnsatisfiedLinkError: Native method not found: com.example.myapplication2.app.MainActivity.stringFromJNI:()Ljava/lang/String;
What I've checked is (Android NDK Native method not found error) :
com.example.myapplication2.app.MainActivity.stringFromJNI and Java_com_example_myapplication2_app_MainActivity_stringFromJNI are matching
extern "C" is not present, because when I used it, I encountered this error : Error: "expected '(' before string constant"
May you know why I encounter this error ?
Add a System.loadLibrary("hello-jni") call to your app startup. Static constructor would be a good place.
The error was in gradle file, which was not doing everything.
Here is my final .gradle file.
Before compilation, it adds three tasks before compilation to do the following :
Run the NDK build
Copy the *.so files from /src/main/libs to /build/lib
Compress the /build/lib folder into /libs/lib.jar
Requirements :
Your bin folder of JDK must be in the PATH environment variable
You must have an ANDROID_NDK environment variable with the path to your NDK (the one downloaded on Android website)
Then, it will include all the needed .so files into your application, without any ndk command needed in your gradle.
Advantage of it : One APK for all platforms
Inconvenient of it : APK bigger, because it contains .so files for all platforms.
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
ndk {
moduleName "hello-jni"
}
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [] //disable automatic ndk-build call
}
}
task buildNative(type: Exec) {
if (System.env.ANDROID_NDK != null) {
println 'Running NDK build'
workingDir "src/main"
commandLine 'cmd', '/c', '%ANDROID_NDK%/ndk-build'
} else {
doLast {
println '##################'
println 'Skipping NDK build'
println 'Reason: ANDROID_NDK not set.'
println '##################'
}
}
}
task copyNativeLibs(dependsOn:buildNative, type: Copy) {
println 'Copying *.so files from /src/main/libs to /build/lib'
from(new File('src/main/libs')) { include '**/*.so' }
into new File(buildDir, 'lib')
}
task nativeLibsToJar(dependsOn:copyNativeLibs, type: Exec, description: 'create a jar archive of the native libs') {
println 'Compressing /build/lib into /libs/lib.jar'
workingDir "build"
commandLine 'cmd', '/c', 'jar cf ../libs/lib.jar lib'
}
tasks.withType(Compile) { compileTask -> compileTask.dependsOn nativeLibsToJar }
clean.dependsOn 'cleanCopyNativeLibs'
tasks.withType(com.android.build.gradle.tasks.PackageApplication) { pkgTask ->
pkgTask.jniFolders = new HashSet<File>();
pkgTask.jniFolders.add(new File(projectDir, 'native-libs'))
}
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(dir: 'libs', include: ['*.jar'])
}
Related
I am using this https://github.com/quiet/org.quietmodem.Quiet link to transfer sound. This is a library so added it in project and in buld.gradle , i have compiled the project as :
compile project(':quiet')
My code for build.gradle(Module : quiet) is
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable = true
jniDebuggable = true
}
}
sourceSets { main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = []
} }
externalNativeBuild{
ndkBuild{
path "$projectDir/src/main/jni/Android.mk"
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
androidTestCompile 'com.android.support:support-annotations:23.0.0'
androidTestCompile 'com.android.support.test:rules:0.5'
androidTestCompile 'com.android.support.test:runner:0.5'
compile 'com.android.support:appcompat-v7:23.1.1'
}
def getNdkDir() {
if (System.env.ANDROID_NDK_ROOT != null)
return System.env.ANDROID_NDK_ROOT
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkdir = properties.getProperty('ndk.dir', null)
if (ndkdir == null)
throw new GradleException("NDK location not found. Define location with ndk.dir in the local.properties file or with an ANDROID_NDK_ROOT environment variable.")
return ndkdir
}
def getNdkBuildCmd() {
def ndkbuild = getNdkDir() + "/ndk-build"
if (Os.isFamily(Os.FAMILY_WINDOWS))
ndkbuild += ".cmd"
return ndkbuild
}
task ndkBuild(type:Exec, description: "Compile JNI Sources") {
workingDir file('src/main')
commandLine getNdkBuildCmd()
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkLibsToJar
}
task ndkLibsToJar(type: Zip, dependsOn: 'ndkBuild', description: 'Create a JAR of the native libs') {
destinationDir new File(buildDir, 'libs')
baseName 'ndk-libs'
extension 'jar'
from(new File(buildDir, 'libs')) { include '**/*.so' }
into 'lib/'
}
Now when i build my project , it throws ndk issues which is shown in the image
The issue I am facing is shown in the image
I just added a library to my project, Gear VRF, and the build.gradle file for the library is unable to find the Oculus sdk. I am getting the error "not copying Oculus files: OVR_MOBILE_SDK not found, as well as "relying on hard-coded paths and environment variables; OVR_MOBILE_SDK not found. At the bottom of the Gradle log I also get "execution failed for task framework:buildNative. User/../../Android/sdk/ndk-bundle/ndk-build finished with nonzero exit value 2.
Any help on this issue is appreciated, I have put the code for the library's build.gradle below. Thanks.
import org.apache.tools.ant.taskdefs.condition.Os
apply plugin: 'com.android.library'
android {
compileSdkVersion 21
buildToolsVersion '23.0.3'
defaultConfig {
minSdkVersion 19
targetSdkVersion 19
ndk {
moduleName "gvrf"
}
}
task copyOculusFiles(type: Copy) {
println "copying oculus binaries"
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
def oculusDir = rootProject.property("OVR_MOBILE_SDK")
copy {
from oculusDir+'/VrApi/Libs/Android/VrApi.jar'
into 'src/main/libs'
}
copy {
from oculusDir+'/VrApi/Libs/Android/armeabi-v7a/libvrapi.so'
into 'src/main/libs/armeabi-v7a'
}
copy {
from oculusDir+'/VrAppSupport/SystemUtils/Libs/Android/SystemUtils.jar'
into 'src/main/libs'
}
} else {
println "WARNING: not copying Oculus files; OVR_MOBILE_SDK not found"
}
}
task buildNative(type: Exec) {
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
} else {
println "WARNING: relying on hard-coded paths and environment variables; OVR_MOBILE_SDK not found"
}
def ndkbuild = ""
if (rootProject.hasProperty("ANDROID_NDK_HOME")) {
ndkbuild = rootProject.property("ANDROID_NDK_HOME")
ndkbuild += '/'
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkbuild += 'ndk-build.cmd'
} else {
ndkbuild += 'ndk-build'
}
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
}
commandLine '/Users/edhillon3/Library/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main').absolutePath, '-j', 16//, 'NDK_DEBUG=1'
}
buildTypes {
debug {
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'
}
releaseToGitHub {
}
}
sourceSets.main {
java.srcDirs = ['src/main/java', 'src/main/backends/oculus']
jni.srcDirs = [] // no auto generation of Android.mk
// pre-compiled libraries
jniLibs {
srcDir 'src/main/libs'
}
}
task cleanNative(type: Exec) {
def ndkbuild = ""
if (rootProject.hasProperty("ANDROID_NDK_HOME")) {
ndkbuild = rootProject.property("ANDROID_NDK_HOME")
ndkbuild += '/'
}
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
ndkbuild += 'ndk-build.cmd'
} else {
ndkbuild += 'ndk-build'
}
if (rootProject.hasProperty("OVR_MOBILE_SDK")) {
environment 'OVR_MOBILE_SDK', rootProject.property("OVR_MOBILE_SDK")
}
commandLine '/Users/edhillon3/Library/Android/sdk/ndk-bundle/ndk-build', '-C', file('src/main').absolutePath, '-j', 16, 'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative, copyOculusFiles
}
task eclipseZip(type: Zip) {
into('GearVRf/res/') {
from 'src/main/res/'
}
into('GearVRf/libs/') {
from('src/main/libs/') {
exclude 'libassimp.so'
exclude 'libjnlua.so'
}
from('build/intermediates/bundles/release/') {
include 'classes.jar'
rename('classes.jar', 'gvrf.jar')
}
}
into('GearVRf/') {
from('src/main/') {
include 'AndroidManifest.xml'
include '.project'
include '.classpath'
include 'project.properties'
}
}
into('GearVRf/java') {
from('src/main/') {
include 'donotdelete.txt'
}
}
baseName 'gvrf-for-eclipse'
}
task eclipseAssembleReleaseToGitHub() << {
println "preparing android library project for eclipse"
eclipseZip.execute()
copy {
from 'build/distributions/gvrf-for-eclipse.zip'
into 'build/outputs/aar/'
}
project.delete('build/distributions/gvrf-for-eclipse.zip')
}
task uploadToGitHub(type: Exec) {
onlyIf {
System.env['RELEASE_ID'] != null
}
onlyIf {
System.env['ACCESS_TOKEN'] != null
}
commandLine '../../tools/upload_to_github', file('build/outputs/aar/framework-releaseToGitHub.aar').absolutePath
}
uploadToGitHub.doFirst {
println('uploading to github')
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile fileTree(dir: 'src/main/libs', include: ['*.jar'])
}
assembleDebug {}.doLast {
task copyAARFiles(type: Copy) {
if (rootProject.hasProperty("LIBS_DIRECTORY")) {
println "copying aar files to the libs_directory"
def libsdirPath = projectDir.absolutePath + '/../../../' +
rootProject.property("LIBS_DIRECTORY")
def libsDir = new File(libsdirPath);
if (libsDir.exists()) {
from 'build/outputs/aar'
into libsDir
include '**/*.aar'
} else {
println "Cannot copy aar files, libs directory does not exist!"
}
}
}
assembleReleaseToGitHub {}.doLast {
println 'removing oculus binaries'
exec {
commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'libs/VrApi.jar']
}
exec {
commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'libs/SystemUtils.jar']
}
exec {
commandLine = ['zip', '-d', 'build/outputs/aar/framework-releaseToGitHub.aar', 'jni/armeabi-v7a/libvrapi.so']
}
eclipseAssembleReleaseToGitHub.execute()
uploadToGitHub.execute();
}
Find gradle.properties file and add the following:
# Un-comment and add the path to ovr directory
OVR_MOBILE_SDK=\.\.\/GearVRf\/ovr_mobile_sdk
I'm trying to convert any project tango sample app to use the new experimental gradle build system. I downloaded an app, verified that it builds and deploys, and then updated files following the experimental-gradle guide. The process was straight-forward, except for the app build.gradle file, shown below before and after my edits. I have been studying the gradle plugin, the experimental guide, etc, but haven't figured out what to do with sourceSets and the two tasks and keep getting errors. What is the right way to modify build.gradle?
Note:
I used point-cloud-jni-example, but these changes should be the same for any project tango app, because the relevant files are essentially identical for all the tango sample apps.
stock app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.projecttango.experiments.nativepointcloud"
minSdkVersion 19
targetSdkVersion 19
}
sourceSets.main {
jniLibs.srcDir 'src/main/libs'
jni.srcDirs = [];
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build"
commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
modified app build.gradle:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 19
buildToolsVersion = "23.0.0"
defaultConfig.with {
applicationId = "com.projecttango.experiments.nativepointcloud"
minSdkVersion.apiLevel = 19
targetSdkVersion.apiLevel = 19
}
android.sourceSets.main {
jniLibs.srcDir = 'src/main/libs'
jni.srcDirs = [];
}
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
ndk.with {
debuggable = true
}
}
}
android.ndk {
moduleName = "point_cloud_jni_example"
ldLibs += ["android", "EGL", "GLESv2", "dl", "log"]
stl = "stlport_static"
}
}
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn ndkBuild
}
task ndkBuild(type: Exec) {
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build.cmd"
commandLine ndkbuild, '-C', file('src/main/jni').absolutePath
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
I am not sure if it resolves all issues.
In any case, you have to change your buildTypes block using:
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
Also use the last version 0.2.1
I am integrating opencv library with my project. I've successfully configured NDK using experimental gradle plugin. But getting error with Opencv. Here is the error showing in my cpp file.
My build.gradle is:
apply plugin: 'com.android.model.application'
model {
android {
compileSdkVersion = 23
buildToolsVersion = "23.0.0"
defaultConfig.with {
applicationId = "com.legalplex.dharani.android"
minSdkVersion.apiLevel = 14
targetSdkVersion.apiLevel = 23
buildConfigFields.with {
create() {
type = "int"
name = "VALUE"
value = "1"
}
}
}
}
android.ndk {
moduleName = "document_scanner"
cppFlags += "-fno-rtti"
cppFlags += "-fno-exceptions"
ldLibs = ["android", "log"]
stl ="gnustl_shared"
}
android.buildTypes {
release {
minifyEnabled = false
proguardFiles += file('proguard-rules.pro')
}
}
android.productFlavors {
// for detailed abiFilter descriptions, refer to "Supported ABIs" #
// https://developer.android.com/ndk/guides/abis.html#sa
create("arm") {
ndk.abiFilters += "armeabi"
}
create("arm7") {
ndk.abiFilters += "armeabi-v7a"
}
create("arm8") {
ndk.abiFilters += "arm64-v8a"
}
create("x86") {
ndk.abiFilters += "x86"
}
create("x86-64") {
ndk.abiFilters += "x86_64"
}
create("mips") {
ndk.abiFilters += "mips"
}
create("mips-64") {
ndk.abiFilters += "mips64"
}
// To include all cpu architectures, leaves abiFilters empty
create("all")
}
}
dependencies {
compile 'com.android.support:support-v4:19.1.0'
compile project(':openCVLibrary')
}
Why it is showing error at opencv includes even after adding module dependency in my gradle file. Please help me out. How to configure my build.gradle file to activate our own Android.mk. Here is my Android.mk file:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
include OpenCV-2.4.10-android-sdk\sdk\native\jni\OpenCV.mk
OPENCV_INSTALL_MODULES := on
LOCAL_MODULE := document_scanner
LOCAL_SRC_FILES := jni_part.cpp
LOCAL_C_INCLUDES := OpenCV-2.4.10-android-sdk\sdk\native\jni\include
OPENCV_LIB_TYPE:=STATIC
LOCAL_LDLIBS += -llog
include $(BUILD_SHARED_LIBRARY)
You should a) enable ndk-build, and b) disable ndk plugin. Code below is tuned for Mac, on Windows you need ndk-build.cmd:
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build"
}
buildNative.onlyIf {
def ndkDir = android.ndkDirectory
file("$ndkDir/ndk-build").exists()
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = android.ndkDirectory
commandLine "$ndkDir/ndk-build", 'clean'
}
cleanNative.onlyIf {
def ndkDir = android.ndkDirectory
file("$ndkDir/ndk-build").exists()
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
defaultConfig.ndk {
moduleName "pexeso-android-mobile"
}
tasks.all {
task -> if (task.name.contains('compileDebugNdk') || task.name.contains('compileReleaseNdk')) task.enabled = false
}
UPDATE similar approach works with the experimental plugin, see define LOCAL_SRC_FILES in ndk{} DSL.
I recently migrated from Android Studio 0.9+ to 1.+ where I had to change my gradle version from 0.12.+ to 1.1.+ for IDE requirements. My app and jni was running
My build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "..."
minSdkVersion 17
targetSdkVersion 19
versionCode 1
versionName "1.0"
ndk {
moduleName "behagcoder"
cFlags "-DHAVE_CONFIG_H -DFPM_ARM -ffast-math -O3" // Define some macros
ldLibs "android", "log" // Link with these libraries!
stl "stlport_shared"
}
}
//flavorDimensions "abi"
productFlavors {
x86 {
flavorDimension "x86"
ndk {
abiFilter "x86"
}
}
mips {
ndk {
abiFilter "mips"
}
}
arm {
flavorDimension "abi"
ndk {
abiFilter "armeabi"
moduleName "behagcoder"
cFlags "-DHAVE_CONFIG_H -DFPM_ARM -ffast-math -O3" // Define some macros
ldLibs "android", "log" // Link with these libraries!
stl "stlport_shared"
}
}
armv7 {
flavorDimension "abi"
ndk {
abiFilter "armeabi-v7a"
}
}
}
sourceSets.main {
jni.srcDirs = [] // This prevents the auto generation of Android.mk
jniLibs.srcDir 'src/main/libs'
}
task buildNative(type: Exec, description: 'Compile JNI source via NDK') {
def ndkDir = "/home/shad/Downloads/NDK/android-ndk-r10d"
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'-j', Runtime.runtime.availableProcessors(),
'all',
'NDK_DEBUG=1'
}
task cleanNative(type: Exec, description: 'Clean JNI object files') {
def ndkDir = "/home/shad/Downloads/NDK/android-ndk-r10d"
commandLine "$ndkDir/ndk-build",
'-C', file('src/main/jni').absolutePath,
'clean'
}
clean.dependsOn 'cleanNative'
tasks.withType(JavaCompile) {
compileTask -> compileTask.dependsOn buildNative
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
...
}
My Android.mk file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := behagcoder
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES := NativeSRLDecoder.cpp bhg/bit.c bhg/decoder.c bhg/fixed.c bhg/frame.c bhg/huffman.c bhg/layer3.c bhg/stream.c bhg/synth.c bhg/timer.c bhg/version.c
LOCAL_CFLAGS := -DHAVE_CONFIG_H -DFPM_ARM -ffast-math -O3
# for logging
LOCAL_LDLIBS += -llog
# for local asset manger
#LOCAL_LDLIBS += -landroid
include $(BUILD_SHARED_LIBRARY)
Error:
java.lang.UnsatisfiedLinkError: Native method not found:
I am new in Android development, I also want to build the app for multiple processor type as x86,mips etc. Thanks in advance