Android master branch

Hi all,

Using NDK r10e (on OS X Yosemite), I can successfully compile the androidEmptyExample, however, as soon as I run it, the app crashes with:

07-07 17:25:09.329    2419-2419/cc.openframeworks.androidEmptyExample D/dalvikvm﹕ Trying to load lib /data/app-lib/cc.openframeworks.androidEmptyExample-2/libOFAndroidApp.so 0x429ba918
07-07 17:25:09.344    2419-2419/cc.openframeworks.androidEmptyExample E/dalvikvm﹕ dlopen("/data/app-lib/cc.openframeworks.androidEmptyExample-2/libOFAndroidApp.so") failed: dlopen failed: cannot locate symbol "sigemptyset" referenced by "libOFAndroidApp.so"...
07-07 17:25:09.344    2419-2419/cc.openframeworks.androidEmptyExample W/dalvikvm﹕ Exception Ljava/lang/UnsatisfiedLinkError; thrown while initializing Lcc/openframeworks/OFAndroid;
07-07 17:25:09.344    2419-2419/cc.openframeworks.androidEmptyExample D/AndroidRuntime﹕ Shutting down VM
07-07 17:25:09.344    2419-2419/cc.openframeworks.androidEmptyExample W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x41f7d700)
07-07 17:25:09.354    2419-2419/cc.openframeworks.androidEmptyExample E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "sigemptyset" referenced by "libOFAndroidApp.so"...
            at java.lang.Runtime.loadLibrary(Runtime.java:362)
            at java.lang.System.loadLibrary(System.java:525)
            at cc.openframeworks.OFAndroid.<clinit>(OFAndroid.java:1038)
            at cc.openframeworks.androidEmptyExample.OFActivity.onCreate(OFActivity.java:18)
            at android.app.Activity.performCreate(Activity.java:5372)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
            at android.app.ActivityThread.access$700(ActivityThread.java:159)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:176)
            at android.app.ActivityThread.main(ActivityThread.java:5419)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862)
            at dalvik.system.NativeStart.main(Native Method)

Note: no changes have been made to any project settings. I simply followed the instructions on GitHub for android.

Also: the github instructions point to using NDK r9d, which means switching GCC to 4.8 and PLATFORM_CFLAGS to c++11 in config.android.default.mk. However, this leads to:

/Users/mustafa/Development/Android/android-ndk-r9d/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/lib/gcc/arm-linux-androideabi/4.8/include/stdint.h:9:26: fatal error: stdint.h: No such file or directory
# include_next <stdint.h>

Using NDK r10b (GCC 4.8 and c++11), compile fails with:

