I want to use dlib library in my android project which is written in c++.
I selected c++ language because it will support iOS also.
So I follow these steps:
I created android ndk project and I included that dlib library
directly in my c++ code folder.
I import .h files and I generated a app gradle file in android studio
project.
But when I am getting library .h files errors, means internal .h files getting errors.
Error:error: linker command failed with exit code 1 (use -v to see invocation)
Error:Build command failed.
Error:org.gradle.internal.UncheckedException:
Related
My client is requesting I package CommonCrypto inside their app and not use the version supplied by the OS.
I haven't found any pre-built distributions, but I found the source code (sans build instructions). Is there a simple way to build from source?
I tried using ndk-build, but I see the following error:
Android NDK: ERROR:Android.mk:corecrypto: LOCAL_SRC_FILES points to a missing file
Android NDK: Check that /SWE/release/Software/Harissa/Updates/BuiltHarissa/Roots/corecrypto/prebuilts/armeabi-v7a/libcorecrypto.so exists or that its path is correct
/Users/rajohns/Library/Android/sdk/ndk/21.0.6113669/build/core/prebuilt-library.mk:45: *** Android NDK: Aborting . Stop.
And as seen in the Android.mk file, the corecrypto module does in fact point to an unknown /SWE/release/Software/Harissa/Updates/BuiltHarissa/Roots/corecrypto directory.
I'm trying to get C++ code to work with react-native (see this for the general steps).
I've generated my project with react-native init, generated the JNI bindings by using Djinni. I'm now trying to build the application and test it on my android emulator (cd $PROJECT_ROOT/android && ./gradlew installDebug). It seems like the header files aren't found, their directories aren't included :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:6:10: fatal error: 'cpp_bridge_text.hpp' file not found
#include "cpp_bridge_text.hpp"
^~~~~~~~~~~~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
I managed to get past this small issue by creating hard links to the headers causing issues. Which leads me to this :
> ./gradlew installDebug
(...)
:app:compileDebugJavaWithJavac UP-TO-DATE
:app:compileDebugNdk
Warning: Deprecated NDK integration enabled by useDeprecatedNdk flag in gradle.properties will be removed from Android Gradle plugin soon.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
https://developer.android.com/studio/projects/add-native-code.html
or use the experimental plugin:
http://tools.android.com/tech-docs/new-build-system/gradle-experimental.
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.cpp:4:
In file included from $PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.hpp:7:
$PROJECT_ROOT/app/src/main/jni/djinni_support.hpp:20:10: fatal error: 'exception' file not found
#include <exception>
^~~~~~~~~~~
1 error generated.
make: *** [$PROJECT_ROOT/android/app/build/intermediates/ndk/debug/obj/local/armeabi-v7a/objs/app/$PROJECT_ROOT/android/app/src/main/jni/NativeCppBridgeText.o] Error 1
:app:compileDebugNdk FAILED
FAILURE: Build failed with an exception.
In this case, it seems like even standard libraries aren't included.
My question is : how do I explicitly specify gradle to add directories to its search/indlude path?
In regular Android projects, it seems that you can edit Android.mk/Application.mk files. There aren't such files in my folders ; I think that gradle actually generates an Android.mk file (in $PROJECT_ROOT/android/app/build/intermediates/ndk/debug/Android.mk), I tried editing it (LOCAL_C_INCLUDES field) to add my directories, but it gets overwritten when I try another build.
Thanks in advance.
You can edit this in $PROJECTROOT/android/app/build.gradle :
android {
defaultConfig {
(...)
ndk {
(...)
cFlags = "-Ipath/to/directory/"
}
}
}
However, you will most likely encounter other issues (I know that for a fact, because I did). I'd recommend you to use the modern and user-friendly CMake integration.
I'm gonna write down the general steps so that I can find it again sometime in the future :
Add your files to the android project (under android studio or another IDE). There should be files in your java/ folder, files in your jni/ folder (JNI bridge files), and files in your cpp/ folder (the native C++).
Add a CMakeLists.txt file to your module (usually named app if you're using react-native).
In this file, respect the following structure :
cmake_minimum_required(VERSION 3.4.1)
add_library( # Name of the library
$(YOUR_LIBRARY_NAME)
# Sets it as a shared library
SHARED
# Relative path to the source file(s)
path/to/your/file.cpp path/to/other/file.cpp )
# Allows you to add folders to the search path : similar to -Ipath/to/your/headerfolder/
include_directories(path/to/your/headerfolder/)
# Allows you to have special compilation flags for the specified library's compilation
target_compile_options( $(YOUR_LIBRARY_NAME)
PRIVATE # You can also use PUBLIC/INTERFACE
-std=gnu++11 ) # Your option ; I needed this in my case
Once it's done, you need to link gradle to your native library :
If you're using android studio, just use the information available in this guide as it's very well explained.
If you aren't, I also advise you to check out this guide, because it's really well explained.
After that, you can either build the project in android studio, or cd $(PROJECTROOT)/android && ./gradlew installDebug. It should work.
Good luck!
I'm trying to build the SoundTouch library for Android, by following the guide provided within the source code:
Compiling
To compile the SoundTouch library source codes into an Android native
library, open Cygwin/bash shell, go to directory
"soundtouch/source/Android-lib/jni" and invoke the NDK compiler with
following command:
$NDK/ndk-build
This will build binaries for all the supported Android platforms
(arm-v5, arm-v7, X86, MIPS etc) of SoundTouch library, plus the JNI
wrapper interface as discussed below. The target binaries will be
built into the "libs" subdirectory. As long as all these .so binary
library versions are included in the APK Application delivery package,
the targer Android device can choose the correct library version to
use.
Notice that to allow Cygwin/bash to locate the NDK compile scripts,
you need to define the location of the NDK installation defined in
environment variable "NDK". That's easiest done by adding the NDK path
definition at end of your ~/.bash_profile file, for instance as
follows:
NDK=/cygdrive/d/Android/android-ndk-r6
to do this I go into Terminal in the SoundTouch/source/android-lib/jni directory and type the following commands:
export ANDROID_NDK=~/Android/Sdk/ndk-bundle
export NDK_ROOT=$ANDROID_NDK
export PATH=${PATH}:${ANDROID_NDK}
ndk-build
Then I get the following error:
[arm64-v8a] Compile++ : soundtouch <= soundtouch-jni.cpp
jni/soundtouch-jni.cpp:23:10: fatal error: '../source/SoundStretch/WavFile.h'
file not found
#include "../source/SoundStretch/WavFile.h"
^
1 error generated.
/home/daniele/Android/Sdk/ndk-bundle/build/core/build-binary.mk:499: recipe for target 'obj/local/arm64-v8a/objs/soundtouch/soundtouch-jni.o' failed
make: *** [obj/local/arm64-v8a/objs/soundtouch/soundtouch-jni.o] Error 1
If I go to that directory the file is there though. Here is a screenshot of the file with it's direcotry:
I'm having a hard time setting up PowerVR SDK for Android on Windows 8 64, assuming I met all requirements:
Android SDK (fresh Eclipse)
Android NDK
Cygwin (with make)
PowerVR Android SDK 3.0
I can perfectly make and run an Android NDK sample. However, the same process fails for building any PowerVR sample (from the SDK). Here's the output when I try to run the makefile:
$ ndk
Compile++ thumb : OGLES2Texturing <= OGLES2Texturing.cpp
arm-linux-androideabi-g++.exe: error: C:/cygwin///cygdrive/c/Users/stfn/workspaces/android/03_Texturing/jni/OGLES2Texturing.cpp: No such file or directory
arm-linux-androideabi-g++.exe: fatal error: no input files
compilation terminated.
/cygdrive/c/android-ndk-r8d/build/core/build-binary.mk:269: recipe for target `obj/local/armeabi/objs/OGLES2Texturing//cygdrive/c/Users/stfn/workspaces/android/03_Texturing/jni/OGLES2Texturing.o' failed
make: * [obj/local/armeabi/objs/OGLES2Texturing//cygdrive/c/Users/stfn/workspaces/android/03_Texturing/jni/OGLES2Texturing.o] Error 1
I suppose the error should be related to a wrong path given to the compiler. To me it looks like a mixture of standard Windows and Cygwin/Unix paths: * C:/cygwin///cygdrive/c/Users/stfn/...*
If been through so many makefiles now trying to resolve this issue but I just don't know where else to look. This is the first time I tried messing with the NDK. I'm afraid this could be my last.
Any help would be greatly appreciated
1.in the Android.mk file, for the PVRSDKDIR, set the path of your project folder in your workspace.
2.Copy the build, tools, and shell folders from the powervr sdk folder to your project folder
I want to know how to build libav on windows7 using cygwin. I've tried the following steps :
1-change the directory using cd command to libav_file_directory/android(android folder is empty where the .so file will be saved as far as my knowledge is concern).
2-execute the ./ndk-buil command.
I got the following as result:
*Android NDK: Could not find application project directory !
Android NDK: Please define the NDK_PROJECT_PATH variable to point to it.
/cygdrive/c/Users/balwant.singh.TA/Desktop/Android/android-ndk-r8/build/core/build-local.mk:130: * Android NDK: Aborting . Stop.*
plese reply with solution, and also I want to know which all android media player uses the libav as their native code.
1.)Set all your paths(Java_Home
2.)Set NDK_HOME to Ndk-Build Path
3.)Run Cygwin
4.)GO to project Library path
5.)Run make command
6.)then Run ndk-build