如何设置 Apache Commons Logger
How to set up Apache Commons Logger
有人知道如何设置 Apache Commons Logger 吗?看起来像people got it running,但我失败得很惨。
我目前的设置非常简单:
build.gradle:
compile('commons-logging:commons-logging:1.2')
j2objcTranslation 'commons-logging:commons-logging:1.2'
记录器初始化:
private static Log logger = LogFactory.getLog(ApiService.class);
还有一个非常简单的logging.properties
文件,如果需要可以附上。
在 iOS 模拟器上翻译和 运行 后抛出以下异常:
2016-09-21 19:39:35.960 temple8-ios[32544:598370] Fucking logger
2016-09-21 19:39:36.048 temple8-ios[32544:598370] *** Terminating app due to uncaught exception 'OrgApacheCommonsLoggingLogConfigurationException', reason: 'java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl (Caused by java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl)'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e471d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d40cdeb objc_exception_throw + 48
2 temple8-ios 0x000000010c056a27 OrgApacheCommonsLoggingLogFactory_newFactoryWithNSString_withJavaLangClassLoader_withJavaLangClassLoader_ + 327
3 temple8-ios 0x000000010c059d06 OrgApacheCommonsLoggingLogFactory_getFactory + 3030
4 temple8-ios 0x000000010c056026 OrgApacheCommonsLoggingLogFactory_getLogWithIOSClass_ + 70
编辑 1
@tball 在 中提供了一些重要的细节,但这导致了一个新问题。我添加了对 LogFactoryImpl
的静态引用,并在项目中包含了 java.util.logging.IOSLogHandler
。尝试翻译 class 时,编译器会抛出以下错误:
/java/util/logging/IOSLogHandler.m:58:17: error: method definition for 'IOS_LOG_MANAGER_DEFAULTS' not found [-Werror,-Wincomplete-implementation]
@implementation JavaUtilLoggingIOSLogHandler
^
java/util/logging/IOSLogHandler.h:34:1: note: method 'IOS_LOG_MANAGER_DEFAULTS' declared here
+ (NSString *)IOS_LOG_MANAGER_DEFAULTS;
^
1 error generated.
我正在使用来自 j2objC github repository and have posted the generated IOSLogHandler.m
on gist 的最新版本 IOSLogHandler
。
非常感谢大家的帮助!
链接器不包含 org.apache.commons.logging.impl.LogFactoryImpl,因为它是动态加载的,因此在链接期间没有需要解析的引用。我不知道如何在 Gradle 中解决这个问题,但有两个通用解决方案:
Link 带有 -ObjC 标志,这会导致所有静态库中的所有 Objective C class 都链接到应用程序中。但是,这可能会引入很多不需要的 classes,因此请检查应用前后的二进制大小,看看是否可以接受。
在已链接到您的应用的 class 中,添加对 org.apache.commons.logging.impl.LogFactoryImpl 的引用。它可以很简单:
@SuppressWarnings("unused")
private static final Class loggingImplClass =
LogFactoryImpl.class;
有人知道如何设置 Apache Commons Logger 吗?看起来像people got it running,但我失败得很惨。
我目前的设置非常简单:
build.gradle:
compile('commons-logging:commons-logging:1.2')
j2objcTranslation 'commons-logging:commons-logging:1.2'
记录器初始化:
private static Log logger = LogFactory.getLog(ApiService.class);
还有一个非常简单的logging.properties
文件,如果需要可以附上。
在 iOS 模拟器上翻译和 运行 后抛出以下异常:
2016-09-21 19:39:35.960 temple8-ios[32544:598370] Fucking logger
2016-09-21 19:39:36.048 temple8-ios[32544:598370] *** Terminating app due to uncaught exception 'OrgApacheCommonsLoggingLogConfigurationException', reason: 'java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl (Caused by java.lang.ClassNotFoundException: org.apache.commons.logging.impl.LogFactoryImpl)'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e471d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010d40cdeb objc_exception_throw + 48
2 temple8-ios 0x000000010c056a27 OrgApacheCommonsLoggingLogFactory_newFactoryWithNSString_withJavaLangClassLoader_withJavaLangClassLoader_ + 327
3 temple8-ios 0x000000010c059d06 OrgApacheCommonsLoggingLogFactory_getFactory + 3030
4 temple8-ios 0x000000010c056026 OrgApacheCommonsLoggingLogFactory_getLogWithIOSClass_ + 70
编辑 1
@tball 在 LogFactoryImpl
的静态引用,并在项目中包含了 java.util.logging.IOSLogHandler
。尝试翻译 class 时,编译器会抛出以下错误:
/java/util/logging/IOSLogHandler.m:58:17: error: method definition for 'IOS_LOG_MANAGER_DEFAULTS' not found [-Werror,-Wincomplete-implementation]
@implementation JavaUtilLoggingIOSLogHandler
^
java/util/logging/IOSLogHandler.h:34:1: note: method 'IOS_LOG_MANAGER_DEFAULTS' declared here
+ (NSString *)IOS_LOG_MANAGER_DEFAULTS;
^
1 error generated.
我正在使用来自 j2objC github repository and have posted the generated IOSLogHandler.m
on gist 的最新版本 IOSLogHandler
。
非常感谢大家的帮助!
链接器不包含 org.apache.commons.logging.impl.LogFactoryImpl,因为它是动态加载的,因此在链接期间没有需要解析的引用。我不知道如何在 Gradle 中解决这个问题,但有两个通用解决方案:
Link 带有 -ObjC 标志,这会导致所有静态库中的所有 Objective C class 都链接到应用程序中。但是,这可能会引入很多不需要的 classes,因此请检查应用前后的二进制大小,看看是否可以接受。
在已链接到您的应用的 class 中,添加对 org.apache.commons.logging.impl.LogFactoryImpl 的引用。它可以很简单:
@SuppressWarnings("unused") private static final Class loggingImplClass = LogFactoryImpl.class;