I am facing a rather niche issue after updating AGP from 8.3.2 to 8.8.2 in our multimodule project, which we use to release a certain SDK.
We have isMinifyEnabled set to true in our library modules because we only expose the API relevant to our customers.
One of the components being published is this:
object LoggerProvider {
@JvmStatic
var logger: Logger = StubLogger()
}
It is intended to be used, for example, like this:
private val myLoggerFromThatSdk = LoggerProvider.logger
And it was before up until our update from AGP 8.3.2 to 8.8.2. Also, if you perform a command + click on .logger part, you will see this:
public object LoggerProvider {
@kotlin.jvm.JvmStatic public final var logger: com.example.sdk.util.log.Logger /* compiled code */
}
Meaning that it was recognized as Kotlin class. Also, at this point, if you click Decompile to Java, the code would look like this:
@Metadata(
mv = {2, 1, 0},
k = 1,
xi = 48,
d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0006\bÆ\u0002\u0018\u00002\u00020\u0001B\t\b\u0002¢\u0006\u0004\b\u0002\u0010\u0003R$\u0010\u0004\u001a\u00020\u00058\u0006@\u0006X\u0087\u000e¢\u0006\u0014\n\u0000\u0012\u0004\b\u0006\u0010\u0003\u001a\u0004\b\u0007\u0010\b\"\u0004\b\t\u0010\n¨\u0006\u000b"},
d2 = {"Lcom/example/sdk/util/log/LoggerProvider;", "", "<init>", "()V", "logger", "Lcom/example/sdk/util/log/Logger;", "getLogger$annotations", "getLogger", "()Lcom/example/sdk/util/log/Logger;", "setLogger", "(Lcom/example/sdk/util/log/Logger;)V", "Sources of com-example-sdk-android.core-base.main"}
)
public final class LoggerProvider {
@NotNull
public static final LoggerProvider INSTANCE = new LoggerProvider();
@NotNull
private static Logger logger = (Logger)(new StubLogger());
private LoggerProvider() { }
@NotNull
public static final Logger getLogger() { return logger; }
public static final void setLogger(@NotNull Logger var0) {
Intrinsics.checkNotNullParameter(var0, "<set-?>");
logger = var0;
}
/** @deprecated */
// $FF: synthetic method
@JvmStatic
public static void getLogger$annotations() { }
}
However, after the update to this new AGP, the line LoggerProvider.logger gives a compilation error at logger part. If you click it, you see this decompiled class (not a Kotlin one - Java at once!):
public final class LoggerProvider {
@NotNull
public static final LoggerProvider INSTANCE = new LoggerProvider();
@NotNull
private static Logger logger = new StubLogger();
private LoggerProvider() { }
@NotNull
public static final Logger getLogger() { return logger; }
public static final void setLogger(@NotNull Logger var0) {
Intrinsics.checkNotNullParameter(var0, "<set-?>");
logger = var0;
}
}
Note the metadata and this method being absent:
/** @deprecated */
// $FF: synthetic method
@JvmStatic
public static void getLogger$annotations() { }
I suspect a newer, stricter R8 is being bundled with this newer AGP, but I couldn't find any mention of relevant information or discussions online about this.
If anyone knows anything - I'd be very grateful.
UPDATE:
I was able to fix the issue, but I still don't understand the underlying logic of it.
Our *.pro files had -donkshrink option included from years ago.
Surprisingly, keeping it after the update to AGP 8.8.2 (or higher. I bet some lower versions are affected too but I didn't test it.) results in the given issue.
As soon as I removed this instruction - the issue was gone. If anyone understands why - you are welcome to share.
This is the issue reported in https://issuetracker.google.com/426163872.
There will be a fix at some point, but in general -dontshrink should only be used for debugging.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With