Skip to content

Commit

Permalink
Replace "facebook.proguard.annotations" with "facebook.yoga.annotatio…
Browse files Browse the repository at this point in the history
…ns" (#35841)

Summary:
Pull Request resolved: #35841

X-link: facebook/litho#928

X-link: facebook/yoga#1216

The Yoga JNI bindings use Reflection, so we need to let ProGuard know not to strip certain annotated fields.

This is done internally using a single copy of `com.facebook.proguard.annotations` from fbandroid (sometimes), which is then repackaged externally, and published as its own whole Yoga specific package. We never actually inform the stock Gradle project of the rules for the annotations though, so apps must add these manually.

This simplifies the setup, where Yoga has its own self-contained annotations/rules. The rules are exposed for Gradle/Buck dependencies, but RN and Litho both consume Yoga via dirsync + custom Gradle logic, so we need to duplicate the proguard rules to them instead of them being propagated automatically.

Changelog: [Internal]

Reviewed By: rshest

Differential Revision: D42406641

fbshipit-source-id: c2b12fd498f93f144e5651917ca878d2a5050e08
  • Loading branch information
NickGerleman authored and facebook-github-bot committed Jan 16, 2023
1 parent cb80f16 commit e6d1ab9
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 5 deletions.
7 changes: 7 additions & 0 deletions ReactAndroid/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,10 @@
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**

# yoga
-keep,allowobfuscation @interface com.facebook.yoga.annotations.DoNotStrip
-keep @com.facebook.yoga.annotations.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.yoga.annotations.DoNotStrip *;
}
2 changes: 1 addition & 1 deletion ReactAndroid/src/main/java/com/facebook/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_libra

rn_android_library(
name = "yoga",
srcs = glob(["yoga/*.java"]),
srcs = glob(["yoga/**/*.java"]),
autoglob = False,
language = "JAVA",
visibility = ["PUBLIC"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

package com.facebook.yoga;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.yoga.annotations.DoNotStrip;

@DoNotStrip
public enum YogaLogLevel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package com.facebook.yoga;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.yoga.annotations.DoNotStrip;

/**
* Interface for receiving logs from native layer. Use by setting YogaNode.setLogger(myLogger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package com.facebook.yoga;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.yoga.annotations.DoNotStrip;
import com.facebook.soloader.SoLoader;

@DoNotStrip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

package com.facebook.yoga;

import com.facebook.proguard.annotations.DoNotStrip;
import com.facebook.yoga.annotations.DoNotStrip;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

package com.facebook.yoga.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.CLASS;

@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR })
@Retention(CLASS)
public @interface DoNotStrip { }

0 comments on commit e6d1ab9

Please sign in to comment.