I am currently trying to create a library file (e.g. .so) from an existing and working OpenGL C++ Visual Studio 19 project.
My plan is to create this library to call functions from the VS-project within Android Studio, as I am trying to extend the AR-Core sample "Hello_AR_c" which should ultimately create an android .apk containing my OpenGL C++ functionality.
I am using Windows 10-64 and Visual Studio19 as well as the current version of Android Studio.
I attempted to create a new Static Library (Android) project in VS and add it to my working solution. After that I included my existing source code files from my OpenGL project and tried to build the android project as ".so".
After fixing some errors which did not appear in the original project I struggled to get rid of the errors in "GLU.h", which prevents me from building it. Nevertheless I am unsure if solving the errors will lead to a compiling and correctly working version.
Error examples:
E0338 more than one instance of overloaded function "gluQuadricCallback" has 'C' linkage GLU.h 232
void APIENTRY gluQuadricCallback(GLUquadric *qobj,GLenum which, void (CALLBACK* fn)())
E0018 expected a ')' GLU.h 364
typedef void (CALLBACK* GLUquadricErrorProc) (GLenum);
I expect that this errors come from a different platform toolset or something similar, as in my android project it is Clang 5.0, where as in my working project it is set to Visual Studio 2017.
Does somebody have any idea for this problem of mine? Is there maybe an easier way to combine a visual studio OpenGL project with an Android studio project?
Thank you in advance.
Error examples:
Android Config - Not building:
OpenGl project - working:
Related
I tried to compile a .so library using Visual Studio 2019 along with OpenCV Android in order to use this library in Unity.
There are some answers on how to configure Visual Studio to use OpenCV Android (here or here) but none of these work for me. Below you can see my configurations.
Visual Studio 2019 (running on Windows 10)
android-ndk-r21e // also tried with android-ndk-r15c android-ndk-r16b and android-ndk-r17c
OpenCV Android 4.5.2 // also tried with OpenCV Android 4.0.0, 4.0.1 and 4.1.0
My settings in Visual Studio 2019 look as follows:
Configuration Properties
- General
Platform Toolset Clang 5.0 (also tried Clang 3.8 or GCC 4.9)
Configuration Type Dynamic Library (.so)
Target API Level Nougat 7.0 (android-24) (also tried different versions)
Use STL LLVM libc++ static library (c++_static) (also tried "GNU STL static library (gnustl_static)")
C/C++
- General
Additional Include Directories "Path to OpenCV_4_5_2_Android\sdk\native\jni\include"
Code Generation Enable C++ Exceptions "Yes(-fexceptions)"
Language C++17(-std=c++1z)
Precompiled Headers Not using Precompiled Headers
Linker
- General
Additional Library Directories Path to OpenCV_4_5_2_Android\sdk\native\libs\armeabi-v7a
- Input
Additional Dependencies Path to OpenCV_4_5_2_Android\sdk\native\libs\armeabi-v7a\libopencv_java4.so
My Source.cpp I try to compile is just a single function for testing purposes
#include <opencv2/core.hpp>
extern "C" float test(float a, float b)
{float c = a * b; return c;}
Which gives me the following errors:
E0035 #error directive: This constructor has not been ported to this platform
E0020 identifier "__fp16" is undefined
use of undeclared identifier 'ANDROID_LOG_INFO'
The ANDROID_LOG_INFO error can be fixed when I add #include "android/log.h" at the top of the file that throws this error. But the other two errors still remain.
I had the exact same issue as you (though I used c++ 11) with the exact same setup, and struggled for days. I believe the errors you're seeing (like me) are from arm_neon.h. Very oddly, I was able to just build (not run) the .so successfully, even with those errors (I say "errors" because if you look at arm_neon.h, others pop up), so try it. Maybe it's some kind of IntelliJ/Intellisense mistake more than anything else where it's catching false negatives from some other toolchain setup.
At the same time, I'm not 100% sure I was always able to build with that issue, so try these steps as well if you can't:
use OpenCV 4.0.1 with Android NDK 16rb. The NDK matters when it comes to OpenCV builds, and this is the only supposed match that I know of.
follow this tutorial from scratch: https://amin-ahmadi.com/2019/06/03/how-to-use-opencv-in-unity-for-android/
if the downloaded OpenCV android SDK is still giving trouble, build OpenCV from the source using his other tutorial here: https://amin-ahmadi.com/2019/02/03/how-to-build-opencv-4-x-for-native-android-development/
and then repeat step 2.
MAJOR EDIT:
OpenCV 4.5.2 needs to be treated differently because it no longer uses toolchains with gnu c++.
-When you build OpenCV from CMake, build with Android NDK 21e, and do not use the toolchain in OpenCV 4.5.2. Use the one inside the Android NDK's build folder (android-ndk-r21e\build\cmake).
-When you build your .so from Visual Studio 2019, do not use the GNU STL, use the LLVM. GNU c++ is no longer part of Android NDKs, and you need to cut it out of the process entirely.
-In the Linker Input, put the names of your library files (or file, if it's just the world one) in the Library Dependencies field, not the Additional Dependencies field.
-Everything else is the same as in those common tutorials.
I have just formatted my computer and reinstalled android studio and sdk & ndk. I've created a new project but now I can't build it with c++ source because I keep getting this error:
.../x86_64-linux-android/bin\ld: error: cannot find -l1
I am not event linking a library called "1". What is it for?
Seems like latest ndk or android-studio has some sort of naming problem or I had a problem when installing it.
I was linking the android library
find_library(ANDROID android)
target_link_library(... ${ANDROID})
but it seems like ${ANDROID} was set to 1. I set it to "android" by hand and now it compiles as expected.
One of the first things the CMake toolchain file does is set(ANDROID TRUE) to indicate that the build is targeting Android. You can't use ANDROID as a variable name in your CMakeLists.txt because it's already used. Best to assume that anything prefixed with ANDROID is part of the implementation.
I am a student and currently working on a project where I am trying to connect my game that which I have created with Android Studio. A neural network has also been made with Tensorflow which is going to be used for the android game.
The problem is that Android Studio uses a build tool which is called Gradle and Tensorflow uses Bazel. To solve this problem I have been trying to build my android game with Bazel but I am stuck at the part where I have to add the used external dependencies. For the game I use the following dependencies:
Appcompat
Support
Percent
Which supposedly should come with the android support repository.
I have looked at http://www.bazel.io/docs/external.html and several other sources but I still do not understand how I can add the dependensies. Could someone provide me with an example how to do it with for example appcompat and what I have to do to make it work? Or is there another way which would be easier?
EDIT: I have have been succesful in building the android example of Tensorflow but this: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/android
But it doesn't include dependensies which I am using.
You may want to look at the Makefile support we just added for Android:
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile
It's still very experimental (and fiddly), but should let you build a static library that you can more easily use in your gradle project.
Nevermind I resolved my issues, after removing the depensies I checked the WORKSPACE file. It seems I didn't set the package correctly, my bad.
I built the OpenCV 3.0 beta with extra modules. The build was without java libraries and that was the only way that I was able to build the OpenCV 3.0 beta without getting errors and there is no problem because I only need the native part.
The problem that I have is when I try to implement the text module I get an error that the library canĀ“t be resolved. The line to implement the library is this:
#include <opencv2/text.hpp>
So my question is: What can I do to resolve this problem? Do I have to move some include files to some location?
Note that OCRTesseract class (inside of opencv2/text.hpp) provides an interface with the tesseract-ocr API (v3.02.02) in C++ and it is compiled only when tesseract-ocr is correctly installed.
First of all you should compile tesseract (and its dependencies) to Android.
I have a similar issue as in the SO question below, but with scala as my language of choice:
Android project referencing "normal" java project in eclipse since sdk tools update 17
Basically, if I setup a regular android project using java,
a regular java library project and a 'glue' android library project as described in the link above, everything works fine and I can use code from my referenced regular java project.
However, if I try to repeat the same procedure using scala projects I get a noclassdeffound exception when launching. (If I move the code form the regular referenced project into the main android project the error disappears and everything works.)
Any hints on what to look for? Anyone doing the same with success?