在Android上禁用log4j JMX

来源:爱站网时间:2021-09-16编辑:网友分享
我正在尝试将Hyperledger Fabric Java SDK移植到Android(API级别26)。 SDK使用Log4j。 Log4j尚未针对android优化。我收到以下错误:I / System.out:警告:sun ....

问题描述


我正在尝试将Hyperledger Fabric Java SDK移植到Android(API级别26)。 SDK使用Log4j。 Log4j尚未针对android优化。我收到以下错误:

I/System.out: WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
I/icandroidsampl: Rejecting re-init on previously-failed class java.lang.Class: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;
        at void org.apache.logging.log4j.core.lookup.JmxRuntimeInputArgumentsLookup.() (JmxRuntimeInputArgumentsLookup.java:35)
        at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
        at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:343)
        at java.lang.Object org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(java.lang.Class) (LoaderUtil.java:185)
        at java.lang.Object org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(java.lang.String) (LoaderUtil.java:207)
        at java.lang.Object org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(java.lang.String, java.lang.Class) (LoaderUtil.java:228)
        at java.lang.Object org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(java.lang.String, java.lang.Class) (Loader.java:311)
        at void org.apache.logging.log4j.core.lookup.Interpolator.(java.util.Map) (Interpolator.java:120)
        at void org.apache.logging.log4j.core.config.AbstractConfiguration.(org.apache.logging.log4j.core.LoggerContext, org.apache.logging.log4j.core.config.ConfigurationSource) (AbstractConfiguration.java:129)
        at void org.apache.logging.log4j.core.config.NullConfiguration.() (NullConfiguration.java:32)
        at void org.apache.logging.log4j.core.LoggerContext.() (LoggerContext.java:86)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(java.lang.String, java.net.URI) (ClassLoaderContextSelector.java:229)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(java.lang.ClassLoader, java.net.URI) (ClassLoaderContextSelector.java:203)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(java.lang.String, java.lang.ClassLoader, boolean, java.net.URI) (ClassLoaderContextSelector.java:128)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(java.lang.String, java.lang.ClassLoader, boolean) (ClassLoaderContextSelector.java:115)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(java.lang.String, java.lang.ClassLoader, java.lang.Object, boolean) (Log4jContextFactory.java:148)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(java.lang.String, java.lang.ClassLoader, java.lang.Object, boolean) (Log4jContextFactory.java:45)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.LogManager.getContext(java.lang.ClassLoader, boolean) (LogManager.java:194)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(java.lang.Class) (AbstractLoggerAdapter.java:138)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.jcl.LogAdapter.getContext() (LogAdapter.java:39)
        at java.lang.Object org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(java.lang.String) (AbstractLoggerAdapter.java:48)
        at org.apache.commons.logging.Log org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(java.lang.String) (LogFactoryImpl.java:40)
        at org.apache.commons.logging.Log org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(java.lang.Class) (LogFactoryImpl.java:55)
        at org.apache.commons.logging.Log org.apache.commons.logging.LogFactory.getLog(java.lang.Class) (LogFactory.java:655)
        at void org.hyperledger.fabric.gateway.impl.GatewayImpl.() (GatewayImpl.java:55)
        at java.util.concurrent.TimeUnit org.hyperledger.fabric.gateway.impl.GatewayImpl.access$000() (GatewayImpl.java:54)
        at void org.hyperledger.fabric.gateway.impl.GatewayImpl$Builder.() (GatewayImpl.java:71)
        at org.hyperledger.fabric.gateway.Gateway$Builder org.hyperledger.fabric.gateway.Gateway.createBuilder() (Gateway.java:87)
        at java.lang.String tubs.ibr.fabricandroidsample.MainActivity$FabricRequestTask.doInBackground(java.lang.Object[]) (MainActivity.java:78)
        at java.lang.Object tubs.ibr.fabricandroidsample.MainActivity$FabricRequestTask.doInBackground(java.lang.Object[]) (MainActivity.java:70)
        at java.lang.Object android.os.AsyncTask$2.call() (AsyncTask.java:333)
        at void java.util.concurrent.FutureTask.run() (FutureTask.java:266)
        at void android.os.AsyncTask$SerialExecutor$1.run() (AsyncTask.java:245)
        at void java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) (ThreadPoolExecutor.java:1167)
        at void java.util.concurrent.ThreadPoolExecutor$Worker.run() (ThreadPoolExecutor.java:641)
