android_native_app_glue.h: No such file or directory

6,079 views
Skip to first unread message

Dinand Vanvelzen

unread,
Sep 9, 2011, 5:06:00 PM9/9/11
to android-ndk
As the subject suggests I have a problem building native applications
with the NDK. I have tried to compile on both windows (cygwin) and
linux (Ubuntu 10 LTS). My method of building is using ndk_build
launched from a directory in my archive (using working directory to
convey to NDK what to build). I do not use Eclipse but instead use
bash scripts invoking ndk_build. Interestingly enough all my other
modules compile just fine and #include <android/log.h> does not give
an error.
It seems to be specific android headers that ndk_build cannot locate.
The other header it cannot find is: native_activity.h
I'm using NDK 6b

Any suggestions on how to fix this?

David Turner

unread,
Sep 12, 2011, 9:07:53 AM9/12/11
to andro...@googlegroups.com
Did you import the helper library? i.e. your Android.mk should have the following at its end:

$(call import-module,android/native_app_glue)


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.


Ronnie van Aarle

unread,
Sep 13, 2011, 6:50:41 AM9/13/11
to android-ndk
Hello Dinand

I have had the same problem, you must make sure that target platform
is
at least API 9. Make sure this is correct in the Manifest.xml and also
in
Application.mk in your /jni folder.

At least this worked for me.

Regards.

Dinand Vanvelzen

unread,
Sep 15, 2011, 5:30:18 AM9/15/11
to android-ndk
Hi,

I thought I tried that before to no avail but this time it did work,
Thanks. I also made sure my AndroidManifest.xml has minimal API set to
9.
It does not get it to build correctly yet though as I'm now getting a
different error:

Android NDK: /cygdrive/e/DATA/Code/trunk/dependencies/android-ndk-r6b/
sources/android/native_app_glue/Android.mk:android_native_app_glue:
LOCAL_MODULE_FILENAME should not include file extensions

I looked around and some had success specifying the filename so as
they suggested I added "LOCAL_MODULE_FILENAME:= lib<myLibName>" to all
my make files (for static and shared libraries) to no avail.
I only get this error on the module using android_native_app_glue, all
my regular C++ modules don't have this problem.


Best regards,

Dinand

Ronnie van Aarle

unread,
Sep 15, 2011, 10:44:02 AM9/15/11
to android-ndk
If you set your libMyApplicationName.so in the Android.mk file, you
should
not include the prefix lib and also not the extension .so.
The prefix lib and the extension .so will be added automatically
during the
build process.

This is my Android.mk file that works for me............

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := native-triangle
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS := -llog -landroid -lEGL -lGLESv2
LOCAL_STATIC_LIBRARIES := android_native_app_glue

include $(BUILD_SHARED_LIBRARY)

$(call import-module,android/native_app_glue)

..........It builds libnative-triangle.so which is a pure native
android app.

In fact it is the same builtfile that came with NativeActivity except
with
a different LOCAL_MODULE.

Good luck.

Dinand Vanvelzen

unread,
Sep 15, 2011, 2:10:21 PM9/15/11
to android-ndk

That did the trick, Thanks Ronnie.
I had "$(call import-module,android/native_app_glue) " before "include
$(BUILD_SHARED_LIBRARY) " as some examples on the internet show.
Placing it after worked just fine.

Now I'm getting no rule to make target.
Thus I added the makefile to my "project file":

"include $(ANDROIDNDK)/sources/android/native_app_glue/Android.mk"

Along with all the other modules. The problem I have now is that the
environment variable $(ANDROIDNDK) which I set in a bash script before
invoking ndk_build is now empty.
Is this the proper way of using environment variables in Android
makefiles or do I have to do anything special?

Thanks so much for all the help!


On Sep 15, 7:44 am, Ronnie van Aarle <ronnie.van.aa...@gmail.com>
wrote:

David Turner

unread,
Sep 16, 2011, 9:40:52 AM9/16/11
to andro...@googlegroups.com
On Thu, Sep 15, 2011 at 8:10 PM, Dinand Vanvelzen <dinand.v...@gmail.com> wrote:

