I ran into problem when I had multiple C files in my project. Single C file was OK for me.
I was getting undefined reference error while doing this.
Then I found out the solution after a lot of search in google.

You can check this post before going through this post.
This is about setting up NDK in MAC.
Starting with NDK for Android – A Simple example. OR How to run a C code in android?

I have to make the change in the Android.mk file to include other files to compile.

This is the content of my Android.mk file

LOCAL_PATH := $(call my-dir)
 
include $(CLEAR_VARS)
 
LOCAL_LDLIBS := -llog
 
LOCAL_MODULE    := ndksetup
LOCAL_SRC_FILES := native.c test.c test_2.c
 
include $(BUILD_SHARED_LIBRARY)

Here is my native.c code in which I am including those two files test.c and test2.c


#include <jni.h>
#include <string.h>
#include <android/log.h>

// my test file 
#include "test.h"
#include "test_2.h"

#define DEBUG_TAG "NDKSetupActivity"
 
void Java_com_ndksetup_NDKSetupActivity_printLog(JNIEnv * env, jobject this, jstring logString)
{
    jboolean isCopy;
    const char * szLogString = (*env)->GetStringUTFChars(env, logString, &isCopy);
 
    __android_log_print(ANDROID_LOG_DEBUG, "TAGGGGG", "NDK: %s", szLogString);
 
    (*env)->ReleaseStringUTFChars(env, logString, szLogString);
}
int Java_com_ndksetup_NDKSetupActivity_fibonacci(int value)
{
	int p = 8;
	printMe();
	printMe2();
	return p;
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.