Undefined reference to AAssetManager_fromJava

后端 未结 5 1834
耶瑟儿~
耶瑟儿~ 2021-02-19 09:36

I am trying to access assets from an android apk using AAssetManager. However, I keep getting \"Undefined reference to AAssetManager_fromJava\" even though I\'ve included asset

相关标签:
5条回答
  • 2021-02-19 09:48

    Android Studio developers, İf you have ExternalNativeBuild file which is called "CMakeList.txt" you must append this code to the file CMakeList.txt

    find_library( # Sets the name of the path variable.
              android-lib
    
              # Specifies the name of the NDK library that
              # you want CMake to locate.
              android )
    target_link_libraries( 
                       ${log-lib}
                        ${android-lib})
    

    if you also have native lib you can add easily like this

    target_link_libraries( native-lib
                       ${log-lib}
                        ${android-lib})
    

    It should work!

    0 讨论(0)
  • 2021-02-19 09:55

    My mistake. I didn't have "android" library added to the linker. I have actually setup NDK dev environment on Visual Studio Express and "android" library wasn't added to my project by default.

    If you are using makefiles, be sure to add -landroid to your LOCAL_LDLIBS when using native AssetManager.

    0 讨论(0)
  • 2021-02-19 10:05

    I added the following to gradle.build

    android.ndk { ldLibs.addAll(["android", "log"]) }

    0 讨论(0)
  • 2021-02-19 10:05

    I fixed it by adding following to Android.mk

    LOCAL_SHARED_LIBRARIES += libandroid
    
    0 讨论(0)
  • 2021-02-19 10:09
    find_library( # Sets the name of the path variable.
        log-lib
    
        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log
    )
    
    find_library(android-lib android)
    
    target_link_libraries( # Specifies the target library.
        hll
        ${log-lib}
        ${android-lib}
        # Links the target library to the log library
        # included in the NDK.
    )
    
    0 讨论(0)
提交回复
热议问题