From a668d5266a7024a7b15f982eea36e2bcd997712d Mon Sep 17 00:00:00 2001 From: maxli Date: Fri, 8 Nov 2024 11:29:48 +0800 Subject: [PATCH] fix(android): avoiding code optimization issues for R8 compile --- modules/android/serialization/build.gradle | 1 + .../hippy/serialization/nio/writer/SafeHeapWriter.java | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/modules/android/serialization/build.gradle b/modules/android/serialization/build.gradle index b82c85d85ff..b1dc05b618c 100644 --- a/modules/android/serialization/build.gradle +++ b/modules/android/serialization/build.gradle @@ -32,4 +32,5 @@ android { dependencies { implementation deps.annotation + implementation project(':hippy-support') } \ No newline at end of file diff --git a/modules/android/serialization/src/main/java/com/tencent/mtt/hippy/serialization/nio/writer/SafeHeapWriter.java b/modules/android/serialization/src/main/java/com/tencent/mtt/hippy/serialization/nio/writer/SafeHeapWriter.java index ebd4f5fb078..b30b18a7237 100644 --- a/modules/android/serialization/src/main/java/com/tencent/mtt/hippy/serialization/nio/writer/SafeHeapWriter.java +++ b/modules/android/serialization/src/main/java/com/tencent/mtt/hippy/serialization/nio/writer/SafeHeapWriter.java @@ -15,6 +15,7 @@ */ package com.tencent.mtt.hippy.serialization.nio.writer; +import com.tencent.mtt.hippy.utils.LogUtils; import java.nio.ByteBuffer; @SuppressWarnings({"unused"}) @@ -73,22 +74,29 @@ public void putDouble(double d) { } @SuppressWarnings("SpellCheckingInspection") + // After upgrading to AGP version 8 or above, R8 compilation will be started. Due to the optimization + // of R8 compilation code, it will affect the logic of the code here, causing encoding and decoding + // failures and white screen problems. Therefore, it is necessary to add some logs in the implementation + // of this function to avoid R8 compilation optimization. @Override public int putVarint(long l) { if (count + 10 > value.length) { enlargeBuffer(count + 10); } - + LogUtils.d("CallFunction", "putVarint l " + l + ", count " + count); long rest = l; int bytes = 0; byte b; do { b = (byte) rest; + LogUtils.d("CallFunction", "putVarint origin b " + b + ", count " + count); b |= 0x80; + LogUtils.d("CallFunction", "putVarint b " + Byte.toUnsignedInt(b) + ", count " + count); value[count++] = b; rest >>>= 7; bytes++; } while (rest != 0); + LogUtils.d("CallFunction", "putVarint bb " + Byte.toUnsignedInt((byte) (b & 0x7f)) + ", bytes " + bytes + ", count " + count); value[count - 1] = (byte) (b & 0x7f); return bytes; }