No rule to make target error android ndk build sqlite - android

I am trying to build sqlite using the android NDK to use a sqlite3_create_function but am getting No rule to make target error. make: *** No rule to make target '/fts3-rank.c', needed by '.../obj/local/armeabi/objs/fts3-rank//fts3-rank.o'. Stop. This Android.mk file is based off of the one on this website: http://www.roman10.net/how-to-compile-sqlite-for-android-using-ndk/
#LOCAL_PATH is used to locate source files in the development tree.
#the macro my-dir provided by the build system, indicates the path of the current directory
LOCAL_PATH := $(call my_dir)
#####################################################################
# build sqlite3 #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/sqlite-amalgamation-3071700
LOCAL_MODULE := sqlite3
LOCAL_SRC_FILES := $(LOCAL_PATH)/sqlite-amalgamation-3071700/sqlite3.c
include $(BUILD_STATIC_LIBRARY)
#include $(BUILD_SHARED_LIBRARY)
#####################################################################
# build our code #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/sqlite-amalgamation-3071700
LOCAL_MODULE := fts3-rank
LOCAL_SRC_FILES := fts3-rank.c
LOCAL_STATIC_LIBRARIES := libsqlite3
#LOCAL_SHARED_LIBRARIES:=libsqlite3
LOCAL_LDLIBS := -llog -lm
#include $(BUILD_SHARED_LIBRARY)
include $(BUILD_EXECUTABLE)

May be There some different reason of this error.
It may be LOCAL_PATH value incorrect so check LOCAL_PATH initialization. Remove any extra spaces in that.
LOCAL_PATH := $(call my-dir)__
Your jni library should be loaded in memory before calling any jni function. Load jni library as follow.
static {
System.loadLibrary("libmy-jni-module");
}
You may refer this discussion on so

I fixed it somehow by trial and error. It was very strange. I guess it's because I was using LOCAL_PATH twice?
I finally got it to build using this Android.mk
#LOCAL_PATH is used to locate source files in the development tree.
#the macro my-dir provided by the build system, indicates the path of the current directory
LOCAL_PATH := $(call my-dir)
#####################################################################
# build sqlite3 #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := sqlite-amalgamation-3071700
LOCAL_MODULE := sqlite3
LOCAL_SRC_FILES := sqlite-amalgamation-3071700/sqlite3.c
include $(BUILD_STATIC_LIBRARY)
#include $(BUILD_SHARED_LIBRARY)
#####################################################################
# build our code #
#####################################################################
include $(CLEAR_VARS)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/sqlite-amalgamation-3071700
LOCAL_MODULE := fts3-rank
LOCAL_SRC_FILES := fts3-rank.c
LOCAL_STATIC_LIBRARIES := libsqlite3
#LOCAL_SHARED_LIBRARIES:=libsqlite3
LOCAL_LDLIBS := -llog -lm
include $(BUILD_SHARED_LIBRARY)
#need main function to have executable
#include $(BUILD_EXECUTABLE)

Related

Android.mk build error export_includes needed by import_includes for prebuilt library

