Search code examples
androidandroid-studioandroid-ndkmupdf

Which compiler to use when running ndk-build on mupdf for OSX?


I want to use mudf in my Android Studio project for viewing/editing PDF files, and I'm following the instructions at http://www.mupdf.com/docs/how-to-build-mupdf-for-android. I have the SDK and the NDK properly set up and the local.properties file configured to point to the correct respective paths. Now, when I run ndk-build, I get the following output:

    armeabi-v7a] Compile thumb  : mupdfthirdparty <= cff.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= type1cid.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= psaux.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= pshinter.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= psnames.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= raster.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= smooth.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= sfnt.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= truetype.c
    [armeabi-v7a] Compile thumb  : mupdfthirdparty <= type1.c
    [armeabi-v7a] StaticLibrary  : libmupdfthirdparty.a
    [armeabi-v7a] SharedLibrary  : libmupdf_java.so
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../source/fitz/printf.c:29: error: undefined reference to '__isinff'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/jsdate.c:332: error: undefined reference to '__isfinite'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/jsdate.c:227: error: undefined reference to '__isfinite'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/jsparse.c:869: error: undefined reference to '__isfinite'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/jsdate.c:318: error: undefined reference to '__isfinite'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/jsnumber.c:40: error: undefined reference to '__isinf'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/json.c:107: error: undefined reference to '__isinf'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/jsvalue.c:14: error: undefined reference to '__isinf'
    /Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../thirdparty/mujs/jsvalue.c:226: error: undefined reference to '__isinf'
    collect2: error: ld returned 1 exit status
    make: *** [/Users/aayushkothari/Codes/mupdf/platform/android/viewer/obj/local/armeabi-v7a/libmupdf_java.so] Error 1

Based on the answers at How to set standard c99 for compile android NDK project, I modified my Application.mk file to include the line APP_CFLAGS += -std=c99

When I run ndk-build again, I get the following:

[armeabi-v7a] Compile thumb  : mupdf_java <= mupdf.c
/Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/mupdf.c: In function 'Java_com_artifex_mupdfdemo_MuPDFCore_getFocusedWidgetSignatureState':
/Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/mupdf.c:2361:2: warning: implicit declaration of function 'pdf_signatures_supported' [-Wimplicit-function-declaration]
  if (!pdf_signatures_supported())
  ^
[armeabi-v7a] Compile thumb  : mupdfcore <= bbox-device.c
[armeabi-v7a] Compile thumb  : mupdfcore <= bidi-std.c
[armeabi-v7a] Compile thumb  : mupdfcore <= bidi.c
[armeabi-v7a] Compile thumb  : mupdfcore <= bitmap.c
[armeabi-v7a] Compile thumb  : mupdfcore <= buffer.c
[armeabi-v7a] Compile thumb  : mupdfcore <= colorspace.c
/Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../source/fitz/colorspace.c: In function 'fast_cmyk_to_rgb_ARM':
/Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../source/fitz/colorspace.c:410:2: error: 'asm' undeclared (first use in this function)
  asm volatile(
  ^
/Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../source/fitz/colorspace.c:410:2: note: each undeclared identifier is reported only once for each function it appears in
/Users/aayushkothari/Codes/mupdf/platform/android/viewer/jni/../../../../source/fitz/colorspace.c:410:6: error: expected ';' before 'volatile'
  asm volatile(
      ^
make: *** [/Users/aayushkothari/Codes/mupdf/platform/android/viewer/obj/local/armeabi-v7a/objs/mupdfcore/__/__/__/__/source/fitz/colorspace.o] Error 1

After a little bit of searching on that, I changed the -c99 to -gnu99 and ran ndk-build again, only to get the initial errors again.

What do I need to change/add to get rid of these, and also in general what steps should someone new to Android follow to include muPDF in an existing Android Studio project?


Solution

  • The first issue, concerning __isinff and so on is I believe a known issue with the 64 bit android NDK, or at least related to some changes that Google has deliberately made to the NDKs.

    If you revert back to an older, 32bit ndk, it should work - for example:

    http://dl.google.com/android/ndk/android-ndk-r10d-darwin-x86.bin

    Adding this to your Application.mk may also help too:

    APP_PLATFORM := android-9
    

    see, eg, https://groups.google.com/forum/#!topic/android-ndk/L2gc5HRq_dA