I'm building a cross-platform Xamarin app and it has been working fine. However, I need to implement some logic in C++ and therefore created a shared Android/iOS project.
The C++ Android project targets the same Android API version as the app project.
If I reference the C++ project (to get the .so file in my Android app project) the app fails to start.
It seems to build fine, and I see Starting Android application ... in the Visual Studio output, but then it just seems to exit without any additional info. In other words, the app is deployed, but it isn't started and the debugger isn't attached.
If I remove the reference again, the app starts normally.
I'm targeting x86 with the C++ library, same architecture as the emulator.
Related
I have an Android app that uses classes from the Android framework/platform, for example AudioTrack. I'd like to find out more about how those classes work internally by stepping into the code of those classes. I've managed to set up the Android Studio debugger to step into the Java part, AudioTrack.java. I also want to step into the C++ part, AudioTrack.cpp, that is called from the Java part via JNI.
How can I set up Android Studio to step into the C++ part of AudioTrack, from the Java part? Where can I get the sources and debug symbols for AudioTrack from, and how to tell Android Studio about them?
Just to be clear: My app doesn't contain native code on its own, I want to debug into the native code of the Android platform itself.
Some more background and info:
I use Android Studio 4.2.2, running my app in the emulator Pixel_3a_API_30_x86. My app uses 30 for the compileSdkVersion and targetSdkVersion, and in the SDK Manager I have "Source for Android 30" installed. That means stepping into Java platform code like AudioTrack.java works fine. However, in ~/Library/Android/sdk/sources/, I can only find AudioTrack.java, not AudioTrack.cpp, and no debug symbols for libandroid_runtime.so (which is the library that contains the native code for AudioTrack).
I've set the debugger type of the run configuration of my app in Android Studio to "Dual (Java + Native)".
When encountering a call to a native method via JNI, the debugger in Android Studio just steps over the function, even when using "Force Step Into". Example of such a native method call:
I can set breakpoints in native code with LLDB commands, like this:
(lldb) br set --name android_media_AudioTrack_start
Breakpoint 4: where = libandroid_runtime.so`android_media_AudioTrack_start(_JNIEnv*, _jobject*), address = 0xe5a7eb00
However, when the debugger stops at that breakpoint, Android Studio shows no source code and no variables due to source code and debug symbols not being available:
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 try to make a own Dialer-App, to get some basic functions to work I try to get the original Dailer from the AndroidOpenSourceProject up to running. I pulled the code from AOPS Dialer master and open it in Android Studio. It told me it detects 103 Manifest files but the project could not build.
As I understand this projects need to be builded into a ROM and not to be builded with the SDK. Is there anyway how I can get this project to be builded with Android Studio and run it on a device/emulator?
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.
I am having difficulty with building my native android application using NDK. There are no binders, certain headers missing, etc.
But I have earlier experience with building using Android source 2.3, where I used to built android first and then doing mmm /path/to/my/application/ -B would build my application, but that was a forked android version.
This time I want to do it for Android 4.4, but before downloading it, I want to know whether default android sources come with commands like mmm and lunch and whether I can build my native application using it.