Bazel: Android master build causes dexing issue with ArrayIndexOutOfBoundsException

Created on 3 Oct 2018  Â·  19Comments  Â·  Source: bazelbuild/bazel

Description of the problem / feature request:

The Bazel Master is causing a dexing exception to be thrown. This succeeds with the stable 0.17.2 version.

Feature requests: what underlying problem are you trying to solve with this feature?

Build with the latest master branch.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Assumes an executable version of the Bazel master branch called bazel-master

  1. git clone [email protected]:sunyal/bazel.git
  2. git checkout dexing-issue
  3. Update WORKSPACE androidndk path
  4. bazel-master build //examples/android/java/bazel:hello_world

What operating system are you running Bazel on?

MacOS High Sierra
version 10.13.6

What's the output of bazel info release?

Source downloaded on "02 Oct 18 17:00"

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

[email protected]:sunyal/bazel.git
4cc28d8679c62bb42e9a05bcc546c584b8d2d60a
07ed27a7b7f682cfbe29fff28af1e16533a45ace

Have you found anything relevant by searching the web?

No

Any other information, logs, or outputs that you want to share?

This is the stacktrace that gets produced

ERROR: /Users/abeggs/projects/bazel/bazel/third_party_additional/BUILD.bazel:2:1: Dexing third_party_additional/_dx/com_googlecode_mp4parser__isoparser__1_1_21/isoparser-1.1.21.jar_desugared.jar with applicable dexopts [] failed (Exit 1)
java.util.concurrent.ExecutionException: com.android.dx.cf.code.SimException: 3
    at java.base/java.util.concurrent.FutureTask.report(Unknown Source)
    at java.base/java.util.concurrent.FutureTask.get(Unknown Source)
    at com.google.devtools.build.android.dexer.DexBuilder.produceDexArchive(DexBuilder.java:253)
    at com.google.devtools.build.android.dexer.DexBuilder.processRequest(DexBuilder.java:218)
    at com.google.devtools.build.android.dexer.DexBuilder.runPersistentWorker(DexBuilder.java:173)
    at com.google.devtools.build.android.dexer.DexBuilder.main(DexBuilder.java:121)
Caused by: com.android.dx.cf.code.SimException: 3
    at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:814)
    at com.android.dx.cf.code.Simulator.simulate(Simulator.java:117)
    at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:789)
    at com.android.dx.cf.code.Ropper.doit(Ropper.java:744)
    at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
    at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:309)
    at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:150)
    at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:102)
    at com.google.devtools.build.android.dexer.Dexing.addToDexFile(Dexing.java:198)
    at com.google.devtools.build.android.dexer.DexConverter.toDexFile(DexConverter.java:31)
    at com.google.devtools.build.android.dexer.DexConversionEnqueuer$ClassToDex.call(DexConversionEnqueuer.java:173)
    at com.google.devtools.build.android.dexer.DexConversionEnqueuer$ClassToDex.call(DexConversionEnqueuer.java:156)
    at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
    at com.android.dx.cf.code.ExecutionStack.setLocal(ExecutionStack.java:187)
    at com.android.dx.cf.code.BaseMachine.storeResults(BaseMachine.java:571)
    at com.android.dx.cf.code.ValueAwareMachine.run(ValueAwareMachine.java:208)
    at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:306)
    at com.android.dx.cf.code.Simulator$SimVisitor.visitLocal(Simulator.java:649)
    at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:412)
    ... 15 more
Target //examples/android/java/bazel:hello_world failed to build
P3 team-Android

Most helpful comment

Based on history around this I would guess that the problematic Jar, com.googlecode.mp4parser:isoparser:1.1.21, has missing or invalid stack map frames. you'll want to fix those (either by fixing at the source, or by recomputing them using, e.g., ASM) before depending on the Jar from an android_binary.

All 19 comments

@jin

There seems to be an issue with with dexing a desugared com.googlecode.mp4parser:isoparser:1.1.21

