Skip to content

Commit

Permalink
Workaround for d8 error on java targets
Browse files Browse the repository at this point in the history
Summary:
The `io.micrometer` classes are causing errors (`NullPointerException` with v29.0.2, and other compilation errors with v33.0.0) when running `d8`.

Updating our custom desguaring to drop methods in those classes as a workaround for now until we root cause the issue.

Although this gets the build going again, it does result in `d8` emitting a ton of warnings, which we should also get to the root of.

Reviewed By: arthaud

Differential Revision: D55156395

fbshipit-source-id: ec8cc546fafd2b1e465e61b660921044f3cd4577
  • Loading branch information
Yuh Shin Ong authored and facebook-github-bot committed Mar 21, 2024
1 parent e5ead0f commit 3268cba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions desugar/com/facebook/marianatrench/MethodHandleVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@
import org.objectweb.asm.signature.SignatureVisitor;

public class MethodHandleVisitor extends ClassVisitor {
private boolean mSkipMethodForClass = false;

public MethodHandleVisitor(ClassVisitor next) {
super(ASM9, next);
}

@Override
public void visit(
int version,
int access,
String name,
String signature,
String superName,
String[] interfaces) {
if (name.contains("io/micrometer/")) {
// D8 does not run cleanly on this package. Needs further investigation.
// Meanwhile, remove methods in it.
System.out.println("Skipping methods in class: " + name);
mSkipMethodForClass = true;
}
super.visit(version, access, name, signature, superName, interfaces);
}

@Override
public MethodVisitor visitMethod(
int access, String name, String desc, String signature, String[] exceptions) {
if (mSkipMethodForClass) {
return null;
}
return new ProcessVisitMethodInsn(super.visitMethod(access, name, desc, signature, exceptions));
}

Expand Down
5 changes: 5 additions & 0 deletions shim/shim.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ def _build_apk_from_jar(jar_path: Path) -> Path:
LOG.info(f"Running d8 on `{jar_path}`...")
output = subprocess.run(
[
# v33 does not run cleanly in some cases.
# Needs further investigation.
# Meanwhile v29.0.2 works but produces warnings likely due to lack
# of Java 11 support.
# "/opt/android/sdk_DEFAULT/build-tools/33.0.0/d8",
"/opt/android/sdk_DEFAULT/build-tools/29.0.2/d8",
"-JXmx8G",
jar_path,
Expand Down

0 comments on commit 3268cba

Please sign in to comment.