How can I do command line debugging using Android NDK - android

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.

Related

Unable to select JNI build variant after upgrading Android Studio to version 3.3

I have a Java Android project that includes JNI code written in C.
I often need to debug into the native code and before upgrading Android Studio to version 3.3 it was working.
Now in my project view I don't have any code in my cpp folder. I have confirmed that all of the C libraries are in the folder on my HDD. The CMAKE file is also missing from the project view but is also in the correct place on my HDD.
I have not changed any code from my source control since upgrading.
I am using
'com.android.tools.build:gradle:3.3.0'.
In the Build Variants section next to my JNI module I just have five dashes instead of the debug/production options.
I have uninstalled and reinstalled android studio too.
Is it possible after upgrading I need to add something to my configuration to correct including CMAKE?
I had the same issue, just figured it out. In AndroidStudio 3.3.1, they changed things around a bit I guess. Now you have to link your NDK build to the app you are building it as part of.
This is documented at: https://developer.android.com/studio/projects/gradle-external-native-builds
The section, "Use the Android Studio UI" is what you want.

How to build a AOSP project in Android Studio

I have imported AOSP code into Android Studio, on building it I am getting some internal errors but Run, Debug buttons are disabled.
The errors I am getting are:
Can anyone please help me how to resolve this error and to compile AOSP into Android Studio.
Also can anyone please help to how to convert this project into a Gradle project?
AOSP used a special format of makefile to build the whole project. If you insist build it on the IDE, you should write a plugin to index the whole makefile on your own.
Focus on something more meaningful. Review and modify the code in IDE, build it in shell, save your time.
To browse and debug AOSP use Intellij IDEA (close to Android Studio) or Eclipse.
AOSP source contains a tool to generate configuration for these two IDE called IDEGen.
IDEGen automatically generates Android IDE configurations for IntelliJ IDEA
and Eclipse. Your IDE should be able to compile everything in a reasonable
amount of time with no errors.
IDEGen README
To debug AOSP Java code take a look at this article (even though it is for Android Studio, configuration is the same for InteliJ IDEA).

Android studio 3 c++ file full of errors but compilation is ok

I am using Android studio 3 to develop Android application that contains c++ code that are compiled using cmake and NDK, the compilation is ok and the app runs correctly, but when I try to edit cpp file, the inline compiler shows a lot of errors, all standard header files are missing, this is very annoying as I cannot know if I make any compilation error until I run the app, I am not using any special configuration in cmake or in cradle file, any suggestion to fix the problem?
CLion (the C++ IDE that Android Studio is based on) does not have a perfect C++ parser. I believe there's a fix for the most common issue (not properly handling SFINAE) coming Soon.
Found a solution:
Close Android Studio
In command-line, delete the .idea folder in your project's root folder.
Open Android Studio, invalidate caches and restart.
Open AS again, sync gradle.
If the above steps don't work, try setting your gradle version to 3.3 (if it's not that already), and try the above steps again.

Can't build C++ project with Android toolchain

I'm using Eclipse Luna on Windows 8 and trying to use an existing C++ project with Android.
I have download the NDK and set the location in Window->Preferences->NDK
I'm getting many compile errors in the jni directory which are probably caused because of Unresolved inclusions (like stdio.h, string, jni.h etc).
The current toolchain is Android GCC. The path and symbols include some stuff from the NDK folder after I ran the ndk-build.cmd from inside the project's folder, but there probably some includes missing.
I'm not sure what else I need to do in order to build the project.
It seems that the problem was and still is with Eclipse itself. The build actually passed but Eclipse still for some reason showed errors which are not really errors and everything is actually working.
This is another proof that Visual Studio is SO much better than Eclipse...

Compile native c binaries for Android - Eg: dosfsck

I am trying to compile the binary dosfsck and mkdosfs for Android, using Linux and Android NDK and SDK. I've setup NDK and SDK properly, the path to the NDK gcc is in my path. I've also downloaded the correct SDK for my device (HTC Desire).
I first tried compiling the file with a simple make:
make
CROSS_COMPILE=/home/droidzone/android/android-ndk-r5b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
I need to be able to run the binary from my device. As it is, the app compiles and runs on Ubuntu, but not my device. I get the error message from sh: Cannot run binary
Could someone please explain how I can link libraries, where I should get them from (within the SDK) and what changes if any to make to the Makefile, and the final syntax to compile this properly for Android
I found this was easiest to do using the agcc script script which you can use by exporting CC=agcc. Lots of projects will not properly support CROSS_COMPILE as you have tried. The agcc script is oriented around using the Android build tree files so I modified it to use the NDK tools. With this you should be able to build most things using make CC=agcc or CC=agcc ./configure

Categories

Resources