Android-ndk generating wrong command
Asked Answered
I

1

0

I have a problem with android ndk-build not copying my shared libraries to intermediates/ndkbuild folder. I have created my modules in the Android.mk like this:

Android.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
EXT_LIB_ROOT := $(LOCAL_PATH)/../prebuilt/dcmtk

LOCAL_MODULE := ofstd
LOCAL_SRC_FILES := $(EXT_LIB_ROOT)/ofstd/lib/$(TARGET_ARCH_ABI)/libofstd.so
LOCAL_EXPORT_C_INCLUDES := $(EXT_LIB_ROOT)/ofstd/include
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := oflog
LOCAL_SRC_FILES := $(EXT_LIB_ROOT)/oflog/lib/$(TARGET_ARCH_ABI)/liboflog.so
LOCAL_EXPORT_C_INCLUDES := $(EXT_LIB_ROOT)/oflog/include
LOCAL_SHARED_LIBRARIES := ofstd
include $(PREBUILT_SHARED_LIBRARY)

It builds and the generated command is:

D:\android-sdk\ndk-bundle\\build\ndk-build.cmd NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=C:\dev\trunk\myApp\app\Android.mk NDK_APPLICATION_MK=C:\dev\trunk\myApp\app\Application.mk APP_ABI=x86 NDK_ALL_ABIS=x86 NDK_DEBUG=1 APP_PLATFORM=android-21 NDK_OUT=C:/dev/trunk/myApp/app/build/intermediates/ndkBuild/debug/obj NDK_LIBS_OUT=C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n

Now, the output from the log is:

md "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib\x86" >NUL 2>NUL || rem
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe [x86] "Gdbserver      ": "[i686-linux-android] C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/gdbserver"
copy /b/y "D:\android-sdk\ndk-bundle\build\\..\prebuilt\android-x86\gdbserver\gdbserver" "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib\x86\gdbserver" > NUL
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe [x86] "Gdbsetup       ": "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/gdb.setup"
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe "set solib-search-path C:/dev/trunk/myApp/app/build/intermediates/ndkBuild/debug/obj/local/x86" > C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/gdb.setup
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe "directory D:/android-sdk/ndk-bundle/build//../platforms/android-21/arch-x86 D:/android-sdk/ndk-bundle/build//../sources/cxx-stl/gnu-libstdc++ C:/dev/trunk/myApp/app/../prebuilt/dcmtk/ofstd/include" >> C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/gdb.setup
md "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\obj\local\x86" >NUL 2>NUL || rem
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe [x86] "Prebuilt       ": "libofstd.so <= C:/dev/trunk/myApp/app/../prebuilt/dcmtk/ofstd/lib/x86/"
copy /b/y "C:\dev\trunk\myApp\app\..\prebuilt\dcmtk\ofstd\lib\x86\libofstd.so" "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\obj\local\x86\libofstd.so" > NUL
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe [x86] "Install        ": "libofstd.so => C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/libofstd.so"
copy /b/y "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\obj\local\x86\libofstd.so" "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib\x86\libofstd.so" > NUL
D:/android-sdk/ndk-bundle/build//../toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-strip --strip-unneeded  C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/libofstd.so
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe [x86] "Prebuilt       ": "liboflog.so <= C:/dev/trunk/myApp/app/../prebuilt/dcmtk/oflog/lib/x86/"
copy /b/y "C:\dev\trunk\myApp\app\..\prebuilt\dcmtk\oflog\lib\x86\liboflog.so" "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\obj\local\x86\liboflog.so" > NUL
D:/android-sdk/ndk-bundle/build//../prebuilt/windows-x86_64/bin/echo.exe [x86] "Install        ": "liboflog.so => C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/liboflog.so"
copy /b/y "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\obj\local\x86\liboflog.so" "C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib\x86\liboflog.so" > NUL
D:/android-sdk/ndk-bundle/build//../toolchains/x86-4.9/prebuilt/windows-x86_64/bin/i686-linux-android-strip --strip-unneeded  C:\dev\trunk\myApp\app\build\intermediates\ndkBuild\debug\lib/x86/liboflog.so

Unfortunately, no files are copied or generated. By running the same command from command line, the result is the same. However, if we skip the -n flag at the end of the command, the command completes successfully with the files being copied. So, my question is how to omit that -n and what is the purpose in that flag? I am using the latest stable ndk release.

Imbricate answered 3/5, 2017 at 5:13 Comment(0)
T
0
  1. Check your ndk path in local.properties file in project folder. It shows ndk-bundle path for building makefiles.

    ndk.dir=/Users/../Library/Android/sdk/ndk-bundle
    
  2. Check build scripts in gradle file. This script shows where shared libs should be located:

    sourceSets.main {
       jni.srcDirs = []
       jniLibs.srcDir 'src/main/libs'
    }
    

    And this shows makefile path for ndk-building:

    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
    

Check my another answer also, maybe it'll help you. Linking shared libraries

Tombac answered 3/5, 2017 at 5:29 Comment(3)
I obviously declared the ndkBuild and the ndk-tools path, because it compiles and executes the makefile script. I tried to set jniLibs.srcDir 'src/main/libs' but I am not sure what it is supposed to do thoughImbricate
@NumLock did you try building with terminal? Just go to jni folder, and run ndk-build. If it build shared libraries, then check your gradle scripts again.Tombac
I used windows command line and as I mentioned, ndk-build copies the files to the respective directories, but only if I skip the -n flagImbricate

© 2022 - 2024 — McMap. All rights reserved.