Can confirm that https://github.com/bazelbuild/bazel/commit/209c82eb5f56dceb30b9fab22c7cb8383507e131 "fixes" this and makes it build, but it was reverted in https://github.com/bazelbuild/bazel/commit/9f7545e6de638e63b25d8454e95305289c3fea94

cc @cushon @kevin1e100

@sunyal your repro example uses an internal Artifactory URL. I created a barebones minimal repro here: https://github.com/jin/repro/tree/master/6299

Based on history around this I would guess that the problematic Jar, com.googlecode.mp4parser:isoparser:1.1.21, has missing or invalid stack map frames. you'll want to fix those (either by fixing at the source, or by recomputing them using, e.g., ASM) before depending on the Jar from an android_binary.

I agree with @kevin1e100. Another option is to run proguard over the invalid jar file. As long as -dontpreverify isn't set it will fix the stack map frames.

It's also probably not a P1 since the issue is invalid input and not a bug in Bazel, and I don't think we have good options for working around it.

here's a diff of the bad / good desugared jars

$ java -jar jardiff.jar bad-isoparser-1.1.21.jar_desugared.jar good-isoparser-1.1.21.jar_desugared.jar

diff --git a/org/mp4parser/aspectj/lang/Aspects14.class.asm b/org/mp4parser/aspectj/lang/Aspects14.class.asm
index e329e53..b638a28 100644
--- a/org/mp4parser/aspectj/lang/Aspects14.class.asm
+++ b/org/mp4parser/aspectj/lang/Aspects14.class.asm
@@ -68,7 +68,7 @@
     ANEWARRAY java/lang/Object
     PUTSTATIC org/mp4parser/aspectj/lang/Aspects14.EMPTY_OBJECT_ARRAY : [Ljava/lang/Object;
     RETURN
-    MAXSTACK = 6
+    MAXSTACK = 5
     MAXLOCALS = 0

   // access flags 0x1
@@ -109,7 +109,7 @@
     ALOAD 1
     INVOKESPECIAL org/mp4parser/aspectj/lang/NoAspectBoundException.<init> (Ljava/lang/String;Ljava/lang/Throwable;)V
     ATHROW
-    MAXSTACK = 3
+    MAXSTACK = 4
     MAXLOCALS = 2

   // access flags 0x9
@@ -276,7 +276,7 @@
     INVOKEVIRTUAL java/lang/Throwable.getMessage ()Ljava/lang/String;
     INVOKESPECIAL java/lang/NoClassDefFoundError.<init> (Ljava/lang/String;)V
     ATHROW
-    MAXSTACK = 2
+    MAXSTACK = 3
     MAXLOCALS = 2

   // access flags 0xA
diff --git a/org/mp4parser/aspectj/lang/NoAspectBoundException.class.asm b/org/mp4parser/aspectj/lang/NoAspectBoundException.class.asm
index e84b6e1..5db81a5 100644
--- a/org/mp4parser/aspectj/lang/NoAspectBoundException.class.asm
+++ b/org/mp4parser/aspectj/lang/NoAspectBoundException.class.asm
@@ -32,7 +32,7 @@
     ALOAD 2
     PUTFIELD org/mp4parser/aspectj/lang/NoAspectBoundException.cause : Ljava/lang/Throwable;
     RETURN
-    MAXSTACK = 4
+    MAXSTACK = 3
     MAXLOCALS = 3

   // access flags 0x1
diff --git a/org/mp4parser/aspectj/runtime/internal/CFlowCounter.class.asm b/org/mp4parser/aspectj/runtime/internal/CFlowCounter.class.asm
index 6eb0f7e..88e9f55 100644
--- a/org/mp4parser/aspectj/runtime/internal/CFlowCounter.class.asm
+++ b/org/mp4parser/aspectj/runtime/internal/CFlowCounter.class.asm
@@ -160,6 +160,6 @@
     PUTSTATIC org/mp4parser/aspectj/runtime/internal/CFlowCounter.tsFactory : Lorg/mp4parser/aspectj/runtime/internal/cflowstack/ThreadStackFactory;
    L8
     RETURN
-    MAXSTACK = 3
+    MAXSTACK = 2
     MAXLOCALS = 3
 }