../../../addons/ofxAndroid/src/ofxAndroidSoundStream.cpp: In member function 'int ofxAndroidSoundStream::androidOutputAudioCallback(JNIEnv*, jobject, jshortArray, jint, jint)':
../../../addons/ofxAndroid/src/ofxAndroidSoundStream.cpp:261:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(out_float_buffer.size()!=bufferSize*numChannels){
                                         ^

../../../libs/boost/lib/android/armeabi-v7a/libboost_filesystem.a(path.o):path.cpp:function boost::filesystem::path::m_erase_redundant_separator(unsigned int): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
../../../libs/boost/lib/android/armeabi-v7a/libboost_filesystem.a(path.o):path.cpp:function boost::filesystem::path::remove_trailing_separator(): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
../../../libs/boost/lib/android/armeabi-v7a/libboost_filesystem.a(path.o):path.cpp:function boost::filesystem::path::remove_filename(): error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
../../../libs/boost/lib/android/armeabi-v7a/libboost_filesystem.a(path.o):path.cpp:function boost::filesystem::path::begin() const: error: undefined reference to 'std::__throw_out_of_range_fmt(char const*, ...)'
../../../libs/poco/lib/android/armeabi-v7a/libPocoFoundation.a(Thread.o):Thread.cpp:function Poco::ThreadImpl::runnableEntry(void*): error: undefined reference to 'sigemptyset'
../../../libs/poco/lib/android/armeabi-v7a/libPocoFoundation.a(Thread.o):Thread.cpp:function Poco::ThreadImpl::runnableEntry(void*): error: undefined reference to 'sigaddset'
../../../libs/poco/lib/android/armeabi-v7a/libPocoFoundation.a(Thread.o):Thread.cpp:function Poco::ThreadImpl::runnableEntry(void*): error: undefined reference to 'sigaddset'
../../../libs/poco/lib/android/armeabi-v7a/libPocoFoundation.a(Thread.o):Thread.cpp:function Poco::ThreadImpl::runnableEntry(void*): error: undefined reference to 'sigaddset'
../../../libs/poco/lib/android/armeabi-v7a/libPocoFoundation.a(Thread.o):Thread.cpp:function _GLOBAL__sub_I_Thread.cpp: error: undefined reference to 'sigemptyset'
../../../libs/poco/lib/android/armeabi-v7a/libPocoFoundation.a(Thread.o):Thread.cpp:function _GLOBAL__sub_I_Thread.cpp: error: undefined reference to 'sigaddset'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigfillset'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(armcap.o):armcap.c:function OPENSSL_cpuid_setup: error: undefined reference to 'sigdelset'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'signal'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function read_string_inner: error: undefined reference to 'tcsetattr'
../../../libs/openssl/lib/android/armeabi-v7a/libcrypto.a(ui_openssl.o):ui_openssl.c:function open_console: error: undefined reference to 'tcgetattr'
collect2: error: ld returned 1 exit status
make[1]: *** [libs/armeabi-v7a/libOFAndroidApp.so] Error 1
make: *** [Debug] Error 2

:examples:android:androidEmptyExample:compileDebugOF FAILED

Any help would be greatly appreciated.

Thanks.

Hi,

If anyone is running the Android master branch on OS X Yosemite successfully, can you please share your NDK / SDK versions and project targets? Specifically, what (if anything) do you change under the libs/openFrameworksCompiled/project/android/ directory to get OF’s androidEmptyExample to compile?

Thanks for any pointers.
m.

it’s working for me fine with ndk r10e. which version of android are you using? can you try adding in your config.make:

NDK_PLATFORM=android-19

Apologies about the much delayed response @arturo.

I updated to master last evening and ran through the same process, adding NDK_PLATFORM=android-19 in the config.make (this is the config.make file in the examples/android/androidEmptyExample folder).

Using Android Studio, I imported the settings.gradle. The NDK version is r10e, and I am using Android SDK-19. The exact settings in the gradle files are:

ofAndroidLib:

android {
compileSdkVersion 19
buildToolsVersion "19.1"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 19
    versionCode 1
    versionName "1.0"
}
...

androidEmptyExample:

android {
compileSdkVersion 19
buildToolsVersion "19.1"

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 19
}
... 

The compile goes through without any issues, however, when the app is being launched on the device, I get the linking error previously posted.

Note: the updated error is available here: linking error gist.

If there is any additional setting I can try or recommendation you might have, please do let me know.

Thanks again.

I think the reason it works for you and not for @mhash is the version of Android device you are running. I can confirm that latest master works fine on devices with 5.0+ but fails with a similar error on devices with 4.X.

I got an unsatisfied link error on a different symbol, “srand”, and resolved it by adding the missing method:

void srand(unsigned int __s) {
srand48(__s);
}

(found the implementation on stack overflow, of course). Then I got another missing symbol: “sigemptyset” and I added that implementation too:

int sigemptyset(sigset_t *set)
{
memset(set, 0, sizeof *set);
return 0;
}

Then I got a third symbol “sigaddset”, couldn’t find the implementation for it and gave up…

Anyway, I also tried different combinations of ndk’s and values for NDK_PLATFORM/SDK_TARGET/GCC_VERSION but nothing compiles other than

ndk = 10e
NDK_PLATFORM = android-21
SDK_TARGET = android-21
GCC_VERSION = 4.9

I also tried removing the flag -nostdlib flag, but then I got some ambiguous references when linking.

I’m also using OSX Yosemite, BTW, so it may be related also.

Tal

thanks @tallavi – you’re right, my devices were all on 4.x. I think it would make sense to open an issue report, which I’ll take care of.

Appreciate your confirming the problem – was driving me mad!

m.

I ran into the same issue and trying Tallavi’s suggestion didn’t work for me - let me know if anyone has ideas

we need to recompile the libraries using NDK_PLATFORM android-19 and hope that will work in both android 4 and 5.

if someone wants to give it a try, you can configure apothecary to use android-19 by editing scripts/apothecary/android_configure.sh and changing line 3 to:

export NDK_PLATFORM=android-19

then run apothecary from scripts/apothecary like:

./apothecary -t android update openssl

and then:

./apothecary -t android update poco

which are the libraries that seem to have problems, you would need to do the same for any library with undefined symbols.

if anyone gets it to work with android 4 and can send a pull request i can test it on android 5.

I’m giving it a shot. I have both Android 4 and 5 devices to test with.

UPDATE:

Both updates failed:

Tals-Air:apothecary tallavi$ ./apothecary -t android update poco

 ----- poco -----

 Downloading "poco"

SHA== https://github.com/pocoproject/poco
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   136    0   136    0     0    146      0 --:--:-- --:--:-- --:--:--   146
  0     0    0 7232k    0     0  1016k      0 --:--:--  0:00:07 --:--:-- 1748k

 Preparing "poco"

/Users/tallavi/Development/Trailze/ThirdParty/openFrameworks-latest-merged/scripts/apothecary/apothecary: line 68: ./ostype.sh: No such file or directory
/Users/tallavi/Development/Trailze/ThirdParty/openFrameworks-latest-merged/scripts/apothecary/apothecary: line 932: XS: unbound variable

 ^ Received error ^

 ^ Received error ^
Tals-Air:apothecary tallavi$ ./apothecary -t android update openssl

 ----- openssl -----

 Downloading "openssl"

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   317  100   317    0     0    216      0  0:00:01  0:00:01 --:--:--   216
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   322  100   322    0     0    623      0 --:--:-- --:--:-- --:--:--   622
Invalid shasum for openssl-1.0.2c.
 It looks like downloading failed for "openssl"

I guess I’m missing something in my environment in order to run this?

Also, I ran this issue.

env:

Android Studio 1.3.1
ndk-r10e
compileSdkVersion 22
buildToolsVersion “23.0.0 rc3”

It works well in Android 5.+,But crashed in Android 4.0,the error msg is:

cannot locate symbol “tcsetattr”

Any help?

we fixed this a couple of weeks ago, which version of OF are you using?

Ubuntu 15.04

and which version of openFrameworks?

I don’t use OF, just ran this issue when reading tty devices, Could you help me to solve this issue? and what cause this issue?


Sorry for add reply in this frame, there’s only three times new reply in one thread.

for your below reply:
I see, and the issue has been resolved by me just now, It’s very kind of you. thanks for you reply.

This is an openFrameworks forum not an android one, but this seems to be caused by compiling with the NDK targeting android version 21 which doesn’t seem to be compatible with previous android versions