我正在尝试为 Android 编写 kotlin 库,但不能包含木材。我总是收到以下错误:
Error:error: unresolved reference: timber
Run Code Online (Sandbox Code Playgroud)
我的 build.gradle 中有这个:
apply plugin: 'java-library'
apply plugin: 'kotlin'
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
}
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
buildscript {
ext.kotlin_version = '1.1.2-4'
repositories {
maven {url "https://maven.google.com"}
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
compile 'com.jakewharton.timber:timber:4.5.1'
testCompile 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)
我的源文件目前非常简单:
package net.mbonnin.test
import timber.log.Timber
class Main() {
fun main() {
Timber.d("hello world")
}
} …Run Code Online (Sandbox Code Playgroud) 我正在使用 Timber 将一些日志写入位于设备上的文件。现在,我正在使用 HTTP 拦截器编写我选择的日志和来自服务器的一些响应。但我想在文件中写入所有异常(例如致命的)。木材或其他图书馆可以吗?
现在我正在使用 Fabric,但我的应用程序并不总是与外部世界有互联网连接
PS我想在没有try/catch的情况下编写所有致命异常
public class FileLoggingTree
{
/**
* Sends an error message to LogCat and to a log file.
* @param context The context of the application.
* @param logMessageTag A tag identifying a group of log messages. Should be a constant in the
* class calling the logger.
* @param logMessage The message to add to the log.
*/
public static void e(Context context, String logMessageTag, String logMessage)
{
if (!Log.isLoggable(logMessageTag, Log.ERROR)) …Run Code Online (Sandbox Code Playgroud) 在 Windows 7 上使用 Android Studio 1.5.1 和 gradle 2.8 或 2.10,尝试运行 gradle clean 时出现以下错误(仅在使用 Timber 时):
gradle clean
Incremental java compilation is an incubating feature.
WARNING [Project: :app] To shrink resources you must also enable ProGuard
:clean
:app:clean FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:clean'.
> Unable to delete file: C:\blabla\app\build\intermediates\exploded-aar\com.jakewharton.timber\timber\4.1.0\jars\lint.jar
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get …Run Code Online (Sandbox Code Playgroud) 我想在单独的模块中使用 wood 来处理我的 Android 应用程序中的日志记录,以便可以从任何模块调用它并记录到内部文件。
问题是,当在单独的类中使用自动标记而不是直接调用木材日志方法时,自动标记不起作用。
例如,我有一个日志记录类,其方法为Logger.kt:
fun d(message: String)
{
Timber.d(message)
}
Run Code Online (Sandbox Code Playgroud)
但是当我从任何地方调用它时,它显然使用日志类作为标记,而不是调用该方法的类。
所以我的问题是,如何通过此方法自动传递调用类?我不想添加像“TAG = classname”这样的附加变量,因为在这种情况下我也可以使用正常的日志记录。
是否可以检索方法的调用类?或者有更好的方法来进行集中日志记录吗?主要目的是不必定义 TAG 变量,同时还能够稍后添加文件日志记录。