That did the trick, Thanks Ronnie.
I had "$(call import-module,android/native_app_glue) " before "include
$(BUILD_SHARED_LIBRARY) " as some examples on the internet show.
Placing it after worked just fine.

Now I'm getting no rule to make target.
Thus I added the makefile to my "project file":

"include $(ANDROIDNDK)/sources/android/native_app_glue/Android.mk"

Along with all the other modules. The problem I have now is that the
environment variable $(ANDROIDNDK) which I set in a bash script before
invoking ndk_build is now empty.
Is this the proper way of using environment variables in Android
makefiles or do I have to do anything special?


You should never include an Android.mk directly from your own project file.

An Android.mk file is meant to be parsed by the NDK build system itself, which is implemented by ndk-build, which itself is only a wrapper around $NDK/build/core/build-local.mk
So try doing the following instead:

include $(ANDROIDNDK)/build/core/build-local.mk

This assumes that you are including this from GNU Make 3.81 (and not another Make/build tool).
Also this assumes that you are in the project's root directory when the include is performed. Otherwise, adjust by defining NDK_PROJECT_PATH to point to this directory.

Generally speaking, mixing the NDK build system with another GNU Make script is probably a rather fragile / dangerous thing. Handle with care :)

Dinand Vanvelzen

unread,
Sep 24, 2011, 2:19:37 AM9/24/11
to android-ndk
Hey David,

Turns out I still have the original problem. I have no idea why it
disappeared for a bit on my windows system (its back now) but on my
linux box the NDK still cannot find the android NDK header files.

I have the import instruction in my Android.mk, all the files state
required NDK = 9, I tried including the native_app_glue.mk from my
main Android.mk which includes all the others (I call that my
"project" file). I also tried "include $(ANDROIDNDK)/build/core/build-
local.mk" which causes the NDK to literally complain that things are
"Weird". There is just something about native_app_glue I cant put my
finger on. Could you or anyone else please take a quick peek at my
archive to see if you spot something wrong?

My SVN archive is here:
https://gucef.svn.sourceforge.net/svnroot/gucef

You can view it without downloading here:
http://gucef.svn.sourceforge.net/viewvc/gucef/trunk/

I start the build by running "trunk/projects/Android/BuildUsingNDK.sh"
it invokes FindNDK.sh and it will invoke "ndk-build" from trunk
It expects the NDK in "trunk/dependencies" which for NDK 6b is "trunk/
dependencies/android-ndk-r6b"

I've been stuck on this for a very long time now, I'd really really
appreciate if someone could help me to compile this thing using
native_app_glue.
Thanks!!!

David Turner

unread,
Sep 24, 2011, 3:32:21 AM9/24/11
to andro...@googlegroups.com
On Sat, Sep 24, 2011 at 8:19 AM, Dinand Vanvelzen <dinand.v...@gmail.com> wrote:
Hey David,

Turns out I still have the original problem. I have no idea why it
disappeared for a bit on my windows system (its back now) but on my
linux box the NDK still cannot find the android NDK header files.


Just a guess, I only add a quick look at your Android.mk, your import statement is:

$(call import-module, android/native_app_glue )

What happens if you drop the spaces, i.e.:

$(call import-module,android/native_app_glue)
 
I wonder if this is not the root cause of the problem. I would qualify that as a NDK bug, but I'd like to be sure before looking further.

Also, there is a bug in your statement:

ifndef $(MY_MODULE_PATH)
...
endif

If should really be:

ifndef MY_MODULE_PATH
...
endif

Dinand Vanvelzen

unread,
Sep 27, 2011, 5:47:12 PM9/27/11
to android-ndk
Hey David,

I implemented the changes you suggested and it now successfully builds
on Ubuntu!!!
I don't really see how removing some spaces would have made a
difference but apparently it did.
As you suggest this might indeed be a NDK bug.

I created a project and made a debug apk package using Ant.
My application installs on a device (2.3.3) but crashes when
launching. I checked the log and it complains it cannot find "native-
activity".
I listed "native-activty" as the module to use in AndroidManifest.xml
as:

