Skip to content

Commit

Permalink
Update Android samples
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiusTheBest committed Feb 6, 2022
1 parent a6b5e51 commit 8b4cccc
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 33 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ target_include_directories(plog
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

if(ANDROID)
target_link_libraries(plog INTERFACE log)
endif()

add_library(plog::plog ALIAS plog)

#making sure we can build standalone under windows
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Android - shows how to use the android-specific appender.
// AndroidJNI - shows how to use the Android appender in JNI.
//

#include <jni.h>
Expand All @@ -8,11 +8,15 @@
#include <plog/Appenders/AndroidAppender.h>
#include <plog/Formatters/FuncMessageFormatter.h>

extern "C" void Java_com_github_sergius_myapp_Sample_foo(JNIEnv* env, jobject obj)
extern "C" jint JNI_Onload(JavaVM*, void*)
{
// For simplicity the logger is initialized here. But the good place is JNI_OnLoad.
static plog::AndroidAppender<plog::FuncMessageFormatter> appender("MyApp"); // Create an appender and set a log tag.
static plog::Logger<0>& logger = plog::init(plog::debug, &appender); // Initialize the logger with the appender.
plog::init(plog::debug, &appender); // Initialize the logger with the appender.

return JNI_VERSION_1_6;
}

extern "C" void Java_com_github_sergius_myapp_Sample_foo(JNIEnv*, jobject)
{
PLOGD << "Hello Android!";
}
23 changes: 23 additions & 0 deletions samples/Android/AndroidNative/Main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// AndroidNative - shows how to use an Android appender.
//

#include <plog/Log.h>
#include <plog/Init.h>
#include <plog/Formatters/TxtFormatter.h>
#include <plog/Appenders/AndroidAppender.h>

int main()
{
static plog::AndroidAppender<plog::TxtFormatter> androidAppender("app");
plog::init(plog::verbose, &androidAppender);

PLOG_VERBOSE << "This is a VERBOSE message";
PLOG_DEBUG << "This is a DEBUG message";
PLOG_INFO << "This is an INFO message";
PLOG_WARNING << "This is a WARNING message";
PLOG_ERROR << "This is an ERROR message";
PLOG_FATAL << "This is a FATAL message";

return 0;
}
15 changes: 13 additions & 2 deletions samples/Android/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
add_custom_target(Android SOURCES jni/Sample.cpp)
set_target_properties(Android PROPERTIES FOLDER Samples)
if(ANDROID)
add_library(AndroidJNI SHARED AndroidJNI/Main.cpp)
target_link_libraries(AndroidJNI plog)

add_executable(AndroidNative AndroidNative/Main.cpp)
target_link_libraries(AndroidNative plog)
else()
add_custom_target(AndroidJNI SOURCES AndroidJNI/Main.cpp)
add_custom_target(AndroidNative SOURCES AndroidNative/Main.cpp)
endif()

set_target_properties(AndroidJNI PROPERTIES FOLDER Samples/Android)
set_target_properties(AndroidNative PROPERTIES FOLDER Samples/Android)
25 changes: 0 additions & 25 deletions samples/Android/jni/Android.mk

This file was deleted.

2 changes: 0 additions & 2 deletions samples/Android/jni/Application.mk

This file was deleted.

0 comments on commit 8b4cccc

Please sign in to comment.