31. May 2017

How to debug C/C++ code in Android Studio

Android Studio has support for debugging Java and also C/C++ code. The problem is that in default configuration the debugger might not work. There is a quick way how to fix the issue.

Go to your application and select Edit Configurations…

Select tab Debugger and change Debug type to value Dual. Press Ok.

Android Studio will check installed packages and in the case of missing debugger it will prompt you to confirm the fix. Just click Yes.

After installation of necessary packages, the debugger will start and you’ll be able to debug even C/C++ code.

5. May 2015

C language in our world 2015 – slides

Slides available in formats: PDFSlideShare

Source code: GitHub/ysoftdevs/cpp-examples

8. December 2014

C++ in our world 2014 – slides


Slides available in formats: PDFSlideShare

Source code: GitHub/ysoftdevs/cpp-examples

11. August 2014

Gradle PMD – Can’t find resource null

Gradle has support for PMD. You can find following example on internet:

apply plugin: 'pmd'

pmdMain {
  ruleSets = [ "basic", "strings" ]
}

This code is not working with Gradle 2.0. Here is error message:

:clean
:pmdMain FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':pmdMain'.
  Can't find resource null. Make sure the resource is a valid file or URL and is on the CLASSPATH. Here's the current classpath: C:\Users\georgik\tmp\install\gradle-2.0\lib\gradle-launcher-2.0.jar

The reason is simple. In case of Gradle 2.0 you must add language prefix before name of rule. You must use java-strings instead of plain strings.

Here is correct example (available also on YSoftDevs Github):

apply plugin: 'pmd'

pmdMain {
  ruleSets = [ "java-basic", "java-strings", "java-braces" ]
}

You can find more rules for PMD in official documentation.

Thanks Matt Sicker for correct solution.

23. June 2014

How to debug Gradle script

First of all: do not use daemon mode for debugging.

IntelliJ Idea is automatically spawning daemon when you start any Gradle task. You have to attach to remote process.

I wrote small “How to debug” based on info from forums.gradle.org.

You’ll need to set GRADLE_OPTS environment variable to:

-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005

Here is example in PowerShell:

01-command-line-options

$env:GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005"

Configure Remote debugging in Idea:

02-configure-remote

You do not need to change anything in default configuration.

Now return to command line with your project and invoke task. Gradle will automatically stop and it waits for debugger.

03-start-process

Attach debugger

04-attach-to-process

Here we go 🙂

05-break-point

There is small limitation. You can stop code execution outside DSL e.g. in class method (line 3). You won’t be able to stop execution in Gradle DSL line 10.

You can download sample build script from Github.