diff --git a/java/com/facebook/jni/HybridData.java b/java/com/facebook/jni/HybridData.java index e7fff38..12fba77 100644 --- a/java/com/facebook/jni/HybridData.java +++ b/java/com/facebook/jni/HybridData.java @@ -16,7 +16,7 @@ package com.facebook.jni; -import com.facebook.jni.annotations.DoNotStrip; +import com.facebook.jni.annotations.DoNotStripAny; import com.facebook.soloader.nativeloader.NativeLoader; /** @@ -27,14 +27,14 @@ *

{@link #resetNative} deletes the corresponding native object synchronously on whatever thread * the method is called on. Otherwise, deletion will occur on the {@link DestructorThread} thread. */ -@DoNotStrip +@DoNotStripAny public class HybridData { static { NativeLoader.loadLibrary("fbjni"); } - @DoNotStrip private Destructor mDestructor = new Destructor(this); + private final Destructor mDestructor = new Destructor(this); /** * To explicitly delete the instance, call resetNative(). If the C++ instance is referenced after @@ -64,11 +64,11 @@ public boolean isValid() { return mDestructor.mNativePointer != 0; } - @DoNotStrip + @DoNotStripAny public static class Destructor extends DestructorThread.Destructor { // Private C++ instance - @DoNotStrip private volatile long mNativePointer; + private volatile long mNativePointer; Destructor(Object referent) { super(referent); diff --git a/java/com/facebook/jni/annotations/DoNotStripAny.java b/java/com/facebook/jni/annotations/DoNotStripAny.java new file mode 100644 index 0000000..f3d5679 --- /dev/null +++ b/java/com/facebook/jni/annotations/DoNotStripAny.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.facebook.jni.annotations; + +import static java.lang.annotation.RetentionPolicy.CLASS; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Add this annotation to a class to instruct Proguard to not strip it or any of its fields or + * methods out. + * + *

This is useful for methods called via reflection that could appear as unused to Proguard. + */ +@Target({ElementType.TYPE}) +@Retention(CLASS) +public @interface DoNotStripAny {}