Closed patuoynageek closed 3 years ago
Found the issue, add_custom_command
isn't catered for other project's paths
need to change the path in
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -R .comment -g -S -d --strip-unneeded ${CMAKE_HOME_DIRECTORY}/../../../build/intermediates/cmake/${CMAKE_BUILD_TYPE}/obj/${ANDROID_ABI}/libnative-lib.so
accordingly to the exported project
Same Issue occurs to me, what's the fix?
FAILED: /Users/hariprasanth.ramesh/StudioProjects/DetectFrida/app/build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so : && /Users/hariprasanth.ramesh/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=aarch64-none-linux-android21 --gcc-toolchain=/Users/hariprasanth.ramesh/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/hariprasanth.ramesh/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -fno-limit-debug-info -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libnative-lib.so -o /Users/hariprasanth.ramesh/StudioProjects/DetectFrida/app/build/intermediates/cmake/debug/obj/arm64-v8a/libnative-lib.so CMakeFiles/native-lib.dir/native-lib.c.o -llog -latomic -lm && cd /Users/hariprasanth.ramesh/StudioProjects/DetectFrida/app/.cxx/cmake/debug/arm64-v8a && /Users/hariprasanth.ramesh/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip -R .comment -g -S -d --strip-unneeded /Users/hariprasanth.ramesh/StudioProjects/DetectFrida/app/src/main/c/../../../build/intermediates/cmake/Debug/obj/arm64-v8a/libnative-lib.so /bin/sh: /Users/hariprasanth.ramesh/Library/Android/sdk/ndk/23.1.7779620/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android-strip: No such file or directory ninja: build stopped: subcommand failed.
@darvincisec @patuoynageek
Hola, ¿podría aconsejarme si estos pasos son correctos para importar esta biblioteca a otro proyecto?
Estoy haciendo lo siguiente:
- Copie toda la
c
carpeta enmain
la carpeta- Comente la biblioteca OLLVM en CMake
- Actualizar
app/build.gradle
externalNativeBuild { cmake { path "src/main/c/CMakeLists.txt" version "3.10.2" } }
- Actualizar raíz
build.gradle
aclasspath 'com.android.tools.build:gradle:4.1.3'
- Actualizar
gradle-wrapper.properties
adistributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
- Agregar
System.loadLibrary("native-lib")
Hice los pasos anteriores para diferentes proyectos y a continuación está mi resultado.
- [x] Clon de este proyecto de repositorio
- [x] Proyecto Kotlin en blanco ( Todos los proyectos en blanco creados a partir de Android Studio Arctic Fox (2020.3.1) )
- [x] Proyecto Java en blanco
- [x] Proyecto Kotlin existente
- [ ] Proyecto Flutter en blanco a través del código nativo de Kotlin
- [ ] Proyecto de complemento Flutter en blanco a través de dart: ffi
No estoy seguro de si puede ayudar con esto, pero tengo problemas para agregar esta biblioteca a los proyectos de Flutter.
Error de Gradle que obtengo:
Launching lib/main.dart on SM G920F in debug mode... Running Gradle task 'assembleDebug'... FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':native_add:externalNativeBuildDebug'. > Build command failed. Error while executing process /Users/nageek/Library/Android/sdk/cmake/3.10.2.4988404/bin/ninja with arguments {-C /Users/nageek/Documents/Workplace/native_add/android/.cxx/cmake/debug/armeabi-v7a native-lib} ninja: Entering directory `/Users/nageek/Documents/Workplace/native_add/android/.cxx/cmake/debug/armeabi-v7a' [1/1] Linking C shared library /Users/nageek/Documents/Workplace/native_add/example/build/native_add/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so FAILED: /Users/nageek/Documents/Workplace/native_add/example/build/native_add/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so : && /Users/nageek/Library/Android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang --target=armv7-none-linux-androideabi16 --gcc-toolchain=/Users/nageek/Library/Android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64 --sysroot=/Users/nageek/Library/Android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -shared -Wl,-soname,libnative-lib.so -o /Users/nageek/Documents/Workplace/native_add/example/build/native_add/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/native-lib.c.o -llog -latomic -lm && cd /Users/nageek/Documents/Workplace/native_add/android/.cxx/cmake/debug/armeabi-v7a && /Users/nageek/Library/Android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip -R .comment -g -S -d --strip-unneeded /Users/nageek/Documents/Workplace/native_add/android/src/main/c/../../../build/intermediates/cmake/Debug/obj/armeabi-v7a/libnative-lib.so /Users/nageek/Library/Android/sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-strip: '/Users/nageek/Documents/Workplace/native_add/android/src/main/c/../../../build/intermediates/cmake/Debug/obj/armeabi-v7a/libnative-lib.so': No such file ninja: build stopped: subcommand failed. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org BUILD FAILED in 17s Exception: Gradle task assembleDebug failed with exit code 1
como solucionaron ?
Build command failed. Error while executing process C:\Users\Priyesh\AppData\Local\Android\Sdk\cmake\3.10.2.4988404\bin\ninja.exe with arguments {-C D:\Novopay\novopay-platform-digi-distribution-app\app.cxx\Debug\6g1o2x5t\armeabi-v7a native-lib} ninja: Entering directory `D:\Novopay\novopay-platform-digi-distribution-app\app.cxx\Debug\6g1o2x5t\armeabi-v7a' [1/2] Building C object CMakeFiles/native-lib.dir/native-lib.c.o [2/2] Linking C shared library D:\Novopay\novopay-platform-digi-distribution-app\app\build\intermediates\cxx\Debug\6g1o2x5t\obj\armeabi-v7a\libnative-lib.so FAILED: D:/Novopay/novopay-platform-digi-distribution-app/app/build/intermediates/cxx/Debug/6g1o2x5t/obj/armeabi-v7a/libnative-lib.so cmd.exe /C "cd . && C:\Users\Priyesh\AppData\Local\Android\Sdk\ndk\20.1.5948944\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe --target=armv7-none-linux-androideabi21 --gcc-toolchain=C:/Users/Priyesh/AppData/Local/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/Priyesh/AppData/Local/Android/Sdk/ndk/20.1.5948944/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o D:\Novopay\novopay-platform-digi-distribution-app\app\build\intermediates\cxx\Debug\6g1o2x5t\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/native-lib.c.o -llog -latomic -lm && cmd.exe /C "cd /D D:\Novopay\novopay-platform-digi-distribution-app\app.cxx\Debug\6g1o2x5t\armeabi-v7a && C:\Users\Priyesh\AppData\Local\Android\Sdk\ndk\20.1.5948944\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-strip -R .comment -g -S -d --strip-unneeded D:/Novopay/novopay-platform-digi-distribution-app/app/src/main/c/../../../build/intermediates/cmake/Debug/obj/armeabi-v7a/libnative-lib.so"" C:\Users\Priyesh\AppData\Local\Android\Sdk\ndk\20.1.5948944\toolchains\llvm\prebuilt\windows-x86_64\bin\arm-linux-androideabi-strip: 'D:/Novopay/novopay-platform-digi-distribution-app/app/src/main/c/../../../build/intermediates/cmake/Debug/obj/armeabi-v7a/libnative-lib.so': No such file ninja: build stopped: subcommand failed.
@patuoynageek @darvincisec can you give suggestions how to resolve this issue. I am trying to add this C module in another project. TIA
In my case i fixed this issue by changing the path in add_custom_command
in CMakeList.txt
FROM :
add_custom_command( TARGET native-lib
POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -R .comment -g -S -d --strip-unneeded ${CMAKE_HOME_DIRECTORY}/../../../build/intermediates/cmake/${CMAKE_BUILD_TYPE}/obj/${ANDROID_ABI}/libnative-lib.so
COMMENT "Stripped native library")
TO :
add_custom_command( TARGET native-lib
POST_BUILD
COMMAND "${ANDROID_TOOLCHAIN_PREFIX}strip" -R .comment -g -S -d --strip-unneeded ${CMAKE_HOME_DIRECTORY}/../../../build/intermediates/cxx/${CMAKE_BUILD_TYPE}/6g1o2x5t/obj/${ANDROID_ABI}/libnative-lib.so
COMMENT "Stripped native library")
The Solution is: If parent folder of project has space or unsupported characters in folder's name, it all because of this.
Example : C:/users/user/desktop/Android Studio Projects/Application Folder Change: Android Studio Projects => AndroidStudioProjects
it worked for me
Hi, would you be able to advise if these steps are correct for importing this library to another project?
I am doing the followings:
c
folder intomain
folderapp/build.gradle
build.gradle
toclasspath 'com.android.tools.build:gradle:4.1.3'
gradle-wrapper.properties
todistributionUrl=https\://services.gradle.org/distributions/gradle-6.7-all.zip
System.loadLibrary("native-lib")
I did the above steps to different projects and below is my result
Not sure if you are able to help with this but I am having issues adding this library to Flutter projects
Gradle Error that I get: