First step: I use QtCreator to compile a bunch of libraries (.so files) + a GUI test program to test those libraries on an Android device.
Second step: After I tested them, I re-compile the libraries without the GUI test program and send them to a client who's going to integrate those .so file in its own Andoid application (generating and apk), not using QtCreator anymore. I do this step using QtCreator (because it's setup, very easy for me to just remove the GUI test program and hit compile), but I'm pretty sure they could also be compiled directly using ndk-build if I work on writting the correct make files for that.
When I re-compile the libraries, there's still a "Android build SDK" option under "Build Android APK" set to "android-22" in QtCreator. However, my client generates its final app for "android-19". And we are wondering if this could be a problem.
My understanding is that my .so files generated in "second step" are built using the NDK only (SDK is not used, so android API version "android-22" is irrelevant as I do not generate any APK...). So there should be no compatibility issue when those .so files are integrated in an application, as far as the same NDK version is used.
Am I right?
Related
I have a lib and dll files (I can choose which file I want to use)
I want to call to functions that are inside the file.
The code that complied in dll/lib wrote at c
dll files (unless the dll is a dot.net dll and you are in a Xamarin app) are not usable in Android.
Furthermore DLL files typically are compiled for x86 (32bit) or x86_64 (64bit) CPUs. The number of Andorid devices with an x86 CPU is next to zero, for Android you need the library compiled for ARMv7 (32bit) and ARMv8 (64bit). As Android is Linux based you need .so files in stead of .dll files.
To make development easier you should install Android Studio + Android NDK (Native Development Kit). Then you have everything for compiling c code in a way that you can make use of it within an Android app.
Google provides multiple sample projects that show how to use NDK: https://developer.android.com/ndk/samples
I am trying to debug a C++ Android application using Android NDK r20.
The project used to use the old way of building using ndk-build and the android.mk file.
Now the project is migrated to using gradle and cmake. Because of this, the ndk-gdb script no longer works, since it uses the old build system which expects an android.mk file.
So how am I supposed to debug from the command line using the latest ndk along with a gradle/cmake build system? Is there a new script that is provided?
ndk-gdb doesn't know how to do it out of the box right now. You can set up some symlinks in a gradle project to make the directory layout match a standalone ndk-build project which will let ndk-gdb work. See https://android.googlesource.com/platform/ndk/+/refs/heads/master/samples/NdkGdbSample/ for an example.
ndk-gdb doesn't work at all with CMake though.
See https://github.com/android-ndk/ndk/issues/1024 (I assume that's actually you that filed it). I don't know when we'll be able to do it, but what's described there is essentially what we'll do. We'll keep the existing script, get it to work with gradle projects, and (eventually) switch it to lldb under the covers.
Using Android Studio is your best bet for native debugging on Android right now.
We have a multi-platform project, with native support, that we are developing in Android Studio using libgdx. We have builds working for Desktop, IOS, Android, Android Wear, and HTML5.
On each of these platforms, we have a different "native" plugin that we are using: a static .a native library on IOS, a .dll on Windows, a bunch of .so files in Android, and a Javascript library on HTML5. All of these, except for the HTML5 version, are built on separate platforms so can't possibly be built by the same Android Studio NDK build.
The problem is that for each of the .java files that declare JNI routines, Android Studio 1.4.x wants to find the source files, but those source files can't possibly be compiled in the IOS project, and likewise for the PC project when running on a Mac.
The standard solution on SO is to add
sourceSets {
main {
jni.srcDirs = [] //disable automatic ndk-build
}
}
To the android{} section, but this ONLY works for the Android, Android Wear launcher projects, and NOT Desktop, IOS, HTML5, etc.
I just want Android Studio to give up on trying to compile NDK, because it can't possibly be done on non-Android projects. Other than finding a downgrade somewhere, how do I do that?
Thanks!
So, I decided that I could figure this out - and I did!
Of course, the NDK builder is just a plugin in IntelliJ, so all you have to do to disable it is to
go to your AndroidStudio installation,
find the "plugins" directory
move or delete the "android-ndk" folder
Tada! No more NDK plugin!
Correct way is to uninstall NDK using SDK manager.
go to Android Studio-> Tools -> SDK Manager
Under SDK tools tab uncheck "NDK", "CMake", "LLDB" and then apply changes. NDK components will be removed.
Downside is NDK is removed for all project. Still struggling to find a way to disable NDK for a particular project only.
If you would like to keep the NDK build for future use and not use it for specific projects just make sure to uncheck these options in the new project dialog...
I have a Java Android application project that includes a so library in libs/armeabi folder.
The c++ code of this library is in a different Android NDK project and is dependent on other different library NDK projects.
Is it possible to debug the c++ code of this library while the Java Android application is running?
In order to debug the native code in .so, first you need .so that was generated with debugging mode. (e.g., NDK_DEBUG = 1)
If you don't have source code and therefore no debuggable .so, there is no way to debug.
Also, please specify your environment such as Android NDK version, IDE, etc.
Assuming you are using Eclipse, this is detailed description how to debug native applications.
As an academic exercise, I'm following this to build an Android app from the command line using just the android sdk.
I was wondering where in the Android SDK I could find the Android library to javac against? Otherwise, javac doesn't know where to find, for instance, android.app.Activity. I think dx needs the library too right?
As an academic exercise, I'm following this to build an Android app from the command line using just the android sdk.
That blog post is from 2009. At the time of this writing, it is 2015. The build process has substantially changed since 2009.
I was wondering where in the Android SDK I could find the Android library to javac against?
$ANDROID_SDK/platforms/platform-NNN, where $ANDROID_SDK is wherever you have the Android SDK installed and NNN is an API level (e.g., 21). In there, you will find an android.jar file that contains the mocks of the Android SDK API that we compile against.
I looked at the docs on the Android page for creating a project through cli, but it would generate an Ant project?
I have heard that you can have a -g switch to generate Gradle build files instead of Ant, but I haven't ever used it. Personally, I would just copy the Gradle build files from a known-working project and modify them to suit.