Build problem with Android libraries tutorial

Sysprogs forums Forums VisualGDB Build problem with Android libraries tutorial

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #661
    hpetschko
    Participant

    Hi,

    I followed the instructions on http://visualgdb.com/tutorials/android/ and succeessfully built and ran the app.
    Then I wanted to add a native library and followed the instructions on http://visualgdb.com/tutorials/android/library/.
    I think that I did everything right yet I get the following error message:

    2> D:/Experiments/android-ndk-r9/toolchains/x86-4.6/prebuilt/windows-x86_64/bin/../lib/gcc/i686-linux-android/4.6/../../../../i686-linux-android/bin/ld.exe: ./obj/local/x86/objs-debug/AndroidProject1/AndroidProject1.o: in function Java_com_visualgdb_example_AndroidProject1_AndroidProject1_stringFromJNI:jni/AndroidProject1.c:32: error: undefined reference to ‘MyTestFunction’

    What could be wrong?

    Thanks a lot!

    H

    #2685
    ket
    Participant

    Hi,

    Please check that the values for LOCAL_SRC_FILES and LOCAL_EXPORT_C_INCLUDES make sense for your project (the working directory is just the project directory of the app, $(LOCAL_PATH) is “jni”), both need to be appropriate relative paths.
    Look in the Output window, if the LOCAL_SRC_FILES value is wrong or the built library cannot be found, then Android NDK will show a warning in the build output with the translated path.

    Also note that in VisualGDB version 4.0 and above you do not need to modify the Android.mk manually, as long as you reference the project VisualGDB will modify the makefile automatically during build. It may still be worth checking the Android.mk changes after building for example if you would prefer to use static over shared libraries.

    #2686
    hpetschko
    Participant

    Thanks for the reply!
    I tried it again, but this time – after having added the library – I made these three steps:

    1) added the include statement
    2) called the function
    3) made the AndroidProject1 dependent on AndroidLibrary1

    Building still yields the same result.

    I have attached the solution plus the build log.

    Many thanks in advance!

    H

    #2687
    ket
    Participant

    Hi,

    It looks like there have been some changes in the Android build system. The issue here is not how the library is referenced in the app project, that code is fine. Building a shared library from a static library does not work any more, it creates an empty library hence the undefined reference error. To fix this replace the Android.mk content of the library project with the following:

    # Generated by VisualGDB
    
    LOCAL_PATH := $(call my-dir)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE    := AndroidLibrary1-static
    #VisualGDBAndroid: AutoUpdateSourcesInNextLine
    LOCAL_SRC_FILES := AndroidLibrary1.c
    LOCAL_C_INCLUDES :=
    LOCAL_STATIC_LIBRARIES :=
    LOCAL_SHARED_LIBRARIES :=
    LOCAL_LDLIBS :=
    LOCAL_CFLAGS :=
    LOCAL_CPPFLAGS :=
    LOCAL_LDFLAGS :=
    PERSISTENT_SRC_FILES := $(LOCAL_SRC_FILES)
    include $(BUILD_STATIC_LIBRARY)
    
    include $(CLEAR_VARS)
    LOCAL_MODULE    := AndroidLibrary1-shared
    LOCAL_SRC_FILES := $(PERSISTENT_SRC_FILES)
    include $(BUILD_SHARED_LIBRARY)
    

    Also, now if there is a shared library target defined somewhere in Android.mk then somehow the static target does not get built. So to still build both static and shared libraries from the same code add the following line to the library project’s Application.mk:

    APP_MODULES := AndroidLibrary1-static AndroidLibrary1-shared

    We will include a fix to these issues in our next r release and edit the Android library tutorial to reflect the changes.

    #2688
    hpetschko
    Participant

    It’s working!

    Thank you very much

    H

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.