I am trying to build openCV 3.0 library with contrib modules for my Java project. I am using CMake 3.4 and Microsoft Visual Studio 2013. In CMake I successfully generate data. Then I am opening ALL_BUILD project in Visual Studio and building it without errors. After build I've got openCV-300.jar and many other files with extensions *.exe, *.dll, *.iik, *.pdb. What I need is file opencv_java300.dll and it is also there however it's greatly smaller than original opencv_java300.dll from standard library. Also when I try to run my simple app I get:
java.lang.UnsatisfiedLinkError: ..\lib\x64\opencv_java300.dll: Can't find dependent libraries
Of course If I am using files from standard openCV version it is working like it supposed to. So my question is what am I doing wrong?I have got contrib library from here https://github.com/itseez/opencv_contrib and I am building library following guide from here https://github.com/Itseez/opencv_contrib/blob/master/README.md (How to build OpenCV with extra modules - cmake-gui part).
EDIT: I had to add directory to all generated files into PATH variable and it worked. But I am still searching for a different solution.
Related
I prefer eclipse over android studio, my question is if I can still use it to build projects for future development - for example the recycleview library. It is supported in eclipse too, but will future google libraries continue to support it?
My second question is, if I'm using eclipse to make an app, will it be run on new devices too, as the project structure is different in eclipse and android studio.
My final question is how can I use libraries from android arsenal if I don't use android studio (all the libraries there are for maven and gradle)?
I prefer eclipse over android studio, my question is if I can still use it to build projects for future development - for example the recycleview library. It is supported in eclipse too, but will future google libraries continue to support it?
In the end, it is all just Java, XML, and other such resources. The RecyclerView library is no exception- it is just a library that can be used in any IDE.
The IDE you use for development is just a tool to view and edit these project files. Separately, you use a build system to build the application. Your IDE, the build system, and the project files are completely separate and one doesn't depend on the other to create a functioning application. In fact, you can build an Android application without an IDE at all.
The biggest issue you might run into here is the format of libraries such as RecyclerView. In the Eclipse days (note that Eclipse Android projects typically use Ant for building), most libraries came as either JAR files or Android libraries (of source code). With the release of Android Studio and the Android Gradle plugin, everything is shifting towards Gradle dependencies.
Also be aware that Google is not going to continue supporting Eclipse development. The tools for building Android application in Eclipse will not continue to receive updates, so bugs may pop up in the future that prevent you from continuing to use it effectively.
My second question is, if I'm using eclipse to make an app, will it be run on new devices too, as the project structure is different in eclipse and android studio.
The output of building an Android application is the same regardless of how or where you build it - you get an APK with the same file structure. The structure of the built APK is independent of the structure of the source code.
My final question is how can I use libraries from android arsenal if I don't use android studio (all the libraries there are for maven and gradle)?
Eclipse can use both Gradle and Maven for building. If you want to use libraries as Gradle or Maven dependencies, you will need to set up your project to use either Maven or Gradle to build instead of Ant. Otherwise you can still find JARs for most projects that don't rely on the Android framework, or you will need to get the source code for the library and set it up as a project dependency yourself.
What I need to do:
Compile the SDL2 source into an .so file for x86 and ARM64 architecture
Reference this file in Xamarin.Android
Call the SDL2 methods in my C# code.
Things I've learned so far:
SDL2 requires a Java Activity or JNI bindings to invoke the native code.
I cannot proceed without somehow integrating SDL2 libs and a JNI to the Xamarin.Android project.
I am incapable of solving this problem and my brain has fried in the process.
Things I've tried:
Outdated GitHub projects:
https://github.com/0x0ade/SDL2Droid-CS
https://github.com/fallahn/sdl2vs
This blog post that lets me create C++ code but not using Xamarin
https://trederia.blogspot.com/2017/03/building-sdl2-for-android-with-visual.html
Running SDL2 through Android Studio which works but doesn't help me as I need to invoke my C# code.
I don't have extensive Xamarin knowledge so I'm not sure how to do this, I can really use another pair of eyes right now. The SDL2Droid-CS GitHub project should theoretically work but I can't find a way to compile the SDL2 used in that project for the x86 emulator included in C#.
I tried compiling my code using armeabiv7 libsdl2.so and then running it directly on my phone. Unfortunately Visual Studio was unable to debug this thus making it difficult for me to implement my code.
Next I tried to debug the previously compiled app (using SDL2Droid-CS) through Android Studio and it gave me this error:
06-19 00:39:55.362 13143-13143/? I/zygote64: Late-enabling -Xcheck:jni
06-19 00:39:55.474 13143-13143/SDL2Droid_CS.SDL2Droid_CS W/ActivityThread: Application SDL2Droid_CS.SDL2Droid_CS can be debugged on port 8100...
06-19 00:39:55.514 13143-13143/? W/monodroid: Creating public update directory: `/data/user/0/SDL2Droid_CS.SDL2Droid_CS/files/.__override__`
Using override path: /data/user/0/SDL2Droid_CS.SDL2Droid_CS/files/.__override__
Using override path: /storage/emulated/0/Android/data/SDL2Droid_CS.SDL2Droid_CS/files/.__override__
Trying to load sgen from: /data/user/0/SDL2Droid_CS.SDL2Droid_CS/files/.__override__/libmonosgen-2.0.so
Trying to load sgen from: /storage/emulated/0/Android/data/SDL2Droid_CS.SDL2Droid_CS/files/.__override__/libmonosgen-2.0.so
Trying to load sgen from: /storage/emulated/0/../legacy/Android/data/SDL2Droid_CS.SDL2Droid_CS/files/.__override__/libmonosgen-2.0.so
Trying to load sgen from: /data/app/SDL2Droid_CS.SDL2Droid_CS-wmPu9Ce48QdJhvYc6bPRiA==/lib/arm64/libmonosgen-2.0.so
Trying to load sgen from: /data/user/0/SDL2Droid_CS.SDL2Droid_CS/files/.__override__/links/libmonosgen-2.0.so
06-19 00:39:55.515 13143-13143/? W/monodroid: Trying to load sgen from: /system/lib/libmonosgen-2.0.so
06-19 00:39:55.515 13143-13143/? A/monodroid: cannot find libmonosgen-2.0.so in override_dir: /data/user/0/SDL2Droid_CS.SDL2Droid_CS/files/.__override__, app_libdir: /data/app/SDL2Droid_CS.SDL2Droid_CS-wmPu9Ce48QdJhvYc6bPRiA==/lib/arm64 nor in previously printed locations.
Do you have a shared runtime build of your app with AndroidManifest.xml android:minSdkVersion < 10 while running on a 64-bit Android 5.0 target? This combination is not supported.
Please either set android:minSdkVersion >= 10 or use a build without the shared runtime (like default Release configuration).
The Min SDK was 19 so the error it gives is weird.
I'm assuming that SDL2 was not implemented properly which is leading to all these problems. The GitHub code has some holes and the person who uploaded it hasn't been active.
Resources:
SDL2 Website: https://www.libsdl.org/
SDL2 Source: https://www.libsdl.org/release/SDL2-2.0.8.zip
SDL2Droid GitHub Project: https://github.com/0x0ade/SDL2Droid-CS
GitHub Project from blog: https://github.com/fallahn/sdl2vs
Blog that explains building SDL2 in Visual Studio
TL;DR: Working files are here: https://github.com/MananAdhvaryu/Android-SDL2-Libraries
So I figured out the crash, it was cause due to the shared runtime that is implemented for debugging by Visual Studio. It was fixed by disabling Shared Runtime in the project settings.
Project Settings -> Android Options -> Untick "Use Shared Runtime"
1. As to why the GitHub Code didn't work:
It was due to broken .jar file in the "bindings" project. I was able to fix it by compiling the .jar file myself from the SDL2 source code. The .java file you need to compile are here, or you can get it from the source code.
Once you have the working .jar simply remove the existing .jar from the Jars folder and replace it with the new one.
If you can't generate the .jar file you can use the one in the GitHub project linked above
2. To create the .so files:
After that the necessary .so file for the processor architecture needs to be compiled. It is done using the Android NDK and a make script. The make script from the SDL2Droid GitHub works fine so I simply changed a few parameters to increase the android minSdkVersion to 19 and got the .so files for all the architectures (x86, x86_64, ARM, ARM64)
#!/bin/bash
NATIVEDIR=$(dirname "$0")
ndk-build -j 4 NDK_PROJECT_PATH="$NATIVEDIR/../SDL2Droid-CS" NDK_APPLICATION_MK="$NATIVEDIR/Application.mk"
This is the bash code to generate the .so files. If you are using Command prompt simply change the "$NATIVEDIR" to the absolute path of your project.
If you cannot generate these native libraries then you can use the one's from the above linked GitHub repository.
they require minimum sdk android-19 and are available for all supported architectures.
To use them simply place the libs folder in your Xamarin.Android project directory.
Call the SDL2 methods in my C# code.
There are official binging for C#. And this is the link on the official website:https://www.libsdl.org/languages.php.
You could download it and compile it to .dll file. Then add it as the reference to your project. You could call the methods by:
using SDL2;
SDL.SDL_SetHint(SDL.SDL_HINT_WINDOWS_DISABLE_THREAD_NAMING, "1");
I've created a simple library to get JSON responses and map it to Java Object.
I built a JAR using 'build with dependencies' in IntelliJ IDEA with JDK 1.8. However, this JAR works when used with other IntelliJ IDEA projects.
However when I add in Android Studio Project, I get this Error:com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
I found on Reddit that some user did the same (built JAR with IntelliJ Idea and Imported in Android Studio)
I think I am missing something or a way to create JAR file which is causing incompatibility to Android Studio. I'm pounding my head for hours with no luck.
For Android Studio, change File -> Project Structure -> SDK Location -> JDK Location to jdk1.7.x. For the command line, ensure java -version outputs java version "1.7.x".
I'm trying to make a cross-platform project using C++ on Windows and the Android NDK. I've been trying to put it together in one project with multiple build configurations, but I'm running into a problem for the Android build.
My project directory structure is as follows:
PROJECT/
src <- This has the Android SDK files
jni <- This has the Android NDK files
src-mp <- Multiplatform C++ code
src-pc <- Windows-specific code
gen
res
...
When building for Android, the src-pc folder contains code that doesn't compile and generates errors (it's using GLFW and GLEW, which doesn't seem to be compatible with Android). I right-clicked on it and hit
"Resource Configurations -> Exclude from Build".
However, the errors in src-pc are still being reported and so Eclipse refuses to run the application. I know the application runs on Android without the src-pc folder.
I suspect it's something with the indexer, but I can't get it to ignore the files in the src-pc folder. I've considered setting up a separate dependent project for Windows, but I was hoping that there was a way to put it all in one project. I've looked at the resource filters functionality, but I don't see a way to set filters for specific build configurations, so that doesn't help.
I already found that it's possible to delete the problem reports in the Problems tab, but doing that every time I build is a nuisance and I was hoping for a better fix.
I'm using Android NDK R9D and the SDK tools for API level 19. I'm on Eclipse Kepler. The toolchain being used for C++ compilation is Cygwin GCC with the Android Builder.
I am trying to make a basic sample from OpenCV android SDK work (color-blob-detector project).
I have followed all their instructions, downloaded the ADT bundle for windows 7 64 bit, the OpenCV SDK 2.4.9 and finally I imported the samples in my workspace and they appear in my package explorer.
Basically, in my package explorer I opened the OpenCV Library - 2.4.9 and OpenCV Sample - color-blob-detection projects.
In the sample project I receive an error regarding the imports from OpenCV particularly
The import org.opencv.android cannot be resolved
The import org.opencv.core cannot be resolved
The import org.opencv.imgproc cannot be resolved
However, these appear in the OpenCV Library - 2.4.9 project, but I do not know how to refer to them or how to include them in the sample project.
I am a beginner at using eclipse, java or android SDK. Am I missing some obvious step?
Also, on the color blob detector project in the Properties -> Android section, in the Library subsection there is mentioned an undefined reference to ..\..\sdk\java which I do not know how to solve.
Can you point me out how to solve these problems?
You should add openCV SDK lib to your eclipse too which is located in \OpenCV-2.4.9-android-sdk\OpenCV-2.4.9-android-sdk\sdk\java.
Add the project located in that folder as Android Application from Existing Code.
http://www.java2s.com/Code/Jar/o/Downloadopencv241jar.htm
download jar file and add to jar in project properties and then ok press it then all problem slove