我知道这个问题已经被问了一百万次,但是我已经尝试了列出所有类型配置的所有方法,但无法让它工作。我真的需要从我的 C 代码中获取日志信息。如果有人可以提供帮助,我将分享相关文件,这将是非常棒的。
在 C 文件中,我在所有包含项下添加:
#include <android/log.h>
#define LOG_TAG "test"
#define ALOG(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
在 C 代码中,我的日志记录行被添加为:
ALOG("This message comes from C at line %d.", __LINE__);
构建梯度:
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 文件:
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)
库不使用 C 文件中的日志记录行构建。只是对 `__android_log_print' 的未定义引用列表,这真的很令人沮丧。我已经尝试了所有问题中提到的所有配置,因此向我指出另一个问题可能对我不起作用。
我现在产生了这个新错误:
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__)
继续现在在我的调试窗口中得到这个不知道这是否相关或有帮助我的本机代码是 C 而不是 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)")
这是控制台输出:
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)