build opencv 3.0 for android with extra modules - android

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.

Related

Using protobuf to communicate between JNI and Unity

My Unity game is using a Android library. They communicate by sending strings over a JNI bridge. Now I want to send protobuf messages over that bridge instead. I already have Google protobuf as a dependency in both Unity and my Android library Project. However I'm not sure how to go ahead.
What I did
create a .proto file?
download protoc for compiling the .proto file for both Unity (c#) and Android (Java)
add the compiled files to the repective projects
In the Android / Java part, everything seems to compile fine. However in Unity I'm getting a ton of compilation errors when adding the compiled .proto file ( == auto generated file)
Here as a placeholder the first compilation error:
Assets\MyApp\ProtobufExample\Detection.cs(62,13): error CS0234: The type or namespace name 'IBufferMessage' does not exist in the namespace 'Google.Protobuf' (are you missing an assembly reference?)
To me this looks like my GoogleProtobuf dependency is not up to date with the compiler, but this is just a guess.
Update
It was a dependency problem. Apparantly I cannot use the latest protobuf compiler (v3.20), as it adds more dependencys that are unknown to the Protobuf library inside Unity. As pointed out in the protobuf github issues, an old version (v3.0) does the trick.
Now I don't have any compilation issues anymore. However I'm getting runtime issues. JNI is complaining that
System.Exception: JNI: Unknown signature for type 'My.Proto.Example.DetectionType' (obj = My.Proto.Example.DetectionType) equal
Could be still an issue of the protoc version being different for Java and C#. Looking at the gradle file I have "protoc:3.18.0" there which indeed might be incompatible with v3.0 which I needed for Unity.
Downgrading Java protobuf leads to gradle compilation errors Unknown generator option: lite.
If anyone has ever done this, could you please recommend a version number that works for both Uniy and Java
I've also had this problem, I've solved it by upgrading the plugin version (to 2.46) in unity. This allows me to use the newest version of protobuf (3.20) and grpctool (2.45). The plugin is provided by official grpc, you can download it here.

WebRTC/MediaSoup library conflict with Gradle build

I am trying to user both MediaSoup and WebRTC libraries in my app.
Separately it works flawlessly, but when trying to add both in the same project I have some conflicts.
It's either:
I add both mediasoup ('org.mediasoup.droid:mediasoup-client:3.0.8-beta-3') and webRTC ('org.webrtc:google-webrtc:1.0.32006') in my project, I can sync my gradle. But when trying to build the project, I get an error saying that I got a lot of duplicated class, as such:
Duplicate class org.webrtc.AndroidVideoDecoder found in modules jetified-google-webrtc-1.0.32006-runtime.jar (org.webrtc:google-webrtc:1.0.32006) and jetified-mediasoup-client-3.0.8-beta-3-runtime.jar (org.mediasoup.droid:mediasoup-client:3.0.8-beta-3)
I add only WebRTC library: impossible to use MediaSoup so not a solution
I add only MediaSoup. So far I can compile and even build my app, but it crashes on the first statement where I use WebRTC, on:
PeerConnectionFactory.initialize()
AS is telling me that the native lib is not found:
java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[zip file ".../base.apk"],nativeLibraryDirectories=[/data/app/dev.arvuz-fuhAdJV_sT2-PQyEHP0vxg==/lib/arm64, /data/app/dev.arvuz-fuhAdJV_sT2-PQyEHP0vxg==/base.apk!/lib/arm64-v8a, /system/lib64]]] couldn't find "libjingle_peerconnection_so.so"
So, that's where I am stuck. How (is it even possible?) to use WebRTC in combination with MediaSoup libraries on Android?
I tried excluding some WebRTC module in my gradle file but couldn't achieve anything.
It's possible that the MediaSoup and webRTC dependencies are using different versions of the same library code under the hood. The namespace of these different versions could collide at runtime when the JVM tries to lookup some native method that's only present in one of the versions. If this is the case, you must use the version of MediaSoup and webRTC that share the same library version.

Equivalent of 'compileOnly' in Android.mk

I have a pre-built java library as a compile time dependency for Android library project(AAR). So while building it in Android Studio, 'compileOnly' is used so that the same gets linked in runtime when deployed with an APK.
However, I should also write an equivalent Android.mk for the library project. I am not able to find any reference to include a prebuilt java library in Android.mk. Can someone help me on this part.
I tried using LOCAL_PREBUILT_JAVA_LIBRARIES attribute, but the system threw an error:
error: dont use LOCAL_PREBUILT_JAVA_LIBRARIES anymore LOCAL_PATH=xxx.
This kind of dependency linking may look strange. Let me give some insight into it also. Basically I am building an application that has one small part being developed by a third party. The setter interface APIs for the third party are shipped in by me in the form of a .jar file so that they use the same as a compile time dependency and build an AAR out of it.
Now the third party project is to be included in my project build(AOSP). This brings a dependency that their module should be compiled for the AAR to get generated and my project uses that AAR to generate the APK.
For the AAR to get compiled and built, I need to link the prebuilt java interface library that is shipped in by me(mentioned in the first step).
Need an equivalent of 'compileOnly' used in build.gradle.

Android Studio C++ NDK library example

I would like to download some working example of Android Studio NDK project with C or C++ which will be compiled to .so library (or APK from which I can extract .so).
I have tried ndkbuild with Android.mk build and also CMake with CMakeLists.txt, official and unofficial tutorials on Windows...
If I try them on android from same app (java), it is working but I want to use NDK in Unity3D on android and I keep getting DllNotFoundException.
I uploaded my Android and Unity projects to github.
First of all, here is a sample Android Project plugin you are looking for.
It's very important to know how to do this yourself.
This used to be hard to do before but the latest Android Studio made it easier to now use C/C++ or generate .so library easily. Update Android Studio to the latest version then follow steps below to create a C++ plugin.
1.Create a new Project in Android Studio
2.Check the Include C++ suport to enable C++.
3.On the Dropdown Menu, check C++ 11 on the C++ Standard drop-down menu. You will need C++ 11 to actually use most useful C++ features. Also, enable exception or frtti if you need them.
That's really it.
When you build the plugin:
The debug library is should be at:
\app\build\intermediates\cmake\debug\obj\
The release library is should be at:
\app\build\intermediates\cmake\debug\obj\
If you only see the debug but not the release version of the plugin, check here for how to make it appear.
Possible reasons you are getting DllNotFoundException on Android:
1.You did not wrap the C/C++ function around extern "C". You must do this for each function in the .cpp file or you do it in the function in the .h file.
2.You put the plugin in the wrong Unity folder.
The armeabi-v7a and x86 plugins generated at <ProjectDirectory>\app\build\intermediates\cmake\release\obj should be placed at Assets\Plugins\Android\libs\armeabi-v7a\ and Assets\Plugins\Android\libs\x86\ in the Unity project.
Make sure to spell these correctly. See this for more information about this.
3.You are loading it incorrectly from the C# side.
Let's say that the name of the plugin is libScreenshot.a, do not include the lib prefix, also do not add the .a when loading it.
[DllImport("Screenshot", CallingConvention = CallingConvention.Cdecl)]
public static extern void takeScreenshot();

How can you add external dependencies to bazel

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.

Categories

Resources