2

I'm trying to compile libdispatch for linux on Android. However I could not find any instructions for Android in the project files.

I can see there are several StackOverflow questions about using libdispatch, but the information is rather thin.

Has anyone successfully compiled libdispatch for Android using NDK?

Sam Khawase
  • 348
  • 6
  • 21
  • 1
    If anyone is having the same issue, here's what worked for me: `ndk-build NDK_TOOLCHAIN_VERSION=clang NDK_PROJECT_PATH=libdispatch/ APP_BUILD_SCRIPT=libdispatch/Android.mk` – Sam Khawase Apr 07 '16 at 13:38
  • 1
    For anyone finding this later, the command Sam posted worked for me, but only after also cloning github.com/mackyle/blocksruntime github.com/PSPDFKit-labs/libkqueue and github.com/PSPDFKit-labs/libpthread_workqueue into the same directory libdispatch is in. – milch Jul 05 '16 at 07:41

1 Answers1

1

I haven't personally tried compiling libdispatch for Android, but I have built many other libraries. It looks like building libdispatch should be quite easy, as there is already an Android.mk file in the repository. You should be able to build this library with the following command (split across lines for readability):

<ndk directory path>/ndk-build \ 
-C <path to libdispatch source directory> \
NDK_LIBS_OUT=<path to directory for built libraries> \
APP_BUILD_SCRIPT=Android.mk 
Francesca Nannizzi
  • 1,695
  • 13
  • 18
  • I've tried that earlier and it gave me error: `Android NDK: Could not find application project directory !` `Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.` – Sam Khawase Apr 06 '16 at 19:26
  • Did you pass the path to your project directory to ndk-build using the -C argument? Some folks are using NDK_PROJECT_PATH= instead of -C to pass the project path, but I've never used that with newer NDKs. What version of the ndk are you using? – Francesca Nannizzi Apr 06 '16 at 20:17
  • I'm trying to compile and build the libdispatch project checked out from Github. Here's the error I get now: `ndk-build NDK_PROJECT_PATH=./libdispatch` `Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./libdispatch/jni/Android.mk` `/Users/sam/Library/Android/sdk/ndk-bundle/build/core/add-application.mk:195: *** Android NDK: Aborting....Stop.` Do I need to include the libdispatch as a submodule in an Android project? I'm totally lost :-( – Sam Khawase Apr 06 '16 at 20:44
  • The expectation is that the Android.mk file is always inside a directory named jni, so ndk-build is attempting to find the path jni/Android.mk inside the libdispatch directory. It doesn't exist, hence the error. This is a mistake on the part of the libdispatch developers, IMO. Try adding APP_BUILD_SCRIPT=/Android.mk to your ndk-build command. – Francesca Nannizzi Apr 07 '16 at 13:06
  • Actually, use APP_BUILD_SCRIPT=Android.mk to your ndk-build command. APP_BUILD_SCRIPT is relative to the directory specified with -C. – Francesca Nannizzi Apr 07 '16 at 13:12
  • Thanks, I figured that out from the source and got past it. There are some compile errors due to blocksruntime. The 3 projects mentioned in the README have no instructions to compile and I'll have to ask the maintainer on the GitHub repo. – Sam Khawase Apr 07 '16 at 13:15
  • Here's the error BTW: `ndk-build NDK_PROJECT_PATH=libdispatch/ APP_BUILD_SCRIPT=libdispatch/Android.mk 0 < 15:11:30 [armeabi] Compile thumb : dispatch <= apply.c arm-linux-androideabi-gcc: error: unrecognized command line option '-momit-leaf-frame-pointer' arm-linux-androideabi-gcc: error: unrecognized command line option '-fblocks' make: *** [libdispatch//obj/local/armeabi/objs/dispatch/src/apply.o] Error 1` – Sam Khawase Apr 07 '16 at 13:15
  • I think you should accept my answer, in that case. BTW, that error probably means you should be using the Clang toolchain, not GCC. – Francesca Nannizzi Apr 07 '16 at 13:20
  • Using clang solved the issue, Thanks a lot, I'll accept your answer :-) – Sam Khawase Apr 07 '16 at 13:37