Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

Android: How to enable printing to android console in external java library?

I'm using an external java library in my android project. Now I want to print stuff inside this library to the android debugging console.

The java library is linked via build.gradle as follows:

[...]
dpendencies {
    implementation project(path: ':MyCustomJavaLibrary')
}

Simply using System.out.println("My Message"); does compile, but the message does not appear in the corresponding debug console. Moreover I cannot use Android Log.d("...") inside the Java library.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is my solution (taken from a related Stackoverflow answer)

import java.util.logging.Level;
import java.util.logging.Logger;

public class MyClass{
    private final Logger logger = java.util.logging.Logger.getLogger("myLogger");
    private final Level log_level = java.util.logging.Level.INFO;
    [...]
    logger.log(log_level, "Start track_pose");
    [...]
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...