The environment...
I have a brand new Visual Studio 2015 Android NDK Solution.
This contains 2 projects (the default template code that is generated by visual studio):
A native activity. This is where I want to put Android specific code. It has some default code which fades the screen colour between green and black.
A 'Packaging' project to help with deployment.
I have deployed this successfully to an Intel HAXM virtual device as well as to a real device connected via USB. All good so far.
I then added an Android dynamic library project (.so) - this is where I want to put core code (platform agnostic).
I added a reference to this Core library from the native activity project.
Everything compiles and links fine. I can still create an .APK file.
Other info:
Android SDK 5.1 (Android-22)
Android NDK 21
x86
Clang 3.8
C++ 11
Not using Make files or Gradle
The problem...
Now whenever I deploy to the virtual/real device I get the following error (taken from logcat)
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.NATester/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.NATester-2/lib/x86/libNATester.so
Things I have tried...
changing the Core library to static (.a)
checked the android device to see if the file exists - it does exist.
Manually deploying the .APK to the android device.
Some articles have suggested using Java code to load the libraries - I want to avoid calling Java code e.g. System.LoadLibrary as this seems like a hack - I feel that it should be possible to to have a pure C++ application on android. I can't be the only person to run into this issue?!
This looks relevant but old and again an unnecessary hack for what must be very common situation
- Can't load native shared library with dependencies in a native activity app
- https://github.com/ikonst/android-dl
For what its worth, I am a seasoned C# developer with Visual Studio (15 years).
I therefore take a lot of things for granted when developing apps - this is my first project using C++/Android and it seems more of a manual battle to get everything to work!
Been struggling for a while but managed to deploy the libraries, quite easy in the end.
Right click on the project [theProject (Andorid-xx)] in the Solution Explorer and select add new item, add your .so library.
Right click on the newly added library and select properties, item type should be library, set Content to Yes, this will deploy the lib.
Related
So , I created an Empty c++ Project In Visual Studio 2019 And Linked The Libraries Non-Staticly
(That Means I Just The Placed The dll's in The Qutput Directory) And Then Closed VIsual Studio And Switched To VSCode And Now I Build The Project Using Devloper Cmd(Of Visual Studio Of Course) and MSBuild I Use SFML To Make The Project And Now Want To Port It Over To Android (Or IOS Or Both Anything Will Work)
Is There Any Way That This Can Happen ? Please Ask Me If You Want Any Other Information
You should install the Mobile Development with C++ package in the Visual Studio Installer. Create a new C++ project using the template Native-Activity Application (Android).
Trying to convert one project type to another is pointless and a waste of your time. However, your old source code can be included in the new project using the various right click actions.
I've installed VisualStudio 2015, Xamarin, and MonoGame 3.5. I'm going to build my XNA app for Windows UWP, iOS, and Android.
I've some libraries based on XNA... and I need to build them for the three target systems (Windows UWP, iOS, and Android), but no way to create a library for Windows UWP. I've tried to create a MonoGame Windows 10 Universal Project, but such a project cannot be converted to generate a DLL.
I've also tried to create a Class Library (Universal Windows) project, but then I was unable to add MonoGame.Framework to the references.
I've the same problem when creating a MonoGame Android Project... no way to switch to a library project. The only MonoGame project that can be modified to be a library project is MonoGame iOS Project.
That said, how can I create a class library based on XNA (MonoGame) to be used from UWP, iOS, and Android?
As far as I know you've only got 2 options here.
Portable Class Libraries
Shared Projects
I haven't really used Shared Projects much. The way I understand them is that they allow you to share code between multiple projects as if it lives in a library but it actually gets compiled directly into the referencing project. They can be thought of like advanced file linking.
Portable Class Libraries are a bit of a different beast. I've used them in the MonoGame.Extended project with great success, but it wasn't always easy. The way they work is to provide a subset of functionality that works on all target platforms. They compile to a DLL that can be referenced by any of the projects and you can be confident the code will be the same.
There are a couple of downsides of using a PCL:
you can only use a subset of functionality. Surprisingly, this doesn't get in the way too often.
if the PCL references another library, it also has to be a PCL.
The second point is where things get a little tricky with MonoGame. Typically, MonoGame isn't shipped as a PCL, but a PCL version has been published on NuGet that can be used.
As it stands right now, the NuGet package is a version behind the official release but surprisingly that doesn't really matter because it's a bait and switch PCL which essentially means it just provides the interface to the real DLL that gets used at runtime. In other words, your game will still happily reference version 3.5 even if the PCL is version 3.2 so long as the interface hasn't changed.
There is some talk about improving this situation in version 3.6.
I noticed MonoGame projects are built using .Net 4.5 by default. Regular class libraries default to the latest installed version of .Net which in my case was 4.5.2. I was able to reference a regular class library by going to its project properties and setting the target framework to 4.5. Hope this helps.
after a couple of weeks I have been unable to get the android set of tools to a functioning level with c++ before and have been given the opportunity of using a project tango, and though that sounds awesome and wondrous and would open a world of opportunity for working with VR... I feel like I am stuck at step -4. My understanding is limited, so bear with me.
I stumbled upon the PCL built for running algorithms on point cloud data, it was open source and appeared like a wonderful solution, it is written in C++ and I have a mild understanding of both c++ and java.
I have tried using Eclipse and the NDK and actually managed to get a project 'deployed' to the tango, however upon attempting to edit any file in the project, java or c++, it breaks and will never deploy again.
Now I am trying to use Android Studio, and after following about 5 conflicting tutorials on 'how to get C++/ndk working in android studio' I have yet to get a working environment.
So here is my question, and we can start at step one, any help is appreciated. How does one get c++ and the PCL working on a google project tango, is there a better way for someone of my skill level? The end result is a mapped 3d space with the project tango, with exportable data sets of manageable size. I have seen it done in demos on youtube, but thus far, like i said, I am stuck on step -4.
we are working on converting all project to android studio based, for now, here is the walk around to get you started:
Open Android Studio, import the project from the repo you just cloned.
Take the motion-tracking-jni-example as the example, copy tango-gl-render, tango-service-sdk, and third-party into the motion-tracking-jni-example/app/src.
Run ndk-build in the motion-tracking-jni-example/app/src/main folder.
ndk will generate the libs folder, rename it to jniLibs.
Go to Android Studio, in build.gradle(Module:app) file, add line 'sourceSets.main.jni.srcDirs = []' to the defaultConfig section.
Just click the run button in Android Studio.
What we did here is basically disabled the Android Stdio's JNI compile and manually built it using ndk.
Start with unity3d, its easy to get a working demo with a week with Unity3D.
And support is very good, documentation is top notch.
Hope this will help.
Tango NDK Tutorial Will help but the basic layout is
Setup a new project
Create your Java activity
Create a JNI file to bridge Java to the C++
Create your C++ logic
Setup your Makefiles and Gradle (probably the most annoying part)
There are numerous questions like this around here, the Qt sites and the OpenCV sites, but none of them quite match my case. (And a lot are unanswered anyway.)
I'm using OpenCV for Android 2.4.6 (the prebuilt version downloadable from the official site)
to build a native App for Android (4.1.2) on a Samsung Galaxy Note 2 with Qt 5.0.1 for Android
(using QtCreator 2.7.2) on a x86_64 Linux host.
I've linked against the libraries in the ../sdk/native/libs/armeabi-v7a folder. (I haven't built OpenCV from source, I'm just using what was in the downloaded package). This includes a libopencv_androidcam.a library. (And I've also tried the libnative_camera_r4.1.1.so shared lib.)
I've also downloaded the market app "OpenCV Manager".
The sample .apks from the samples directory work on my phone, but I haven't tried to build them on my own, as I don't have a Java development environment set up.
Starting my application, which contains a cv::VideoCapture inputCapture(CV_CAM_ANDROID); statement, I get the following error and no camera input:
E/OpenCV::camera(15299): CameraWrapperConnector::connectToLib ERROR: cannot dlopen camera wrapper library
E/OpenCV::camera(15299): Native_camera returned opening error: 4
My questions:
Should this work? I have seen a lot
of bug reports, but all with older
OpenCV versions and newer/older
Android versions. Bonus points if it
has been seen working on this phone
model.
Should this work out of the box with the downloaded OpenCV Android SDK? Or do I need to build OpenCV from source with some special options? (Which ones?)
Do I need special library versions on the phone itself? Do I need to have root access to the device to make this work?
Are there any "known to be working" Andoid examples using native code instead of Java?
Thanks a lot for any help!
I'll repeat the answer I got from user #Moster at http://answers.opencv.org here:
Copy libnative_camera_r4.1.1.so from the folder
/sdk/native/libs/armeabi-v7a to your Qt project's folder
/android/libs/armeabi-v7a. Make sure you have also allowed the camera
in the android_manifest in the Qt creator. Maybe all this helps
This indeed works. While I already mentioned the camera permissions in the Manifest.xml (or rather the Qt project settings), copying the shared lib to the project directory did the trick.
Seems like it's found and linked during build, but not copied to the device from its original location.
Neither the "Copy local Qt libs to device" in the deploy settings (Qt libs only?) nor the OpenCV Manager App (only loads the right libs when called directly from the Java code?) helped before.
I have not been able to trigger breakpoints set in Android source files (framework source files, as opposed to my application's source files). I have attached the Android source files, so I can see them and set breakpoints, but when I run in debug mode, these breakpoints are not triggered. I have also tried adding Class Loader breakpoints: this works fine on Android source classes. I am using Eclipse 3.7.2, and I've tried with several different Android SDK versions.
Robguinness,
It looks like what you would like to do is debug Android framework, right? The best method of doing this, from what I understand, is to import the AOSP project into Android Studio (only recognizes Java files) by running "make idegen && development/tools/idegen/idegen.sh" and then opening the android.ipr file that it generated in Android Studio. You can then hook up your emulator and set breakpoints in the Java code.
There are also a wide selection of tools to debug the Kernel, C native code, etc. but there it is such a long topic to cover on this site. If you are interested in more specifics, I would highly recommended Karim Yaghmour's class on Android Debugging (http://www.opersys.com/training/android-debug-and-performance). He has also given several talks at AnDevCon that should be freely available on Youtube about AOSP and Android Internals.
Best Wishes!