diff --git a/org/mp4parser/aspectj/runtime/internal/CFlowStack.class.asm b/org/mp4parser/aspectj/runtime/internal/CFlowStack.class.asm
index dd0ccb9..c3c2908 100644
--- a/org/mp4parser/aspectj/runtime/internal/CFlowStack.class.asm
+++ b/org/mp4parser/aspectj/runtime/internal/CFlowStack.class.asm
@@ -44,7 +44,7 @@
     INVOKEVIRTUAL org/mp4parser/aspectj/runtime/CFlow.get (I)Ljava/lang/Object;
    L1
     ARETURN
-    MAXSTACK = 3
+    MAXSTACK = 2
     MAXLOCALS = 3

   // access flags 0xA
@@ -111,7 +111,7 @@
     ICONST_0
    L1
     IRETURN
-    MAXSTACK = 2
+    MAXSTACK = 1
     MAXLOCALS = 1

   // access flags 0x1
@@ -300,6 +300,6 @@
     PUTSTATIC org/mp4parser/aspectj/runtime/internal/CFlowStack.tsFactory : Lorg/mp4parser/aspectj/runtime/internal/cflowstack/ThreadStackFactory;
    L8
     RETURN
-    MAXSTACK = 3
+    MAXSTACK = 2
     MAXLOCALS = 3
 }
diff --git a/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.class.asm b/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.class.asm
index bf3e9ec..33e78c7 100644
--- a/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.class.asm
+++ b/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadCounterImpl11.class.asm
@@ -185,7 +185,7 @@
     ICONST_0
    L1
     IRETURN
-    MAXSTACK = 2
+    MAXSTACK = 1
     MAXLOCALS = 1

   // access flags 0x1
diff --git a/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl$ThreadCounterImpl.class.asm b/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl$ThreadCounterImpl.class.asm
index 9fc7485..15faed6 100644
--- a/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl$ThreadCounterImpl.class.asm
+++ b/org/mp4parser/aspectj/runtime/internal/cflowstack/ThreadStackFactoryImpl$ThreadCounterImpl.class.asm
@@ -81,7 +81,7 @@
     ICONST_0
    L1
     IRETURN
-    MAXSTACK = 2
+    MAXSTACK = 1
     MAXLOCALS = 1

   // access flags 0x1
diff --git a/org/mp4parser/aspectj/runtime/reflect/Factory.class.asm b/org/mp4parser/aspectj/runtime/reflect/Factory.class.asm
index 2a2b551..eeb0369 100644
--- a/org/mp4parser/aspectj/runtime/reflect/Factory.class.asm
+++ b/org/mp4parser/aspectj/runtime/reflect/Factory.class.asm
@@ -127,7 +127,7 @@
     INVOKEVIRTUAL java/lang/Throwable.getMessage ()Ljava/lang/String;
     INVOKESPECIAL java/lang/NoClassDefFoundError.<init> (Ljava/lang/String;)V
     ATHROW
-    MAXSTACK = 2
+    MAXSTACK = 3
     MAXLOCALS = 2

   // access flags 0x1