<!-- Tell NativeActivity the name of our .so -->
<meta-data android:name="android.app.lib_name"
android:value="native-activity" />

However I do have "native-activity.so" in my output directory and it
gets added into the debug application apk. Since I do nothing special
with the apk I would expect it to be able to find my ".so"
Why can it not find the module even though it has it? Do I have to
specify a path somewhere? Is "native-activity.so" not a valid name for
my glue module?

Thanks a lot!


On Sep 24, 12:32 am, David Turner <di...@android.com> wrote:
> On Sat, Sep 24, 2011 at 8:19 AM, Dinand Vanvelzen <
>

David Turner

unread,
Sep 29, 2011, 3:41:43 PM9/29/11
to andro...@googlegroups.com
On Tue, Sep 27, 2011 at 2:47 PM, Dinand Vanvelzen <dinand.v...@gmail.com> wrote:
Hey David,

I implemented the changes you suggested and it now successfully builds
on Ubuntu!!!
I don't really see how removing some spaces would have made a
difference but apparently it did.
As you suggest this might indeed be a NDK bug.

It definitely is, and I'll fix this. For the record, the GNU Make language is really hostile to good coding practice :-)

Thanks for the confirmation

David Turner

unread,
Sep 29, 2011, 3:43:25 PM9/29/11
to andro...@googlegroups.com
On Tue, Sep 27, 2011 at 2:47 PM, Dinand Vanvelzen <dinand.v...@gmail.com> wrote:

However I do have "native-activity.so" in my output directory and it
gets added into the debug application apk. Since I do nothing special
with the apk I would expect it to be able to find my ".so"
Why can it not find the module even though it has it? Do I have to
specify a path somewhere? Is "native-activity.so" not a valid name for
my glue module?

The package manager only copies files that are named as lib/<abi>/lib<name>.so at installation time.
If your shared library is called "native-activity.so", it is simply ignored and not installed into /data/data/<package-name>/lib/ which is why your app doesn't work.

Dinand Vanvelzen

unread,
Sep 29, 2011, 3:53:18 PM9/29/11
to andro...@googlegroups.com
Hey All,

I figured out the problem with the load crashing:
1) make sure your libs start with "lib" because otherwise they are not placed in the data/data/<package name>/lib directory
2) dependency libs are not automatically loaded at all and the NDK will complain it cant find your modules while in reality the problem is that a module your module depends on is not yet loaded.

Hopefully this will help someone else
STATEMENT OF CONFIDENTIALITY
_______________________________

THE INFORMATION CONTAINED IN THIS E-MAIL MESSAGE IS PRIVILEGED AND CONFIDENTIAL INFORMATION INTENDED ONLY FOR THE USE OF THE INDIVIDUAL OR ENTITY NAMED ABOVE. IF THE READER OF THIS MESSAGE IS NOT THE INTENDED RECIPIENT, YOU ARE HEREBY NOTIFIED THAT ANY DISSEMINATION, DISTRIBUTION OR COPY OF THIS COMMUNICATION IS STRICTLY PROHIBITED. IF YOU HAVE RECEIVED THIS COMMUNICATION IN ERROR, PLEASE IMMEDIATELY NOTIFY THE SENDER VIA TELEPHONE OR BY REPLYING TO THIS COMMUNICATION THEN PERMANENTLY DELETE THIS COMMUNICATION.

David Turner

unread,
Sep 29, 2011, 4:39:38 PM9/29/11
to andro...@googlegroups.com
On Thu, Sep 29, 2011 at 12:53 PM, Dinand Vanvelzen <dinand.v...@gmail.com> wrote:
Hey All,

I figured out the problem with the load crashing:
1) make sure your libs start with "lib" because otherwise they are not placed in the data/data/<package name>/lib directory

Correct
 
2) dependency libs are not automatically loaded at all and the NDK will complain it cant find your modules while in reality the problem is that a module your module depends on is not yet loaded.

And this is a bug that will be fixed in the next release. You can force all libraries to be installed by explicitely liste then in your APP_MODULES definition in the meantime.

Hope this helps
Reply all
Reply to author
Forward
0 new messages