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)