Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

How can I debug my Android native C++ library for Unity3D?

Discussion in 'Android' started by garrilla, Jul 12, 2019.

  1. garrilla

    garrilla

    Joined:
    Jan 12, 2016
    Posts:
    22
    I have created a JUCE based audio library in C++ (originally as a windows DLL)

    I have successfully built it into an AAR library with Android Studio

    I can successfully run it in a Unity3D build for Android.

    I can get the debugger messages back to LogCat

    However, I really need to step through some part of the native C++ code with a managed debugger. ( I know how use a debugger for the c# for unity on android)

    I've searched for days but cannot find an answer.

    Unity3D 2018.3.11f1

    Android Studio 3.4.1 Build #AI-183.6156.11.34.5522156, built on May 1, 2019 JRE: 1.8.0_152-release-1343-b01 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,988
    You use Android Studio's Native Debugger for such cases, from Unity choose Export Project in BuildPlayerWindow, and import that project in Android Studio.

    Set debugger type to Native in Android Studio, in project settings set the symbol path, if those were separated from library files. And you're good to go.
     
    garrilla likes this.
  3. garrilla

    garrilla

    Joined:
    Jan 12, 2016
    Posts:
    22
    Thanks.

    I know how to set the symbols but can you elaborate on "if those were separated from library files" I'm not sure what you're suggesting
     
  4. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,988
    I am talking about stripping symbols from your native library, and were they stripped to separate file, sorry for not being clear
     
  5. garrilla

    garrilla

    Joined:
    Jan 12, 2016
    Posts:
    22
    OK, thanks again. I'm with you now. They're not stripped.

    However, I do have another question if you have the patience for it.

    When my exported app comes into Android Studio, the native code is the .aar so I'm a little confused how I should set breakpoints?

    Should I bring my library into the exported app? or the exported app into the library? etc.
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,988
    Assuming the library was built on same machine, you drag & drop C/C++ files in your Android Studio project and place breakpoints there.

    P.S AAR is simply a package (a zip file), the native library sits in aar itself, which has .so extension. You can actually unzip AAR using 7zip or othere compression program.
     
  7. garrilla

    garrilla

    Joined:
    Jan 12, 2016
    Posts:
    22
    OK, I built the AAR. (I know it a zip too - but a good tip!)

    So I just need to copy the source files into the exported project into the /libs folder? sorry if this seems obvious, just a complete android nube except for vanilla builds.
     
  8. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,988
    You don't need to copy them, you simply need to open them in Android Studio, either drag & drop, or File->Open, after that you can start placing breakpoints
     
  9. garrilla

    garrilla

    Joined:
    Jan 12, 2016
    Posts:
    22
    I really appreciate your replies and I'm so sorry for seeming dumber...


    so I have two projects open - my Unity-export app & my c++native library

    what am dragging and where am I dropping it?

    e.g drag my source folder from the library to the libs folder of the export app, etc
     
  10. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    1,988
    No worries.

    You drag & drop C++ files to Android Studio session which currently debugs your application, you don't need to add those files to project.


    AS.jpg
     
    garrilla likes this.
  11. garrilla

    garrilla

    Joined:
    Jan 12, 2016
    Posts:
    22
    OK, I get you now!

    I've done that, but it doesn't hit the breakpoint I set - although I know from the logcat that it must have past that point (a Debug.Log() command from unity to the native code prints successfully)

    EDIT: my error, I was setting the wrong path for the symbols.

    It works now.

    Thanks so much for your help @Tomas1856
     
    Last edited: Jul 15, 2019
    Tomas1856 likes this.