I have a very simple test project. Basically one native c file under jni (jni is
under the root of the project, in the same directory as 'src' 'res' etc). The make
file is the basically the simplest:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_SRC_FILES := native.c
include $(BUILD_SHARED_LIBRARY)
Error message is: make: * No rule to make target ` '/native.c'. needed by...
Obviously ndk-build was trying to find the file under root. If I copy the file
to the root '/' or if I specify the full path of 'native.c' in the make file,
then things are ok.
I also tried to output $LOCAL_PATH by $(warning, '$(LOCAL_PATH)') and found no problem.
Create Android.mk with the following content:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native
LOCAL_SRC_FILES := native.c
include $(BUILD_SHARED_LIBRARY)
Put native.c in the same folder where your Android.mk is.
Run ndk-build
You will have the output as follows:
D:\12314\jni>ndk-build
"Compile thumb : native <= native.c
SharedLibrary : libnative.so
Install : libnative.so => libs/armeabi/libnative.so
Related
I want to include *.so in Android.mk. Here is my code save in app/jni/Android.mk
The .so file is same in app/jni/libdpfr6.so
My code is
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := libdpfr6
LOCAL_SRC_FILES := libdpfr6.so
include $(PREBUILT_STATIC_LIBRARY)
but after running the app I got a error.
LOCAL_SRC_FILES should point to a file ending with ".a"
Android NDK: The following file is unsupported: libdpfr6.so
I need help.
In my Android.mk file i have something like this
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := testmodule
FILE_LIST := $(LOCAL_PATH)/include/md5/md5.с
FILE_LIST += $(LOCAL_PATH)/include/md5/md5main.с
FILE_LIST += $(wildcard $(LOCAL_PATH)/include/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
include $(BUILD_SHARED_LIBRARY)
but when i run ndk-build - i get the following error
Android NDK: WARNING: Unsupported source file extensions in /Users/some/path/jni/Android.mk for module testmodule
Android NDK: include/md5/md5.с include/md5/md5main.с
(I use android-ndk-r8c on OSX 10.9.2)
How can i add *.c file the Android.mk? What could i be doing wrong?
(I can post more of the Android.mk and Application.mk if needed)
Just to move the answer from the comments, like #greenapps said this works:
You could rename them to .cpp and if that is not possible
create a .cpp file in which you include both .c files.
I am using the Android NDK to build a shared library. I have include a snippet from my Android.mk file that is causing me a few issues.
LOCAL_PATH := $(call my-dir)
..#other module here
..#other module here
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
My spatialite.c file includes some header files that are located in a folder that is external to the application project folder. I have included that folder in LOCAL_C_INCLUDES as shown above, but on running ndk-build, it still cannot locate these includes. What is the correct way of allowing the ndk-build command to identify where these includes are located. Any help will be greatly appreaciated.
UPDATE:
I wanted to add that spatialite itself need not be visible to the Java layer. I will thereafter be building another module which uses spatialite. I am not sure if this makes a difference to the way I declare the module on the Android.mk file.
The compiler output is shown below:
jni/spatialite.c:102:20: fatal error: geos_c.h: No such file or directory
#include
The .h file that is being imported in spatialite.c is located at C:/projects/externalappsdk/include. The spatialite.c and Android.mk are located at C:/mobile/myandroidproject/jni/
The include directive within my spatialite.c file is shown below:
#ifndef OMIT_GEOS /* including GEOS */
#include <geos_c.h>
#endif
ANSWER:
I managed to get this working using help from the answers provided by Chris which I have accepted. However, I had to make one change to the Android.mk file as is shown below:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
Note, that the LOCAL_C_INCLUDES goes two levels back instead of three.
Without a
LOCAL_PATH := $(call my-dir)
At the top of the Android.mk, I was unable to build a replica of your project as described, however the error was different than your report - without that directive the compiler was searching for the C source files in an NDK system directory rather in the jni/ folder.
$ cd mobile/myandroidproject/jni
$ ndk-build
Compile thumb : spatialite <= spatialite.c
SharedLibrary : libspatialite.so
Install : libspatialite.so => libs/armeabi/libspatialite.so
File: ./mobile/myandroidproject/jni/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := spatialite
LOCAL_C_INCLUDES := ../../../projects/externalappsdk/include
LOCAL_SRC_FILES := sqlite3.c \
spatialite.c
include $(BUILD_SHARED_LIBRARY)
File: ./mobile/myandroidproject/jni/spatialite.c
#include <geos_c.h>
File: ./mobile/myandroidproject/jni/sqlite3.c
//empty file
File: ./projects/externalappsdk/include/geos_c.h
//empty file
At minimum you should add the LOCAL_PATH line to your Android.mk
If that does not solve the problem, then please update your question with any differences between your project structure and my recreation of it.
Use LOCAL_EXPORT_C_INCLUDE_DIRS instead of LOCAL_C_INCLUDES
when I tried the NDK build command here is the error i got
D:\AndroidWorkSpace\cppTestProj>D:\android-ndk-r8b-windows\android-ndk-r8b\ndk-b
uild.cmd
Android NDK: WARNING: Unsupported source file extensions in jni/Android.mk for m
odule cppTestProj
Android NDK: LOCAL_SRC_FILES :=
"Compile++ thumb : cppTestProj <= maintestapp.cpp
jni/maintestapp.cpp:1:19: fatal error: iostream: No such file or directory
compilation terminated.
make: *** [obj/local/armeabi/objs/cppTestProj/maintestapp.o] Error 1
The JNI folder has the following files:
maintestapp.cpp
Test_array_type.cpp
Test_array_type.h
Could u pls let me know the issue. Im not using Cygwin for the same. Am I missing any files?
Here is the make file
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cppTestProj
LOCAL_SRC_FILES := LOCAL_SRC_FILES := maintestapp.cpp \
Test_array_type.cpp
include $(BUILD_SHARED_LIBRARY)
here is the cpp file
#include<iostream>
#include"Test_array_type.h"
#include<stdio.h>
#include<conio.h>
using namespace std;
int main()
{
Test_array_type test_array;
Test_array_type *ptest_array1;
test_array.AddToList(10);
test_array.AddToList(20);
test_array.AddToList("Basha");
test_array.PrintList();
ptest_array1 = test_array.clonelist();
test_array.DeleteFromList(3);
test_array.AddToList(10);
test_array.AddToList(20);
test_array.AddToList(30);
test_array.AddToList(40);
test_array.AddToList(true);
test_array.AddToList("Java Beon APP");
test_array.PrintList();
ptest_array1->PrintList();
getch();
return true;
}
you should not run the 'ndk-build' command from your projects jni folder. To execute the Android.mk file run ndk-bild command within your root directory of project.
Your Android.mk should be look like this
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := cppTestProj
LOCAL_SRC_FILES := maintestapp.cpp \
Test_array_type.cpp
include $(BUILD_SHARED_LIBRARY)
Then run your ndk-build command
You can see this link for sample Android.mk file
Update:
static {
System.loadLibrary("hello-jni");
}
for more information please refer HelloJni.java file of sample project.
Thanks
you need to add LOCAL_C_INCLUDES and include your visual C++ include folders, since you are obviuosly working with it.
In Android in the Application i want to import one android.mk file into another Android.mk file in the Application
for this i have used in one Andorid.mk file which is to be imported into another module of same project
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := EDSDKModule
LOCAL_SRC_FILES :=libEDSDK.a
LOCAL_ARM_MODE := arm
TARGET_PLATFORM:=android-8
TARGET_ARCH_ABI:=armeabi
TARGET_ABI:=$(TARGET_PLATFORM)-$(TARGET_ARCH_ABI)
include $(PREBUILT_STATIC_LIBRARY)
and main Andorid.mk file is written is
include C:\my_module\Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := EDSK
LOCAL_MODULE_FILENAME := foo
LOCAL_SRC_FILES := sample.c
LOCAL_STATIC_LIBRARIES := EDSDKModule
include $(BUILD_SHARED_LIBRARY)
LOCAL_ARM_MODE := arm
TARGET_PLATFORM:=android-8
TARGET_ARCH_ABI:=armeabi
TARGET_ABI:=$(TARGET_PLATFORM)-$(TARGET_ARCH_ABI)
$(call import-module,EDSDKModule)
but i have got this error on building project using Android-NDk i.e
please suggest some solutions on how to import one module into another module of android.mk file in a project
I am guessing the problem is here :
$NDK_MODULE_PATH\C:\Final FOlder\final c\Mysetup\newworks\SimpleApp\jni\path1\Android.mk:
/*here i have given directory path of android.mk file */
Possible mistakes :
Try to get rid of the empty spaces in the path :
C:\Final FOlder\final c\
to something like this :
C:\FInal_Folder\final_c\myotherdir\xyz.mk
If you are using a absolute path like :
C:\mypath\myotherdir\xyz.mk
then you NEED NOT prefix it with $NDK_MODULE_PATH. Just use the above absolute path itself, which is C:\mypath\myotherdir\xyz.mk
You need an include keyword infront of your above include statement :
# comment : including my mk file here
include C:\mypath\myotherdir\xyz.mk
Get rid of the : in the end of your include statement
So you have to do something like :
include C:\mypath\myotherdir\xyz.mk
OR
If you have the mk file in NDK LOCAL FOLDER then
include $NDK_MODULE_PATH\mylocaldir\xyz.mk
Hope this helps. CHeers!