I/icandroidsampl:     at void java.lang.Thread.run() (Thread.java:764)
    Caused by: java.lang.ClassNotFoundException: Didn't find class "java.lang.management.ManagementFactory" on path: DexPathList[[zip file "/data/app/tubs.ibr.fabricandroidsample-48U2GXMv9D0UPIKFDpmpOA==/base.apk"],nativeLibraryDirectories=[/data/app/tubs.ibr.fabricandroidsample-48U2GXMv9D0UPIKFDpmpOA==/lib/x86, /system/lib]]
        at java.lang.Class dalvik.system.BaseDexClassLoader.findClass(java.lang.String) (BaseDexClassLoader.java:134)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String, boolean) (ClassLoader.java:379)
        at java.lang.Class java.lang.ClassLoader.loadClass(java.lang.String) (ClassLoader.java:312)
        at void org.apache.logging.log4j.core.lookup.JmxRuntimeInputArgumentsLookup.() (JmxRuntimeInputArgumentsLookup.java:35)
        at java.lang.Object java.lang.reflect.Constructor.newInstance0(java.lang.Object[]) (Constructor.java:-2)
        at java.lang.Object java.lang.reflect.Constructor.newInstance(java.lang.Object[]) (Constructor.java:343)
        at java.lang.Object org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(java.lang.Class) (LoaderUtil.java:185)
        at java.lang.Object org.apache.logging.log4j.util.LoaderUtil.newInstanceOf(java.lang.String) (LoaderUtil.java:207)
        at java.lang.Object org.apache.logging.log4j.util.LoaderUtil.newCheckedInstanceOf(java.lang.String, java.lang.Class) (LoaderUtil.java:228)
        at java.lang.Object org.apache.logging.log4j.core.util.Loader.newCheckedInstanceOf(java.lang.String, java.lang.Class) (Loader.java:311)
        at void org.apache.logging.log4j.core.lookup.Interpolator.(java.util.Map) (Interpolator.java:120)
        at void org.apache.logging.log4j.core.config.AbstractConfiguration.(org.apache.logging.log4j.core.LoggerContext, org.apache.logging.log4j.core.config.ConfigurationSource) (AbstractConfiguration.java:129)
        at void org.apache.logging.log4j.core.config.NullConfiguration.() (NullConfiguration.java:32)
        at void org.apache.logging.log4j.core.LoggerContext.() (LoggerContext.java:86)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.createContext(java.lang.String, java.net.URI) (ClassLoaderContextSelector.java:229)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.locateContext(java.lang.ClassLoader, java.net.URI) (ClassLoaderContextSelector.java:203)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(java.lang.String, java.lang.ClassLoader, boolean, java.net.URI) (ClassLoaderContextSelector.java:128)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.selector.ClassLoaderContextSelector.getContext(java.lang.String, java.lang.ClassLoader, boolean) (ClassLoaderContextSelector.java:115)
        at org.apache.logging.log4j.core.LoggerContext org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(java.lang.String, java.lang.ClassLoader, java.lang.Object, boolean) (Log4jContextFactory.java:148)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(java.lang.String, java.lang.ClassLoader, java.lang.Object, boolean) (Log4jContextFactory.java:45)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.LogManager.getContext(java.lang.ClassLoader, boolean) (LogManager.java:194)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.spi.AbstractLoggerAdapter.getContext(java.lang.Class) (AbstractLoggerAdapter.java:138)
        at org.apache.logging.log4j.spi.LoggerContext org.apache.logging.log4j.jcl.LogAdapter.getContext() (LogAdapter.java:39)
        at java.lang.Object org.apache.logging.log4j.spi.AbstractLoggerAdapter.getLogger(java.lang.String) (AbstractLoggerAdapter.java:48)
I/icandroidsampl:     at org.apache.commons.logging.Log org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(java.lang.String) (LogFactoryImpl.java:40)
        at org.apache.commons.logging.Log org.apache.logging.log4j.jcl.LogFactoryImpl.getInstance(java.lang.Class) (LogFactoryImpl.java:55)
        at org.apache.commons.logging.Log org.apache.commons.logging.LogFactory.getLog(java.lang.Class) (LogFactory.java:655)
        at void org.hyperledger.fabric.gateway.impl.GatewayImpl.() (GatewayImpl.java:55)
        at java.util.concurrent.TimeUnit org.hyperledger.fabric.gateway.impl.GatewayImpl.access$000() (GatewayImpl.java:54)
        at void org.hyperledger.fabric.gateway.impl.GatewayImpl$Builder.() (GatewayImpl.java:71)
        at org.hyperledger.fabric.gateway.Gateway$Builder org.hyperledger.fabric.gateway.Gateway.createBuilder() (Gateway.java:87)
        at java.lang.String tubs.ibr.fabricandroidsample.MainActivity$FabricRequestTask.doInBackground(java.lang.Object[]) (MainActivity.java:78)
        at java.lang.Object tubs.ibr.fabricandroidsample.MainActivity$FabricRequestTask.doInBackground(java.lang.Object[]) (MainActivity.java:70)
        at java.lang.Object android.os.AsyncTask$2.call() (AsyncTask.java:333)
        at void java.util.concurrent.FutureTask.run() (FutureTask.java:266)
        at void android.os.AsyncTask$SerialExecutor$1.run() (AsyncTask.java:245)
        at void java.util.concurrent.ThreadPoolExecutor.runWorker(java.util.concurrent.ThreadPoolExecutor$Worker) (ThreadPoolExecutor.java:1167)
        at void java.util.concurrent.ThreadPoolExecutor$Worker.run() (ThreadPoolExecutor.java:641)
        at void java.lang.Thread.run() (Thread.java:764)

之所以会这样,是因为Android Runtime中不包含java.lang.management.ManagementFactory。

所以,我试图禁用JMX。没有成功同样的错误。像系统属性这样的接缝不在库的“范围”内?这怎么可能?

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        System.setProperty("log4j2.disable.jmx","true");

        [...]
    }
[...]
}

我也尝试过:https://loune.net/2016/05/using-log4j2-2-3-with-android/。没有成功同样的错误。

问题是,我正在使用的库中使用了log4j。因此,我不是在寻找在Android中使用日志记录的方法,而是在Android中配置log4j的方法,因此它不会引发异常。

[请帮助,我花了一整天的时间来解决这个问题。

思路:


Log4j 2不正式支持Android。这主要是因为没有一个Log4j提交者针对Android开发。就是说,只要我们有参与者可以帮助使其正常工作并验证新版本,我们将乐于使其正常工作。我建议您参加Log4j开发人员的列表,并提供所有可能的帮助。这主要包括报告与上述错误类似的错误,可能提交修补程序请求以及测试修补程序。话虽如此,由于Android对JDK中类的限制,我不能保证可以解决所有问题,但我们很乐意尝试。

上一篇:如何单击Web元素以显示日期选择器?

下一篇:从Java头开始

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载