EDIT: This has not been decided yet. I suspected, based on comments, that using the old NDK (10d) might be a problem, so I upgraded to 15c and looked at all the problems to collect my stuff using clang and the new C ++ library. Unfortunately, ndk-gdb is broken into 15c, and my attempts to hack python to make it work have not delivered me anywhere. Then I used the preview of Android Studio 3.0, and I went back to where I was before - I can see the stack information, but all the code is an assembly in lldb. Work must continue. I will return to using logcat for debugging :(
I come to you with a bruised forehead from numerous blows on the wall.
I will try to be brief and provide all relevant information at the same time. If there is any relevant information that I have not included, let me know.
Description:
I support the Android application as part of my work. I had to resort to logging in order to debug my own code, because although I can set breakpoints and hit them, I canβt see the source or variable information .
I spent many hours and googling, trying to figure out what I'm missing, but still no luck.
My OSX build assembly using Android NDK r10D and gradle 3.2 to create an APK.
I am trying to use AndroidStudio 3.0 beta 6 to install and debug an APK.
My Android.manifest includes a tag:
android:debuggable="true"
Source:
This is an example of compiling one of the native C ++ files with -v for verbosity:
~/src/libraries/cBase$ make android Building obj/Binary.ao Using built-in specs. COLLECT_GCC=arm-linux-androideabi-g++ Target: arm-linux-androideabi Configured with: /s/ndk-toolchain/src/build/../gcc/gcc-4.8/configure --prefix=/tmp/ndk-User/build/toolchain/prefix --target=arm-linux-androideabi --host=x86_64-apple-darwin --build=x86_64-apple-darwin --with-gnu-as --with-gnu-ld --enable-languages=c,c++ --with-gmp=/tmp/ndk-User/build/toolchain/temp-install --with-mpfr=/tmp/ndk-User/build/toolchain/temp-install --with-mpc=/tmp/ndk-User/build/toolchain/temp-install --with-cloog=/tmp/ndk-User/build/toolchain/temp-install --with-isl=/tmp/ndk-User/build/toolchain/temp-install --with-ppl=/tmp/ndk-User/build/toolchain/temp-install --disable-ppl-version-check --disable-cloog-version-check --disable-isl-version-check --enable-cloog-backend=isl --with-host-libstdcxx='-static-libgcc -lstdc++ -lm' --disable-libssp --enable-threads --disable-nls --disable-libmudflap --disable-libgomp --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared --disable-tls --disable-libitm --with-float=soft --with-fpu=vfp --with-arch=armv5te --enable-target-optspace --enable-initfini-array --disable-nls --prefix=/tmp/ndk-User/build/toolchain/prefix --with-sysroot=/tmp/ndk-User/build/toolchain/prefix/sysroot --with-binutils-version=2.24 --with-mpfr-version=3.1.1 --with-mpc-version=1.0.1 --with-gmp-version=5.0.5 --with-gcc-version=4.8 --with-gdb-version=7.6 --with-python=/Users/User/mydroid/ndk/prebuilt/darwin-x86_64/bin/python-config.sh --with-gxx-include-dir=/tmp/ndk-User/build/toolchain/prefix/include/c++/4.8 --with-bugurl=http://source.android.com/source/report-bugs.html --enable-languages=c,c++ --disable-bootstrap --enable-plugins --enable-libgomp --disable-libsanitizer --enable-gold --enable-graphite=yes --with-cloog-version=0.18.0 --with-isl-version=0.11.1 --enable-eh-frame-hdr-for-static --with-arch=armv5te --program-transform-name='s&^&arm-linux-androideabi-&' --enable-gold=default Thread model: posix gcc version 4.8 (GCC) COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-g' '-v' '-D' 'ANDROID' '-O0' '-g' '-c' '-MMD' '-MP' '-I' '/Users/spartygw/src/libraries' '-I' '/Users/spartygw/src/libraries/thirdparty' '-I' '/Users/spartygw/src/libraries/thirdparty/jpeg' '-I' '/Users/spartygw/src/libraries/thirdparty/zlib' '-I' '/Users/spartygw/src/include' '-I' '/Users/spartygw/android-toolchain/sysroot/usr/include' '-D' '__ARM_ARCH_5__' '-D' '__ARM_ARCH_5T__' '-D' '__ARM_ARCH_5E__' '-D' '__ARM_ARCH_5TE__' '-D' '__ANDROID__' '-D' 'DEBUG' '-o' 'obj/Binary.ao' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp' '-mtls-dialect=gnu' /Users/spartygw/android-toolchain/bin/../libexec/gcc/arm-linux-androideabi/4.8/cc1plus -quiet -v -I /Users/spartygw/src/libraries -I /Users/spartygw/src/libraries/thirdparty -I /Users/spartygw/src/libraries/thirdparty/jpeg -I /Users/spartygw/src/libraries/thirdparty/zlib -I /Users/spartygw/src/include -I /Users/spartygw/android-toolchain/sysroot/usr/include -iprefix /Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/ -isysroot /Users/spartygw/android-toolchain/bin/../sysroot -MMD obj/Binary.d -MP -MQ obj/Binary.ao -D_GNU_SOURCE -D ANDROID -D __ARM_ARCH_5__ -D __ARM_ARCH_5T__ -D __ARM_ARCH_5E__ -D __ARM_ARCH_5TE__ -D __ANDROID__ -D DEBUG Binary.cc -mbionic -fpic -quiet -dumpbase Binary.cc -march=armv5te -mfloat-abi=soft -mfpu=vfp -mtls-dialect=gnu -auxbase-strip obj/Binary.ao -g -g -O0 -Wextra -Wall -version -fexceptions -frtti -o /var/folders/03/hpjtv8c969scgcc5121ybrwr0000gn/T//ccciFNCN.s GNU C++ (GCC) version 4.8 (arm-linux-androideabi) compiled by GNU C version 4.2.1 (Apple Inc. build 5666) (dot 3), GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/include" ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../include/c++/4.8/backward" ignoring duplicate directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-androideabi/4.8/include" ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../sysroot/usr/local/include" ignoring duplicate directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-androideabi/4.8/include-fixed" ignoring nonexistent directory "/Users/spartygw/android-toolchain/bin/../lib/gcc/../../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/include" ignoring nonexistent directory "/Users/spartygw/src/include" ignoring duplicate directory "/Users/spartygw/android-toolchain/sysroot/usr/include" as it is a non-system directory that duplicates a system directory #include "..." search starts here: #include <...> search starts here: /Users/spartygw/src/libraries /Users/spartygw/src/libraries/thirdparty /Users/spartygw/src/libraries/thirdparty/jpeg /Users/spartygw/src/libraries/thirdparty/zlib /Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/include /Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/include-fixed /Users/spartygw/android-toolchain/bin/../lib/gcc/../../include/c++/4.8 /Users/spartygw/android-toolchain/bin/../lib/gcc/../../include/c++/4.8/arm-linux-androideabi /Users/spartygw/android-toolchain/bin/../sysroot/usr/include End of search list. GNU C++ (GCC) version 4.8 (arm-linux-androideabi) compiled by GNU C version 4.2.1 (Apple Inc. build 5666) (dot 3), GMP version 5.0.5, MPFR version 3.1.1, MPC version 1.0.1 GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: 7c7303e2f21bf352ab9993b8ba84df0b ^ COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-g' '-v' '-D' 'ANDROID' '-O0' '-g' '-c' '-MMD' '-MP' '-I' '/Users/spartygw/src/libraries' '-I' '/Users/spartygw/src/libraries/thirdparty' '-I' '/Users/spartygw/src/libraries/thirdparty/jpeg' '-I' '/Users/spartygw/src/libraries/thirdparty/zlib' '-I' '/Users/spartygw/src/include' '-I' '/Users/spartygw/android-toolchain/sysroot/usr/include' '-D' '__ARM_ARCH_5__' '-D' '__ARM_ARCH_5T__' '-D' '__ARM_ARCH_5E__' '-D' '__ARM_ARCH_5TE__' '-D' '__ANDROID__' '-D' 'DEBUG' '-o' 'obj/Binary.ao' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp' '-mtls-dialect=gnu' /Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/as -v -I /Users/spartygw/src/libraries -I /Users/spartygw/src/libraries/thirdparty -I /Users/spartygw/src/libraries/thirdparty/jpeg -I /Users/spartygw/src/libraries/thirdparty/zlib -I /Users/spartygw/src/include -I /Users/spartygw/android-toolchain/sysroot/usr/include -march=armv5te -mfloat-abi=soft -mfpu=vfp -meabi=5 --noexecstack -o obj/Binary.ao /var/folders/03/hpjtv8c969scgcc5121ybrwr0000gn/T//ccciFNCN.s GNU assembler version 2.24 (arm-linux-androideabi) using BFD version (GNU Binutils) 2.24 COMPILER_PATH=/Users/spartygw/android-toolchain/bin/../libexec/gcc/arm-linux-androideabi/4.8/:/Users/spartygw/android-toolchain/bin/../libexec/gcc/:/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ LIBRARY_PATH=/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/:/Users/spartygw/android-toolchain/bin/../lib/gcc/:/Users/spartygw/android-toolchain/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/lib/:/Users/spartygw/android-toolchain/bin/../sysroot/usr/lib/ COLLECT_GCC_OPTIONS='-Wextra' '-Wall' '-g' '-v' '-D' 'ANDROID' '-O0' '-g' '-c' '-MMD' '-MP' '-I' '/Users/spartygw/src/libraries' '-I' '/Users/spartygw/src/libraries/thirdparty' '-I' '/Users/spartygw/src/libraries/thirdparty/jpeg' '-I' '/Users/spartygw/src/libraries/thirdparty/zlib' '-I' '/Users/spartygw/src/include' '-I' '/Users/spartygw/android-toolchain/sysroot/usr/include' '-D' '__ARM_ARCH_5__' '-D' '__ARM_ARCH_5T__' '-D' '__ARM_ARCH_5E__' '-D' '__ARM_ARCH_5TE__' '-D' '__ANDROID__' '-D' 'DEBUG' '-o' 'obj/Binary.ao' '-march=armv5te' '-mfloat-abi=soft' '-mfpu=vfp' '-mtls-dialect=gnu'
Android.mk:
My Android.mk in the jni directory looks like this:
LOCAL_PATH := $(call my-dir)
Application.mk:
APP_STL := stlport_static APP_PLATFORM := android-10 APP_ABI := armeabi-v7a APP_OPTIM := debug
My build.gradle file:
////////////////////////////////////////////////////////////////////////////// // need this for password dialog import groovy.swing.SwingBuilder buildscript { System.properties['com.android.build.gradle.overrideVersionCheck'] = 'true' repositories { jcenter() } dependencies { // Current Gradle version. final GradleVersion gradleVersion = GradleVersion.current() // Gradle version 3.0+ requires a different classpath final GradleVersion gradle3 = GradleVersion.version('3.0') // Compare versions. if (gradleVersion >= gradle3) { println "Your Gradle version is at least 3.0" classpath 'com.android.tools.build:gradle:2.2.0' } else { println "Your Gradle version is older than 3.0" classpath 'com.android.tools.build:gradle:2.1.0' } } } apply plugin: 'com.android.application' android { lintOptions { disable 'LongLogTag','ProtectedPermissions','AppLinksAutoVerifyError','MangledCRLF' } defaultConfig { applicationId "com.mycompany.myapp.myclass" } compileSdkVersion 23 buildToolsVersion "23.0.2" sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] resources.srcDirs = ['src'] aidl.srcDirs = ['src'] renderscript.srcDirs = ['src'] res.srcDirs = ['res'] assets.srcDirs = ['assets'] jniLibs.srcDirs = ['libs'] } debug.setRoot('build-types/debug') release.setRoot('build-types/release') } signingConfigs { release { // We can leave these in environment variables storeFile file(String.valueOf(System.getenv("PKCS12_FILE"))) keyAlias "mykey" // These two lines make gradle believe that the signingConfigs // section is complete. Without them, tasks like installRelease // will not be available! storePassword "notYourRealPassword" keyPassword "notYourRealPassword" } } buildTypes { release { signingConfig signingConfigs.release } debug { debuggable true jniDebuggable true } } } dependencies { compile 'com.android.support:support-v4:23.1.1' compile 'com.google.android.gms:play-services:8.4.0' } task askForPasswords { doLast { def pw = '' if(System.console() == null) { new SwingBuilder().edt { dialog(modal: true, title: 'Enter password', alwaysOnTop: true, resizable: false, locationRelativeTo: null, pack: true, show: true) { vbox { // Put everything below each other label(text: "Signing the APK...Enter the keystore password:") def input1 = passwordField() button(defaultButton: true, text: 'OK', actionPerformed: { pw = new String(input1.password); dispose(); }) } } } } else { // Must create String because System.readPassword() returns char[] // (and assigning that below fails silently) pw = new String(System.console().readPassword("Keystore password: ")) } android.signingConfigs.release.storePassword = pw android.signingConfigs.release.keyPassword = pw } } tasks.whenTaskAdded { theTask -> if (theTask.name.equals("packageRelease")) { theTask.dependsOn "askForPasswords" } } task getVersion() { println GradleVersion.current().getVersion() }