0

I know this question has been asked a million times, however i have tried all methods listed all types of configurations and can not get this to work. I really need to get logging info out of my C code. I will share relevant files if anyone can help that would be fantastic.

in the C file i am adding underneath all of my includes:

#include <android/log.h>
#define LOG_TAG "test"
#define ALOG(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)

In the C code my logging line is being added as:

ALOG("This message comes from C at line %d.", __LINE__);

Build gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.3"

    defaultConfig {
        applicationId "com.app.matlabtest"
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        ndk {
            moduleName "com.app.matlabtest"
            ldLibs "log", "z", "m"
        }

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.google.android.gms:play-services-location:17.0.0'
    implementation 'com.google.android.gms:play-services-maps:17.0.0'
    implementation 'com.opencsv:opencsv:4.0'
    implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0'
    implementation 'com.karumi:dexter:6.1.0'
    implementation files('libs/jna-5.5.0.jar')
    compile group: 'commons-io', name: 'commons-io', version: '2.0.1'
}

Android.mk file:

LOCAL_PATH :=$(call my-dir)
LOCAL_LDLIBS  := -llog
include $(CLEAR_VARS)
LOCAL_MODULE := com.app.matlabtest
LOCAL_SRC_FILES := ...
...
... //all the C files
...
include $(BUILD_SHARED_LIBRARY)

The Library does not build with the logging lines in the C file. Just a list of undefined reference to `__android_log_print' which is really frustrating. I have tried every configuration mentioned on all questions, so pointing me to another question probably will not work for me.

I have now produced this new error:

I know get this:/Documents/MatLabTest/jni/dxfParseFileContentsNEW.c:3541:1: error: expected identifier
ALOG("This message comes from C at line %d.", __LINE__);
^
/Documents/MatLabTest/jni/dxfParseFileContentsNEW.c:46:56: note: expanded from macro 'ALOG'
#define ALOG(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
                                                       ^
/Documents/MatLabTest/jni/dxfParseFileContentsNEW.c:45:17: note: expanded from macro 'LOG_TAG'
#define LOG_TAG "test"
                ^
/Documents/MatLabTest/jni/dxfParseFileContentsNEW.c:3541:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
/Documents/MatLabTest/jni/dxfParseFileContentsNEW.c:46:19: note: expanded from macro 'ALOG'
#define ALOG(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
                  ^
/Documents/MatLabTest/jni/dxfParseFileContentsNEW.c:3541:1: error: conflicting types for '__android_log_print'
/Users/lead/Documents/MatLabTest/jni/dxfParseFileContentsNEW.c:46:19: note: expanded from macro 'ALOG'
#define ALOG(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)

Moved on to now get this in my debug window don't know if this is relevant or helpful my native code is C not C++:

Executing commands in '/Applications/Android Studio.app/Contents/bin/lldb/shared/stl_printers/load_script'.
(lldb) script import sys
(lldb) script import os
(lldb) script gala_available = os.environ.get('AS_GALA_PATH') is not None
(lldb) script exec("if gala_available: sys.path.append(os.environ['AS_GALA_PATH'])")
(lldb) script exec("if gala_available: import gdb")
(lldb) script exec("if gala_available: import gdb.printing")
(lldb) script libstdcxx_printers_available = gala_available and (os.environ.get('AS_LIBSTDCXX_PRINTER_PATH') is not None)
(lldb) script exec("if libstdcxx_printers_available: sys.path.append(os.environ['AS_LIBSTDCXX_PRINTER_PATH'])")
(lldb) script exec("if libstdcxx_printers_available: import printers")
(lldb) script exec("if libstdcxx_printers_available: printers.register_libstdcxx_printers(None)")
(lldb) script exec("if lldb.debugger.GetCategory('libstdc++-v6').IsValid(): lldb.debugger.GetCategory('gnu-libstdc++').SetEnabled(False)")

And here is the console output:

05/18 11:44:27: Launching 'app' on Pixel 3a API 28.
$ adb shell am start -n "com.app.matlabtest/com.app.matlabtest.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D
Waiting for application to come online: com.app.matlabtest | com.app.matlabtest.test
Waiting for application to come online: com.app.matlabtest | com.app.matlabtest.test
Connecting to com.app.matlabtest
Now Launching Native Debug Session
$ adb shell cat /data/local/tmp/lldb-server | run-as com.app.matlabtest sh -c 'cat > /data/data/com.app.matlabtest/lldb/bin/lldb-server && chmod 700 /data/data/com.app.matlabtest/lldb/bin/lldb-server'
$ adb shell cat /data/local/tmp/start_lldb_server.sh | run-as com.app.matlabtest sh -c 'cat > /data/data/com.app.matlabtest/lldb/bin/start_lldb_server.sh && chmod 700 /data/data/com.app.matlabtest/lldb/bin/start_lldb_server.sh'
Starting LLDB server: /data/data/com.app.matlabtest/lldb/bin/start_lldb_server.sh /data/data/com.app.matlabtest/lldb unix-abstract /com.app.matlabtest-0 platform-1589798669325.sock "lldb process:gdb-remote packets"
Debugger attached to process 22001
Signal: SIGABRT (signal SIGABRT)
docker dev
  • 91
  • 3
  • 10
  • 1
    I'm pretty sure `LOCAL_LDLIBS := -llog` needs to go **after** `include $(CLEAR_VARS)`, since `CLEAR_VARS` will clear most of the `LOCAL_` variables. – Michael May 17 '20 at 15:30
  • @Michael Wow, Thanks that made the libraries build no errors on building, however the logging messages are not being displayed in logcat? can you see any reason? – docker dev May 17 '20 at 16:38
  • @Michael Should i be getting logging showing in my logcat within android studio? – docker dev May 18 '20 at 08:42
  • I suppose. Assuming that your logging call actually gets executed, and that your device isn't filtering out logs below a certain severity level. – Michael May 18 '20 at 08:57
  • @Michael I now get the error i have added to the question, is there an issue with my logging? i was using an implementation advised. Any thoughts, need to get this working – docker dev May 18 '20 at 09:00
  • I can't reproduce that. But it looks kind of like you're trying to use `ALOG` somewhere before having included `android/log.h`. – Michael May 18 '20 at 09:21
  • @Michael Yes you were right i had a log line in a static import. Thanks, no error now but yet still no log outputs.. So frustrating. – docker dev May 18 '20 at 09:51
  • Well, try raising the log level from INFO to ERROR and see if that helps. And set a breakpoint at one of your log calls so that you can see that they're actually executed. – Michael May 18 '20 at 10:11
  • @Michael Thanks, Have done, nothing else out, when i try to set a break point in the C code, when i run it the breakpoint turns from the red dot to a white no entry type sign. So looks like that is not possible? – docker dev May 18 '20 at 10:18
  • @Michael In the debugger LLDB Window i get the output which i have added to the question above. Thanks for this help – docker dev May 18 '20 at 10:30

0 Answers0