I am having issues creating a Android prebuilt shared library. In hope of figuring out what I'm doing wrong, I followed Google's example where I found the source for this example in the android-8.1.0_r52 tree at development/ndk/tests/prebuilt-library/jni.
Here's how I configure the ASOP
$ . build/envsetup.sh
$ lunch (I selected 29 aosp_bullhead_userdebug)
Then in the above jni folder I issued "$ mm"
The error I get is (which is the same is my other project)
ninja: error: 'out/target/product/bullhead/obj/SHARED_LIBRARIES/foo-prebuilt_intermediates/export_includes', needed by 'out/target/product/bullhead/obj/SHARED_LIBRARIES/foo-user_intermediates/import_includes', missing and no known rule to make it
When I grep the out/target/products/bullhead folder for "foo" I get nothing.
I also tried replacing
include $(PREBUILT_SHARED_LIBRARY)
with
include $(BUILD_PREBUILT)
and get the same error, but "obj" is replaced with "obj_arm".
Below is the stock Android.mk that comes with the tree.
LOCAL_PATH := $(call my-dir)
# Define BUILD_FOO=1 to rebuild libfoo.so from scratch, then
# copy obj/local/armeabi/libfoo.so to jni/libfoo.so
#
ifneq ($(BUILD_FOO),)
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := foo/foo.c
LOCAL_C_INCLUDES := $(LOCAL_PATH)/foo
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
include $(BUILD_SHARED_LIBRARY)
else # not build libfoo.so, trying to use PREBUILT_SHARED_LIBRARY instead.
# Note: the module is named foo-prebuilt, but the library is libfool.so !
#
include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := libfoo.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/foo
include $(PREBUILT_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := foo-user
LOCAL_SRC_FILES := foo-user.c
LOCAL_SHARED_LIBRARIES := foo-prebuilt
include $(BUILD_SHARED_LIBRARY)
endif
This is the jni/ directory structure
jni/
Android.mk
foo-user.c
libfoo.so
foo/
foo.c
foo.h

ndk-build undefined reference errror

I'm using ndk-build to build a set of shared library(.so) for my android project. I configured and made the source code of C++ library(gdal-2.2.2).
everything was ok.("./configure & make & make install" was successful).
So i created my jni folder like this documentation.
but when I'm trying to use ndk-build on windows, I get a lot of error like "Undefined refrence to somthing".
I've spent a lot of time on this project. Is there someone to help me?
Thanks.
Update
I used configure like this on ubuntu 16.04:
./configure --prefix=/home/mahdi/Desktop/build/ --with-spatialite=yes --with-spatialite-soname=libspatialite.so --host=i686-linux-android CXXFLAGS="-D_GLIBCXX_USE_CXX11_ABI=0" LIBS="-lsupc++ -lstdc++"
After make & make install step I created JNI. this is my directory.
jniwrap
jni
gdal
Android.mk
Application.mk
gdal_wrap.cpp
gdalconst_wrap.c
gnm_wrap.cpp
libgdal.a
ogr_wrap.cpp
osr_wrap.cpp
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/gdal/include
LOCAL_SRC_FILES := libgdal.a
LOCAL_EXPORT_LDLIBS := -lz
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdaljni
LOCAL_SRC_FILES := gdal_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdalconstjni
LOCAL_SRC_FILES := gdalconst_wrap.c
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := ogrjni
LOCAL_SRC_FILES := ogr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := osrjni
LOCAL_SRC_FILES := osr_wrap.cpp
LOCAL_STATIC_LIBRARIES := gdal
include $(BUILD_SHARED_LIBRARY)
Aplication.mk
APP_STL := gnustl_shared
APP_CFLAGS := Android.mk
APP_ABI := x86
APP_PLATFORM := android-14
Then I used android-ndk-r16b in windows-x86_64 but I faced with these errors like this picture:
There was a lot of "undefined reference error" that i can't show here.
Note: for making gdal Java Binding I used swig and jdk7 on my ubuntu 16.04.
When you build libgdal.a on your ubuntu machine, you must have sqlite3, which resolves #include "sqlite3.h".
These include files are enough for a static library, but to create libgdaljni.so you also need libsqlite3.a. You can cross-compile it for Android it yourself on the same ubuntu machine, but it is probably OK to get prebuilt library e.g. from https://github.com/couchbase/couchbase-lite-java-native/tree/master/vendor/sqlite/libs/android.
Copy this file (for appropriate ABI) to the same directory, and modify your Android.mk accordingly:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := sqlite3
LOCAL_SRC_FILES := libsqlite3.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := gdal
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/gdal/include
LOCAL_SRC_FILES := libgdal.a
LOCAL_EXPORT_LDLIBS := -lz
LOCAL_STATIC_LIBRARIES := sqlite3
include $(PREBUILT_STATIC_LIBRARY)
*continued without changes*
If you still have "undefined reference error", this could mean that some other libraries should be added.

Prebuild of static library failed

I try to set up an Android NDK build based on CMake scripts, which dynamically create the required Android make files. While I can't use the JNI folder structure I split the build process in several separated make scripts:
1st Create root Android.mk file located in project root:
#ANDROID ROOT MAKEFILE
LOCAL_PATH := D:/binrev/repository/bar
include $(CLEAR_VARS)
MY_LOCAL_CFLAGS := -DDEBUG
include D:/binrev/repository/bar/src/Android.mk
2nd Create source Android.mk file in project source folder and perform module build:
$(info "[INFO] Source Makefile invoked")
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := bar
LOCAL_C_INCLUDES:= D:/binrev/repository/bar/include
LOCAL_SRC_FILES := bar.cpp
ifeq (debug,"debug")
MY_LOCAL_CFLAGS := -DDEBUG
endif
ifeq (false,true)
LOCAL_ARM_MODE := arm
endif
LOCAL_EXPORT_C_INCLUDES := D:/binrev/repository/bar/include
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -landroid
LOCAL_STATIC_LIBRARIES += foo
ifeq (OFF, ON)
include $(BUILD_SHARED_LIBRARY)
else
include $(BUILD_STATIC_LIBRARY)
endif
Basicly this mechanism works and I could compile my sources, but I fail if I try to include a Prebuild of a library. I tried the following ways to include a pre-build
of a static library (with modified source/include definitions):
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_SRC_FILES := lib/android/$(TARGET_ARCH_ABI)/libfoo.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
include $(PREBUILT_STATIC_LIBRARY)
1st Prebuild definition in source Android.mk file
2nd Call import-module mechanism and add Prebuild Android.mk file to prebuild-lib
3rd Prebuild definition in root Android.mk file
[Edit:] Here is the snipped of the call-import test which also fail:
$(info "[INFO] Source Makefile invoked")
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := bar
LOCAL_C_INCLUDES:= D:/binrev/repository/bar/include
LOCAL_SRC_FILES := bar.cpp
ifeq (debug,"debug")
MY_LOCAL_CFLAGS := -DDEBUG
endif
ifeq (false,true)
LOCAL_ARM_MODE := arm
endif
LOCAL_EXPORT_C_INCLUDES := D:/binrev/repository/bar/include
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -landroid
LOCAL_STATIC_LIBRARIES += foo
ifeq (ON, ON)
include $(BUILD_SHARED_LIBRARY)
else
include $(BUILD_STATIC_LIBRARY)
endif
$(call import-module, external-deps/foo)
In each case the Script with the prebuild-definition is invoked, but the prebuild
is not performed. When my NDK build has been compleded, the prebuild library and
objects are not copied to my obj folder. It seems to me that the prebuild is
completely ignored. But the path to prebuild sources are correct, otherwise the
compile fails with missing file error.
You could get the complete source of this test implementation here:
[Test projects][1]https://sourceforge.net/projects/binrevengine/files/publications/
Hint: The bar project is the project which tries to prebuild the foo project.
The foo project contains the prebuild sources.
The added tests projects could be build by your own using MinGW64 with GCC 4.7/4.8 in handshake with CMake and pre installed NDK (using r8e).
I completly get lost and running out of ideas ...
Thanks for any help.
The Android build system will not build a static library without it being used by a shared library. Just create a dummy shared library that has your static library as a dependency and voila:
include $(CLEAR_VARS)
LOCAL_MODULE := dummy
LOCAL_PATH := $(LOCAL_PATH)
LOCAL_SRC_FILES := dummy.c
LOCAL_STATIC_LIBRARIES := foo
include $(BUILD_SHARED_LIBRARY)
To exclude possible sources of defects I've reduced the Android make file to simplest case without using CMake generator of those files:
LOCAL_PATH := D:/binrev/repository/bar
include $(CLEAR_VARS)
LOCAL_MODULE := foo-prebuilt
LOCAL_SRC_FILES := external-deps/foo/lib/android/$(TARGET_ARCH_ABI)/libfoo.a
include $(PREBUILT_STATIC_LIBRARY)
include $(CLEAR_VARS)
LOCAL_MODULE := bar
LOCAL_C_INCLUDES:= D:/binrev/repository/bar/include
LOCAL_C_INCLUDES+= D:/binrev/repository/bar/external-deps/foo/include
LOCAL_SRC_FILES := src/bar.cpp
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -landroid
LOCAL_SHARED_LIBRARIES := foo-prebuilt
include $(BUILD_SHARED_LIBRARY)
and:
LOCAL_PATH := D:/binrev/repository/foo
include $(CLEAR_VARS)
LOCAL_MODULE := foo
LOCAL_C_INCLUDES:= D:/binrev/repository/foo/include
LOCAL_SRC_FILES := src/foo.cpp
LOCAL_LDLIBS := -llog
LOCAL_LDLIBS += -landroid
include $(BUILD_STATIC_LIBRARY)
The failure still exists. The prebuild of the foo library is not executed. I also excluded MinGW64 as possible source of defect, if I try to build the project with Windows command line it results in same issue. The shared library is build, but the prebuild is not executed.
I checked my sources and scripts multiple times, but can't find any failure.
Any ideas what could be wrong or missing?

ADT tool chain not producing output for static libraries

Trying to build a static NDK library using Android's ADT Eclipse tool chain. However, whenever I build with BUILD_STATIC_LIBRARY, no output is produced: I get the message
make: Nothing to be done for `all'."
Any recommendations?
LOCAL_PATH := $(call my-dir)
STL_PATH := "C:/Android/ndk/sources/cxx-stl/gnu-libstdc++/4.6/include"
PLATFORM_INCLUDE := "C:/Android/ndk/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi/include"
APP_STL := gnustl_static
include $(CLEAR_VARS)
LOCAL_MODULE := libCore
LOCAL_CPPFLAGS += -std=c++11 -fexceptions -D_OS_ANDROID
LOCAL_LDLIBS := -lGLESv2 -lEGL -lstdc++
LOCAL_C_INCLUDES += $(LOCAL_PATH)/Headers
...
LOCAL_SRC_FILES += Source/Engine/Game.cpp
...
include $(BUILD_STATIC_LIBRARY)
Here is the content of Android.mk file of two-libs sample project from Android NDK.
LOCAL_PATH:= $(call my-dir)
# first lib, which will be built statically
#
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-first
LOCAL_SRC_FILES := first.c
include $(BUILD_STATIC_LIBRARY)
# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)
LOCAL_MODULE := libtwolib-second
LOCAL_SRC_FILES := second.c
LOCAL_STATIC_LIBRARIES := libtwolib-first
include $(BUILD_SHARED_LIBRARY)
You may try building the static library as part of another shared library as shown in the example.
I just did a ndk-build on the two-libs sample project and i could see the .a file along with .so in obj\local\armeabi directory.
Edit:
By default, ndk-build will only build shared libraries and executables, and the modules they depend on. To force a build specify libCore in APP_MODULES as follows.
APP_MODULES := libCore
or in command line as
ndk-build APP_MODULES=libCore

include libjpeg in a NDK build

As specified in this answer, I downloaded libjpeg 8d from github and placed it in a folder {ANDROID_APP}/jni/libjpeg. This library has it's own Android.mk, so I tried to include it at the end of my {ANDROID_APP}/jni/Android.mk this way :
include $(LOCAL_PATH)/libjpeg/Android.mk
Note : I'm using the latest version of android NDK (r8c)
After running ndk-build, I still get this error :
ANDROID_APP/jni/libfoo/foo_analysis.c:36:21: fatal error: jpeglib.h: No such file or directory
This is the structure of my global Android.mk :
LOCAL_PATH := $(call my-dir)
# libFoo
include $(CLEAR_VARS)
LOCAL_MODULE := libfoo
LOCAL_MODULE_FILENAME := libfoo
LOCAL_SRC_FILES := libfoo/foo.c libfoo/foo_analysis.c libfoo/foo_extract.c
LOCAL_STATIC_LIBRARIES := libbmp # declared previously but not shown in this example
LOCAL_CFLAGS = ${FLAGS}
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libfoo
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)
# libBar
include $(CLEAR_VARS)
LOCAL_MODULE := libbar
LOCAL_MODULE_FILENAME := libbar
LOCAL_SRC_FILES := bar/bar.c
LOCAL_STATIC_LIBRARIES := libfoo
LOCAL_CFLAGS = ${FLAGS}
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/bar
LOCAL_EXPORT_LDLIBS := -llog
include $(BUILD_STATIC_LIBRARY)
# callbar
LOCAL_MODULE := libcallbar
LOCAL_MODULE_FILENAME := libcallbar
LOCAL_SRC_FILES := com_androidapp_nativeC_callbar.c
LOCAL_STATIC_LIBRARIES := libbar
LOCAL_CFLAGS = ${FLAGS}
include $(BUILD_SHARED_LIBRARY)
#libjpeg
include $(LOCAL_PATH)/libjpeg/Android.mk
I tried to use LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/libfoo $(LOCAL_PATH)/libjpeg
and LOCAL_C_INCLUDES := $(LOCAL_PATH)/libjpeg in the libFoo module, but I still get the same error.
Just looked at Android.mk in jpeg8d-master folder and seems to be it has nothing.
I was trying to compile library directly according to STANDALONE-TOOLCHAIN.HTML
I do next: $export NDKROOT=/home/alex/tools/android-ndk-r8c (where is your NDK) $export SYSROOT=$NDKROOT/platforms/android-9/arch-arm (or any other android platform)
but files from jpeg8d-master have windows \r symbols and I deleted config.guess, config.sub, depcomp than use $automake -a command. And replace ltmain.sh from glib-2.34.0
than $./configure CC="$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc --sysroot=$SYSROOT" --host=arm-linux-androideabi $make
next try prebuilts feature NDK - How to use a generated .so library in another project and NDK/PREBUILTS.HTML

Categories

Resources