diff --git a/org/mp4parser/aspectj/runtime/reflect/InitializerSignatureImpl.class.asm b/org/mp4parser/aspectj/runtime/reflect/InitializerSignatureImpl.class.asm
index 5575f2e..825b848 100644
--- a/org/mp4parser/aspectj/runtime/reflect/InitializerSignatureImpl.class.asm
+++ b/org/mp4parser/aspectj/runtime/reflect/InitializerSignatureImpl.class.asm
@@ -24,7 +24,7 @@
     GETSTATIC org/mp4parser/aspectj/runtime/reflect/SignatureImpl.EMPTY_CLASS_ARRAY : [Ljava/lang/Class;
     INVOKESPECIAL org/mp4parser/aspectj/runtime/reflect/CodeSignatureImpl.<init> (ILjava/lang/String;Ljava/lang/Class;[Ljava/lang/Class;[Ljava/lang/String;[Ljava/lang/Class;)V
     RETURN
-    MAXSTACK = 8
+    MAXSTACK = 7
     MAXLOCALS = 3

   // access flags 0x0
@@ -110,6 +110,6 @@
     LDC "<init>"
    L1
     ARETURN
-    MAXSTACK = 2
+    MAXSTACK = 1
     MAXLOCALS = 1
 }
diff --git a/org/mp4parser/aspectj/runtime/reflect/JoinPointImpl.class.asm b/org/mp4parser/aspectj/runtime/reflect/JoinPointImpl.class.asm
index 6e43950..7e087dc 100644
--- a/org/mp4parser/aspectj/runtime/reflect/JoinPointImpl.class.asm
+++ b/org/mp4parser/aspectj/runtime/reflect/JoinPointImpl.class.asm
@@ -341,7 +341,7 @@
     ALOAD 9
     INVOKEVIRTUAL org/mp4parser/aspectj/runtime/internal/AroundClosure.run ([Ljava/lang/Object;)Ljava/lang/Object;
     ARETURN
-    MAXSTACK = 17
+    MAXSTACK = 4
     MAXLOCALS = 13

   // access flags 0x1
diff --git a/org/mp4parser/aspectj/runtime/reflect/MethodSignatureImpl.class.asm b/org/mp4parser/aspectj/runtime/reflect/MethodSignatureImpl.class.asm
index a767260..f71d02f 100644
--- a/org/mp4parser/aspectj/runtime/reflect/MethodSignatureImpl.class.asm
+++ b/org/mp4parser/aspectj/runtime/reflect/MethodSignatureImpl.class.asm
@@ -145,7 +145,7 @@
     ALOAD 0
     GETFIELD org/mp4parser/aspectj/runtime/reflect/MethodSignatureImpl.method : Ljava/lang/reflect/Method;
     ARETURN
-    MAXSTACK = 5
+    MAXSTACK = 6
     MAXLOCALS = 4

   // access flags 0x1
@@ -235,6 +235,6 @@
    L6
     ACONST_NULL
     ARETURN
-    MAXSTACK = 4
+    MAXSTACK = 5
     MAXLOCALS = 8
 }

@cushon thanks for the tip about running proguard. I can confirm that with this proguard config in android_binary.proguard_specs, the desugared jar can be dexed correctly:

-dontwarn com.googlecode.mp4parser.**
-keep public class **
-dontoptimize

@sunyal do you mind trying this method out?

@cushon I have a couple of questions.

  1. How does the library get into this particular state? Seeing the comments it appears that Espresso had a similar issue.
    https://github.com/sannies/mp4parser/
  2. How do we correct this without using proguard on the library itself or introducing those proguard specs into the build?

The espresso build was using proguard with -dontpreverify set, which produces bytecode that leads to this problem.

Is that library using proguard or any other bytecode rewriting tools?

To provide a little background, the problem occurs if bytecode has missing or ill-formed StackMapTable attributes [1], and is rewritten using ASM. Recent versions of ASM require Java 7 and newer bytecode to have valid StackMapTable attributes when computing the max_stack size of a code attribute [2].

Note that StackMapTable attributes are required starting in Java 7, so code omitting those attributes doesn't verify. (The verification can be disabled on JDK 7 by passing -XX:-UseSplitVerifier, but support for that configuration was removed in 8.)

In the example in this bug desugar rewrites some code with invalid StackMapTable attributes using ASM, and then ASM can't compute the proper max_stack value, and then dx crashes processing the code because it relies on max_stack being correct.

[1] https://docs.oracle.com/javase/specs/jvms/se11/html/jvms-4.html#jvms-4.7.4
[2] https://gitlab.ow2.org/asm/asm/commit/0c4423ba22450f8cad2649615a0d6826d65bbf7c#2dadfa4c5a4913d71ddc2f4dd9c7d9190f4a0c64_48_48

@cushon thanks for the explanation. I had some understanding yesterday based around potentially ASM causing some issues with the StackMapTable attributes.
I took a few approaches to try to mitigate the issues:

  1. Upgraded to the latest jar 1.9.27
  2. It does look like there are ASM libraries being used by different plugins, such as AspectJ, shader.
    I have updated aspectj plugins and libraries to the latest versions. I also updated to the latest maven compile and shader plugins. Change the complianceLevels https://github.com/sannies/mp4parser/blob/master/isoparser/pom.xml#L46
    Change the source and target values for compilation
    https://github.com/sannies/mp4parser/blob/master/isoparser/pom.xml#L67

I know these were stabs in the dark, and unfortunately I still ran into the same issue with the SimException

Why does the stable version of Bazel not fail on this?

It turns out this is a desugar bug after all.

The aspectj bytecode omits StackMapTables, but it's also v45 bytecode, so that should be OK.

However desugar is upgrading the major version to v51, which isn't allowed to omit StackMapTables:

-Classfile jar:file:/tmp/tmp.PyxciKLQPH/repro/6299/isoparser-1.9.38-SNAPSHOT.jar!/org/mp4parser/aj/lang/Aspects14.class
-  Last modified Oct 5, 2018; size 4859 bytes
-  MD5 checksum ef4eb474439a6cb66dcfd68a450620a6
+Classfile jar:file:/tmp/tmp.PyxciKLQPH/repro/6299/bazel-out/android-armeabi-v7a-fastbuild/bin/_dx/local/isoparser-1.9.38-SNAPSHOT.jar_desugared.jar!/org/mp4parser/aj/lang/Aspects14.class
+  Last modified Jan 1, 1980; size 4829 bytes
+  MD5 checksum 4c5a90826f2648c03c8331ae2c4fb3ca
   Compiled from "Aspects14.java"
 public class org.mp4parser.aj.lang.Aspects14
-  minor version: 3
-  major version: 45
+  minor version: 0
+  major version: 51
   flags: ACC_PUBLIC, ACC_SUPER
...
   public static java.lang.Object aspectOf(java.lang.Class) throws org.mp4parser.aj.lang.NoAspectBoundException;
     descriptor: (Ljava/lang/Class;)Ljava/lang/Object;
     flags: ACC_PUBLIC, ACC_STATIC
     Code:
-      stack=4, locals=2, args_size=1
+      stack=3, locals=2, args_size=1
          0: aload_0
          1: invokestatic  #38                 // Method getSingletonOrThreadAspectOf:(Ljava/lang/Class;)Ljava/lang/reflect/Method;
          4: aconst_null
@@ -271,17 +268,17 @@
          from    to  target type
              0    11    12   Class java/lang/reflect/InvocationTargetException
              0    11    26   Class java/lang/Exception

Desugar has logic to preserve

https://github.com/bazelbuild/bazel/blob/73b0808d52127fc04a5548a54fdfa98dd2cd6710/src/tools/android/java/com/google/devtools/build/android/desugar/Java7Compatibility.java#L71

But ASM uses one int for both the major and minor versions: https://asm.ow2.io/javadoc/org/objectweb/asm/ClassVisitor.html#visit-int-int-java.lang.String-java.lang.String-java.lang.String-java.lang.String:A-

aspectj includes a minor version, so in this case the ASM version is (3 << 16) | 45, which is greater than 51, so Desugar incorrectly upgrades the major version to 51.

The fix:

diff --git a/src/tools/android/java/com/google/devtools/build/android/desugar/Java7Compatibility.java b/src/tools/android/java/com/google/devtools/build/android/desugar/Java7Compatibility.java
index 2090d5ccc2..9b6730f540 100644
--- a/src/tools/android/java/com/google/devtools/build/android/desugar/Java7Compatibility.java
+++ b/src/tools/android/java/com/google/devtools/build/android/desugar/Java7Compatibility.java
@@ -68,7 +68,7 @@ public class Java7Compatibility extends ClassVisitor {
     this.interfaces = interfaces;
     isInterface = BitFlags.isSet(access, Opcodes.ACC_INTERFACE);
     super.visit(
-        Math.min(version, Opcodes.V1_7),
+        (version & 0xffff) > Opcodes.V1_7 ? Opcodes.V1_7 : version,
         access,
         name,
         signature,

I occur the same issue, desugar generate some error, lead to dx error.

ENV:

Build label: 0.23.1
Build target: bazel-out/darwin-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Mar 4 10:40:32 2019 (1551696032)
Build timestamp: 1551696032
Build timestamp as int: 1551696032

@act262 please post the full stacktrace here

  gradle-to-bazel git:(dev_dependeny) ✗ bazel build //app --verbose_failures
INFO: Analysed target //app:app (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
ERROR: /Users/zhangchaoxian/open_sources/gradle-to-bazel/module1/BUILD.bazel:44:1: Dexing module1/_dx/jarDeps/ouzd.jar_desugared.jar with applicable dexopts [--nolocals] failed (Exit 1): DexBuilder failed: error executing command 
  (cd /private/var/tmp/_bazel_zhangchaoxian/f1fa2ce49a8fb2a14518b3bb74319221/execroot/gradle_to_bazel && \
  exec env - \
    PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home:/Users/zhangchaoxian/Library/Android/sdk/tools:/Users/zhangchaoxian/Library/Android/sdk/tools/bin:/Users/zhangchaoxian/Library/Android/sdk/platform-tools:/Users/zhangchaoxian/Library/Android/sdk/build-tools/28.0.3:/Users/zhangchaoxian/.sdkman/candidates/gradle/current/bin:/Users/zhangchaoxian/flutter/bin \
  bazel-out/host/bin/external/bazel_tools/src/tools/android/java/com/google/devtools/build/android/dexer/DexBuilder @bazel-out/android-armeabi-v7a-fastbuild/bin/module1/_dx/jarDeps/ouzd.jar--nolocals.dex.zip-0.params)
Execution platform: @bazel_tools//platforms:host_platform
java.util.concurrent.ExecutionException: com.android.dx.cf.code.SimException: stack: overflow
        at java.base/java.util.concurrent.FutureTask.report(Unknown Source)
        at java.base/java.util.concurrent.FutureTask.get(Unknown Source)
        at com.google.devtools.build.android.dexer.DexBuilder.produceDexArchive(DexBuilder.java:253)
        at com.google.devtools.build.android.dexer.DexBuilder.processRequest(DexBuilder.java:218)
        at com.google.devtools.build.android.dexer.DexBuilder.runPersistentWorker(DexBuilder.java:173)
        at com.google.devtools.build.android.dexer.DexBuilder.main(DexBuilder.java:121)
Caused by: com.android.dx.cf.code.SimException: stack: overflow
        at com.android.dx.cf.code.ExecutionStack.throwSimException(ExecutionStack.java:341)
        at com.android.dx.cf.code.ExecutionStack.push(ExecutionStack.java:168)
        at com.android.dx.cf.code.BaseMachine.storeResults(BaseMachine.java:573)
        at com.android.dx.cf.code.ValueAwareMachine.run(ValueAwareMachine.java:208)
        at com.android.dx.cf.code.RopperMachine.run(RopperMachine.java:306)
        at com.android.dx.cf.code.Simulator$SimVisitor.visitNoArgs(Simulator.java:556)
        at com.android.dx.cf.code.BytecodeArray.parseInstruction(BytecodeArray.java:583)
        at com.android.dx.cf.code.Simulator.simulate(Simulator.java:117)
        at com.android.dx.cf.code.Ropper.processBlock(Ropper.java:789)
        at com.android.dx.cf.code.Ropper.doit(Ropper.java:744)
        at com.android.dx.cf.code.Ropper.convert(Ropper.java:349)
        at com.android.dx.dex.cf.CfTranslator.processMethods(CfTranslator.java:309)
        at com.android.dx.dex.cf.CfTranslator.translate0(CfTranslator.java:150)
        at com.android.dx.dex.cf.CfTranslator.translate(CfTranslator.java:102)
        at com.google.devtools.build.android.dexer.Dexing.addToDexFile(Dexing.java:198)
        at com.google.devtools.build.android.dexer.DexConverter.toDexFile(DexConverter.java:31)
        at com.google.devtools.build.android.dexer.DexConversionEnqueuer$ClassToDex.call(DexConversionEnqueuer.java:173)
        at com.google.devtools.build.android.dexer.DexConversionEnqueuer$ClassToDex.call(DexConversionEnqueuer.java:156)
        at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        at java.base/java.lang.Thread.run(Unknown Source)
Target //app:app failed to build
INFO: Elapsed time: 3.201s, Critical Path: 1.48s
INFO: 8 processes: 8 worker.
FAILED: Build did NOT complete successfully

I just using dx tools to handleouzd.jar_desugared.jar, origin ouzd.jar can dx succeed.

 dx --dex bazel-out/android-armeabi-v7a-fastbuild/bin/module1/_dx/jarDeps/ouzd.jar_desugared.jar
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow
Uncaught translation error: com.android.dx.cf.code.SimException: stack: overflow

UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:614)
        at com.android.dx.command.dexer.Main.runMonoDex(Main.java:310)
        at com.android.dx.command.dexer.Main.runDx(Main.java:288)
        at com.android.dx.command.dexer.Main.main(Main.java:244)
        at com.android.dx.command.Main.main(Main.java:95)
Caused by: java.lang.InterruptedException: Too many errors
        at com.android.dx.command.dexer.Main.processAllFiles(Main.java:606)
        ... 4 more

I using desugar_deploy.jar from AGP 3.2.1, It can desugar jar and dx ok.
but under bazel's desugar's jar can not dx , what's different here?

For anyone who wants a quick fix, here goes:

genrule(
    name = "good_jar",
    srcs = ["bad.jar"],
    outs = ["good.jar"],
    tools = [
        "@bazel_tools//third_party/java/proguard",
    ],
    cmd = """\
$(location @bazel_tools//third_party/java/proguard) \
    -injars $< -outjars $@ \
    -dontwarn -dontoptimize -dontobfuscate -dontshrink > /dev/null
""",
)

You can then depend on :good_jar

New version:

alias(
    name = "proguard",
    actual = select({
        "@bazel_tools//src/conditions:linux_x86_64": "@remote_java_tools_linux//:proguard",
        "@bazel_tools//src/conditions:darwin": "@remote_java_tools_darwin//:proguard",
        "@bazel_tools//src/conditions:darwin_x86_64": "@remote_java_tools_darwin//:proguard",
        "@bazel_tools//src/conditions:windows": "@remote_java_tools_windows//:proguard",
        "//conditions:default": "@remote_java_tools_linux//:proguard",
    })
)

genrule(
    name = "pushservice_jar",
    srcs = ["bad.jar"],
    outs = ["good.jar"],
    tools = [":proguard"],
    cmd = """\
$(location :proguard) \
    -injars $< -outjars $@ \
    -dontwarn -dontoptimize -dontobfuscate -dontshrink > /dev/null
""",
)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

cyberbono3 picture cyberbono3  Â·  3Comments

ttsugriy picture ttsugriy  Â·  3Comments

alexandrvb picture alexandrvb  Â·  3Comments

buchgr picture buchgr  Â·  3Comments

davidzchen picture davidzchen  Â·  3Comments