# Consumer ProGuard/R8 rules for coherencelib.
#
# The shared C library reaches back into Java via JNI by string name
# (GetMethodID(host, "kvGet", "(Ljava/lang/String;)Ljava/lang/String;") etc). If R8 in
# the host app renames or strips any of these members, the JNI lookup
# returns NULL and init() bails — the library degrades silently to a no-op
# at runtime. Keep just enough of the public surface and the reflection
# trampoline to keep those lookups resolvable.
#
# These rules are scoped tightly: the Coherence class is package-private,
# but consumer ProGuard runs across the merged classpath after the AAR is
# inlined, so it can still rename or remove members unless we tell it not
# to.

# JNI lookups in unity_coherence_jni.cpp resolve these by exact name +
# signature. Renaming any one breaks Coherence.init at process start.
-keep class com.unity3d.coherence.Coherence {
    java.lang.String kvGet(java.lang.String);
    boolean kvSet(java.lang.String, java.lang.String);
    java.lang.String generateUuid();
    java.lang.String reflectString(java.lang.String);
    java.lang.Long reflectInt(java.lang.String);
    java.lang.Boolean reflectBool(java.lang.String);
}

# Log trampoline (CoherenceBridge.setLogHandler -> JNI GetMethodID).
-keep class com.unity3d.coherence.LogHandler {
    void onLog(int, java.lang.String);
}

# vmInvokeMain constructs VmInvokeResult from native via FindClass +
# GetMethodID("<init>") + GetFieldID for the three fields. Without these
# keep rules, R8 will rename "status"/"bytes"/"errorMessage" and the JNI
# field writes will throw NoSuchFieldError.
-keep class com.unity3d.coherence.VmInvokeResult {
    <init>();
    int status;
    byte[] bytes;
    java.lang.String errorMessage;
}

# CoherenceBridge holds the JNIEXPORT entry points. JNI-exported native
# methods are matched by JNIEXPORT-decorated symbols compiled into the
# .so; the Java class itself need not be kept (the symbol lookup is by C
# name), but keeping it avoids surprising "method not found" errors when
# downstream code reaches in for the static native helpers.
-keep class com.unity3d.coherence.CoherenceBridge { *; }

# Native-method names are matched by JNI symbol mangling against the Java
# class + method. The mangling cannot survive class/method renames.
-keepclasseswithmembernames class com.unity3d.coherence.** {
    native <methods>;
}
