Open eugenelozada opened 7 years ago
I have the same but the app doesn't run fine for me - it crashes on pressing any button. This is on Android O Developer Preview but I understand that ManagementFactory was removed in API 20.
Seeing this issue on 7.1. Any work around for this issue ?
Lint reports all these imports not existing in Android:
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: java.lang.management. Referenced from org.apache.logging.log4j.core.jmx.Server.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.jms. Referenced from org.apache.logging.log4j.core.appender.mom.JmsAppender.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.mail.internet. Referenced from org.apache.logging.log4j.core.net.MimeMessageBuilder.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.mail.util. Referenced from org.apache.logging.log4j.core.net.SmtpManager.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.mail. Referenced from org.apache.logging.log4j.core.net.SmtpManager.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.management. Referenced from org.apache.logging.log4j.core.jmx.AppenderAdmin.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.naming. Referenced from org.apache.logging.log4j.core.appender.db.jdbc.DataSourceConnectionSource.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.persistence. Referenced from org.apache.logging.log4j.core.appender.db.jpa.JpaDatabaseManager.
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-core/2.2/c707664e020218f8529b9a5e55016ee15f0f82ac/log4j-core-2.2.jar: Invalid package reference in library; not included in Android: javax.xml.bind. Referenced from org.apache.logging.log4j.core.config.plugins.convert.TypeConverters.ByteArrayConverter.
In my case, being a lint issue, I solved it by adding this configuration:
<issue id="InvalidPackage">
<ignore regexp="org.apache.logging.log4j.core.*"/>
</issue>
It crashes my app on Android O
java.lang.NoClassDefFoundError: org.apache.logging.log4j.core.lookup.JmxRuntimeInputArgumentsLookup
at java.lang.reflect.Constructor.newInstance0(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:334)
at org.apache.logging.log4j.core.util.ReflectionUtil.instantiate(ReflectionUtil.java:185)
at org.apache.logging.log4j.core.lookup.Interpolator.
https://github.com/api-ai/apiai-android-client has transitive dependency on https://github.com/api-ai/apiai-java-client Which adds log4j to your app.
log4j was not really designed to work on Android VM, so the best way to solve your issue is to use different implementation.
compile 'ai.api:sdk:2.0.5@aar'
// api.ai SDK dependencies
compile('ai.api:libai:1.4.8') {
exclude module: 'log4j-core'
}
The example below still uses log4j-api
as logging entry-point, but it excludes whole implementation nonsense.
Then, the simplest way to configure default logging is by log4j2.component.properties
resource file:
log4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory
Define default log level log4j2.simplelog.properties
org.apache.logging.log4j.simplelog.level=DEBUG
Similar thing can be achieved in code - just add to your Application class:
static {
LogManager.setFactory(new SimpleLoggerContextFactory());
// but SimpleLoggerContextFactory does not allow to override log level in runtime
// I guess you would need to play with root logger, but it's easier to set it in resource file
}
At the end, your logs would be visible in stderr
. Ofc, you may also do your own LoggerContextFactory
implementation.
Question, when mentioning "Then, the simplest way to configure default logging is by log4j2.component.properties resource file:"
Where and how to setup this file for an Android project?
@sergiandreplace Just put into src/main/resources
folder
> tail -vn +1 src/main/resources/*
==> src/main/resources/log4j2.component.properties <==
log4j2.loggerContextFactory=org.apache.logging.log4j.simple.SimpleLoggerContextFactory
==> src/main/resources/log4j2.simplelog.properties <==
org.apache.logging.log4j.simplelog.level=DEBUG
Thanks, now it works perfectly on Android 8, buuuut, lint is not happy about it. It returns the error:
Package not included in Android
../../../../../.gradle/caches/modules-2/files-2.1/org.apache.logging.log4j/log4j-api/2.2/d7ef6ad7ff0711dd12fe409d62d72d6ed14516e0/log4j-api-2.2.jar: Invalid package reference in library; not included in Android: java.lang.management. Referenced from org.apache.logging.log4j.message.ExtendedThreadInformation.
This check scans through libraries looking for calls to APIs that are not included in Android.
As the ExtendedThreadInformation class is referencing java.lang.management classes that are not included in Android.
One option is to ignore the error, but I'm not really happy ignoring InvalidPackage errors.
More info. If I remove the exclusion on log4j-core, the apps crashes, but lint says nothing about the java.lang.management issue, despite the classes are not there. This looks like a weird behaviour from Lint.
No news on this issue? We stopped using dialogflow because this (it was an experimental feature)
But, as @vandalko said, log4j is not intended for android, so, why is this library using it?
I think df team should really remove it
I'm seeing these warnings on application startup
Rejecting re-init on previously-failed class java.lang.Class<org.apache.logging.log4j.core.lookup.JmxRuntimeInputArgumentsLookup>: java.lang.NoClassDefFoundError: Failed resolution of: Ljava/lang/management/ManagementFactory;
Likely due to the Java VM Android is running does not have those classes. Anyway we can exclude them fro being loaded or referenced? App still runs fine though.