chasm icon indicating copy to clipboard operation
chasm copied to clipboard

Issues when minifying chasm in Android using r8

Open basic-bgnr opened this issue 10 months ago • 7 comments

@CharlieTap Thanks to your project, I've been able to run a demo android app that utilizes running a wasm file without any issues.
Today I decided to build a release version of the app and to my dismay the r8 compiler failed to successfully compile the app, crashing with null pointer exception.

chasm version: 0.9.53

AGPBI: {"kind":"error","text":"java.lang.NullPointerException","sources":[{"file":"/home/user/.gradle/caches/modules-2/files-2.1/io.github.charlietap.chasm/decoder-jvm/0.9.53/a73838c28c6ee7c126768d3c5cd714b1bca3ef0e/decoder-jvm-0.9.53.jar"}],"tool":"R8"}

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete, position: Lio/github/charlietap/chasm/decoder/context/scope/SectionScopeKt;SectionScope(Lio/github/charlietap/chasm/decoder/context/DecoderContext;Lkotlin/Pair;)Ljava/lang/Object;, origin: /home/user/.gradle/caches/modules-2/files-2.1/io.github.charlietap.chasm/decoder-jvm/0.9.53/a73838c28c6ee7c126768d3c5cd714b1bca3ef0e/decoder-jvm-0.9.53.jar:io/github/charlietap/chasm/decoder/context/scope/SectionScopeKt.class

I tried keeping the entire chasm dependency without minification using the following proguard rule but couldn't manage to avoid the null pointer exception.

-keep class io.github.charlietap.chasm.** { *; }
-keep interface io.github.charlietap.chasm.** { *; }
-keep enum io.github.charlietap.chasm.** { *; }

Could you point me in the right direction?

basic-bgnr avatar Mar 02 '25 18:03 basic-bgnr

Hey thanks, I'm able to reproduce this by running R8 on the build. 0.9.6 is coming sometime in the next 2 weeks and I will aim to get a fix out with that

CharlieTap avatar Mar 02 '25 18:03 CharlieTap

Thank you for responding so quickly. Will be waiting for it. 👍

basic-bgnr avatar Mar 03 '25 02:03 basic-bgnr

Just an update on this, I've reached out to the R8 team and they're giving some steer. It won't make 9.6.0 but I will do a minor release as soon as its ready

CharlieTap avatar Mar 09 '25 14:03 CharlieTap

@CharlieTap thank you. Did you find out what is causing this, is it an issue with chasm or the R8? Would you link the issue tracker of R8 regarding this, I googled it but couldn't find.

basic-bgnr avatar Mar 10 '25 02:03 basic-bgnr

Hey, the original ticket was here: https://issuetracker.google.com/issues/400746842

Its now fixed but that version of R8 will not be baked into AGP just yet, to use it you can override R8 with this:

settings.gradle.kts

pluginManagement {
    buildscript {
        repositories {
            mavenCentral()
            maven {
                url = uri("https://storage.googleapis.com/r8-releases/raw")
            }
        }
        dependencies {
            classpath("com.android.tools:r8:8.8.39")
        }
    }
}

CharlieTap avatar Mar 12 '25 20:03 CharlieTap

Thanks again. It's working fine now. Might as well close this issue and keep a snippet of how to enable R8 in the README.md until the AGP is updated.

basic-bgnr avatar Mar 13 '25 11:03 basic-bgnr

I'm going to leave this open until we get a version of AGP with a version of R8 > 8.8.39 and then I'll add some docs pointing to that

CharlieTap avatar Mar 21 '25 10:03 CharlieTap

This was fixed in versions >= AGP 8.9.2

CharlieTap avatar Oct 25 '25 20:10 CharlieTap