Debugging NDK and JNI for Android

    This article will focus on debugging code for Android.
    Recently, there have been many advances in this direction. Android Studio appeared, google added support for debugging native code in eclipse.
    If you need to debug only Java, then Android Studio will cover your needs completely.
    If you need debugging with C ++ or Java code, then the ADT Bundle with built-in Eclipse will again help solve your problem.
    If briefly
    • Make it clear to Eclipse that the project contains a native part (Add native support)
    • Make sure that the build command has NDK_DEBUG = 1
    • Click Debug as Android Native Application

    on some devices it is also necessary to set debuggable to true in the manifest.
    But if you need to debug jni code, where c ++ and Java functions work alternately, then this method will not work for you, because depending on the chosen debugging method (Android Native Application, Android Application ) debugging works either with C ++ or java code.
    How to debug mixed code will be discussed later in the article.

    The basis of our entire system will be the NVIDIA Debug Manager for Android NDK. Despite the statement that it is for debugging the Tegra platform, it is superbly capable of debugging any Android platform.

    I did not succeed in installing NVIDIA Debug Manager for Android NDK on the ADT Bundle, so I had to do my own assembly.

    First, a list of what we need.
    1. Eclipse (I recommend Kepler) download will suit either Standart or IDE for C / C ++ Developers
    2. Stand-alone Android SDK Tools Bottom of the page GET THE SDK FOR AN EXISTING IDE
    3. NDK If you are not writing yet under x64 Android then you need Platform (32-bit target)
    4. Tegra Android Development Pack Registration is required to download it


    Installation procedure
    1. Install Eclipse - just unpack it wherever you want
    2. Install ADT - unpack anywhere, run \ tools \ android - add the necessary platforms
    I had enough of such a set
    image

    3. Install NDK - unpack anywhere
    4. Install ADT Plugin in Eclipse
    Instruction manual
    1. Launch Eclipse select Help> Install New Software
    2. Click Add in the upper left corner.
    3. In the Add Repository dialog, type “ADT Plugin” in the Name field and dl-ssl.google.com/android/eclipsein the Location field
    4. In the Available Software dialogue, activate the checkbox opposite Developer Tools and click Next
    5. In the next window, click Next again.
    6. Read and accept the license agreement
    7. If during installation you received a security warning, just click OK
    8. Restart Eclipse
    9. In the Welcome to Android Development window, select Use existing SDKs and specify the path to the installed SDK
    10. Go to Eclipse-> Preference-> Android-> NDK and specify the path to NDK

    Original

    5. Run the Tegra Android Development Pack installer - we only need the NVIDIA Debug Manager for Android NDK
    6. We find in the installation folder NVDebugMgrForAndroidNDK * .zip
    7. Run eclipse Help-> Install New Software-> Add-> Archive show the path to the installed zip to the file, put a daw on the NVIDIA Debug Manager, agree with everything that they will offer us
    8. The last step in the Debug as Android NDK Application list (on some devices it may say that I did not find GDB Make sure that the Android NDK Application -> GDB Server Settings is in the settings APK bundled)
    Screen
    image


    Now breakpoints work both in Java and in C ++ code.
    If you suddenly encounter problems with NDK 10, try r9d
    here are links to some versions of
    android-ndk-r9d-windows-x86_64.zip
    android-ndk-r9d-darwin-x86_64.tar.bz2
    android -ndk-r9d-linux-x86.tar.bz2

    Also popular now: