Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

all samples should include configuration and instructions for JNI debugging #20

Closed
proppy opened this issue Jun 30, 2015 · 21 comments
Closed
Assignees

Comments

@proppy
Copy link
Contributor

proppy commented Jun 30, 2015

Using:

    android.buildTypes {
        debug {
            isJniDebuggable = true
        }
    }
@kneth
Copy link

kneth commented Jul 12, 2015

I am trying to debug some native code using Android Studio 1.3 (preview) with the new NDK support. My app/build.gradle has a section like

android.buildTypes {
    release {
        isMinifyEnabled = false
        proguardFiles += file('proguard-rules.txt')
    }

    debug {
        isJniDebuggable = true
        isDebuggable = true
    }
}

For gdb I constantly get

Syntax error: extraneous input 'n' expecting {<EOF>, ','} in "=tsv-created,name="trace_timestamp",initial="0"\n" line 1 position 48
com.jetbrains.cidr.execution.debugger.backend.gdb.GDBResponse$ResponseParseException: Syntax  error: extraneous input 'n' expecting {<EOF>, ','} in "=tsv-created,name="trace_timestamp",initial="0"\n"   line 1 position 48
    at com.jetbrains.cidr.execution.debugger.backend.gdb.GDBResponse$Parser.parse(GDBResponse.java:84)
    at com.jetbrains.cidr.execution.debugger.backend.gdb.GDBResponse.parse(GDBResponse.java:18)

For lldb it cannot get a handshake.

Do I miss something in my build.grade?

@proppy
Copy link
Contributor Author

proppy commented Jul 13, 2015

@kneth can you file a separate issue on https://code.google.com/p/android/issues/entry?template=Tools%20bug%20report so that we can track the RC 1 debugging issue separatly?

This issue is more about updating the the gradle files for the sample to add debug configuration.

@proppy
Copy link
Contributor Author

proppy commented Jul 13, 2015

@kneth (Note that lldb worked for me, albeith slow):

DEVICE SHELL COMMAND: cat /data/local/tmp/lldb-server | run-as com.android.gl2jni sh -c 'cat > /data/data/com.android.gl2jni/lldb/bin/lldb-server; chmod 700 /data/data/com.android.gl2jni/lldb/bin/lldb-server'
DEVICE SHELL COMMAND: rm /data/local/tmp/lldb-server
DEVICE SHELL COMMAND: cat /data/local/tmp/start_lldb_server.sh | run-as com.android.gl2jni sh -c 'cat > /data/data/com.android.gl2jni/lldb/bin/start_lldb_server.sh; chmod 700 /data/data/com.android.gl2jni/lldb/bin/start_lldb_server.sh'
DEVICE SHELL COMMAND: rm /data/local/tmp/start_lldb_server.sh
Now Launching Native Debug Session
Debugger attached to process 2571

A limitation of the current RC is that you can't debug native code on init, this is fixed with:
https://android-review.googlesource.com/#/c/156943/ and other upcoming update of the 1.4 branches.

@kneth
Copy link

kneth commented Jul 13, 2015

@proppy I'll give lldb a second try. I have submitted bug https://code.google.com/p/android/issues/detail?id=179694&thanks=179694&ts=1436779249

@proppy
Copy link
Contributor Author

proppy commented Aug 4, 2015

Closing this as with gradle-experimental-0.2.0, the debug build is now debuggeable by default.

If you want to debug the release build you need to add:

android.buildType {
  release {
    ndk {
      debuggable = true
    }
  }
}

@proppy proppy closed this as completed Aug 4, 2015
@proppy
Copy link
Contributor Author

proppy commented Aug 6, 2015

Reopening since it would be nice to have step by step instructions to setup debugging on a project in each README.

Related #54

@GiantGeorgeGo
Copy link

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        ndk {
            debuggable = true
        }
    }
    debug {
        debuggable = true
        jniDebuggable = true
    }
}

it works for me.

@kneth
Copy link

kneth commented Oct 20, 2015

@GiantGeorgeGo Works like in native debugging? Or just compiling?

@ggfan
Copy link
Contributor

ggfan commented Oct 20, 2015

@GiantGeorgeGo are you using experimental plugin or android plugin for gradle?

@GiantGeorgeGo
Copy link

@kneth it works for native debug.
@ggfan I am not using the experimental plugin, just the android plugin.

@ggfan
Copy link
Contributor

ggfan commented Oct 21, 2015

@GiantGeorgeGo experimental plugin is the one supported right now: all samples here are using the experimental plugin.

@sistr22
Copy link
Contributor

sistr22 commented Nov 11, 2015

jniDebuggable doesn't exist anymore with gradle-experimental:0.4.0-alpha2
What's the replacement (Currently I can't dbg step by step in C++ code with gradle-experimental:0.4.0-alpha2)

@rschiu
Copy link
Contributor

rschiu commented Nov 11, 2015

@WhiteSEEKER It's part of the 'ndk' configuration block now. e.g.

    release {
        debuggable = true
        ndk {
            debuggable = true
        }
    }

The debug build should have ndk debuggable by default.

proppy added a commit to proppy/android-ndk that referenced this issue Nov 12, 2015
@proppy
Copy link
Contributor Author

proppy commented Nov 12, 2015

reopening, we should call that out more explicitly in the README.md file or point to http://tools.android.com/tech-docs/new-build-system/gradle-experimental

@proppy
Copy link
Contributor Author

proppy commented Nov 17, 2015

This should also include something about switch to the native run configuration

@sistr22
Copy link
Contributor

sistr22 commented Nov 27, 2015

I can rarely debug. Most of the time I have:

Now Launching Native Debug Session
Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=com.my.package.name }

Client not ready yet..Connected to process 16172 on device XXXXX
Failed to attach native debugger: unable to attach

With AS 2.0 preview
Gradle 2.9 and experiemental plugin 0.6.0-alpha1 (but it wasn't working properly before so ...)

Also I don't see anymore the switch between lldb and gdb, a bit like this non-answered stackoverflow question:

http://stackoverflow.com/questions/32684845/how-to-switch-between-lldb-and-gdb-in-android-studio

@kneth
Copy link

kneth commented Nov 27, 2015

I updated the issue mentioned in a comment in July after trying AS 2.0 preview - I didn't have much success with debugging :-(

@sistr22
Copy link
Contributor

sistr22 commented Nov 27, 2015

I actually found the issue I had (And now debugging works for me).
I had to open the sdk manager (Tools->android->sdk manager) then go in the tab "SDK Tools" and there I had to check "LLDB".
Then I selected the app-native run configuration, run in debug and it worked properly (breakpoints hit etc)

@dezynetechnologies
Copy link

@WhiteSEEKER's solution works for me as well

@ggfan ggfan self-assigned this May 9, 2016
@ggfan
Copy link
Contributor

ggfan commented May 9, 2016

starting to take a look at this one.
yes, confirmed indeed, that for release build, enabling ndk "debuggable" does turn on the debugger.
   buildTypes {
        release {
           debuggable = true
           ndk.debuggable = true
        }
   }

created #197, please have a look: capture this debugging into a doc.

@ggfan
Copy link
Contributor

ggfan commented May 11, 2016

right now [version 2.1] debugger is only LLDB for JNI code. closing this one for now. To make the reference.md a useful one is a task: will put energy on it and hopefully could get most of the controls in this doc so less guess work in the future [when write gradle scripts].

In summary:

  • when building for debug version, ndk.debuggable is true by default, no need to do anything special
  • when building for release version, and want to include debug info [not sure the reason], enable ndk.debuggable = true

closing this one, please re-open if we should do it differently. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants