diff --git a/README.md b/README.md index b707f4040b4..cdb952faecf 100644 --- a/README.md +++ b/README.md @@ -21,11 +21,11 @@ https://firebase.google.com. 1. [Unit Testing](#unit-testing) 1. [Integration Testing](#integration-testing) 1. [Proguarding](#proguarding) - 1. [APIs used via reflection](#apis-used-via-reflection) + 1. [APIs used via reflection](#APIs-used-via-reflection) 1. [APIs intended for developer - consumption](#apis-intended-for-developer-consumption) + consumption](#APIs-intended-for-developer-consumption) 1. [APIs intended for other Firebase - SDKs](#apis-intended-for-other-firebase-sdks) + SDKs](#APIs-intended-for-other-firebase-sdks) 1. [Publishing](#publishing) 1. [Dependencies](#dependencies) 1. [Commands](#commands) @@ -87,11 +87,6 @@ If you don't have a suitable testing project already: * Download the resulting `google-services.json` file and put it in the root of your checkout. -For now, you have to disable security rule enforcement for the Realtime -Database, Cloud Firestore, and Cloud Storage in your test project (if running -the integration tests for any of those). Re-enable your security rules after -your test run. - #### Running Integration Tests Integration tests can be executed on the command line by running @@ -99,58 +94,40 @@ Integration tests can be executed on the command line by running ./gradlew ::connectedCheck ``` -## Proguarding +## Annotations -Firebase Android SDKs operate under the assumption that a vast majority of -developers do not proguard their apps. Artifacts published via the -[Publishing](#publishing) section are pre-proguarded (preguarded?) to reduce the -size impact on apps that consume them. There are three levels of retention that -APIs have, depending on how they are used. +Firebase SDKs use some special annotations for tooling purposes. -### APIs used via reflection +### @Keep APIs that need to be preserved up until the app's runtime can be annotated with [@Keep](https://developer.android.com/reference/android/support/annotation/Keep). The [@Keep](https://developer.android.com/reference/android/support/annotation/Keep) annotation is *blessed* to be honored by android's [default proguard -configuration](https://developer.android.com/studio/write/annotations#keep). -These APIs should be generally **discouraged**, because they can't be -proguarded. - -#### Usage - -- Annotate APIs with - [@Keep](https://developer.android.com/reference/android/support/annotation/Keep) +configuration](https://developer.android.com/studio/write/annotations#keep). A common use for +this annotation is because of reflection. These APIs should be generally **discouraged**, because +they can't be proguarded. -### APIs intended for developer consumption - -The -[@Keep](https://developer.android.com/reference/android/support/annotation/Keep) -mechanism described above is too restrictive for APIs that are not used via -reflection, which is the case for a vast majority of the Firebase public APIs. -We annotate these APIs with -[@PublicAPI](firebase-common/src/main/java/com/google/firebase/annotations/PublicApi.java). +### @KeepForSdk -#### Usage +APIs that are intended to be used by Firebase SDKs should be annotated with +`@KeepForSdk`. The key benefit here is that the annotation is *blessed* to throw +linter errors on Android Studio if used by the developer from a non firebase +package, thereby providing a valuable guard rail. -- Annotate the necessary APIs with firebase-common's - [@PublicApi](firebase-common/src/main/java/com/google/firebase/annotations/PublicApi.java) -### APIs intended for other Firebase SDKs +### @PublicApi -APIs that are intended to be used by Firebase SDKs may be annotated with -`@KeepForSdk`. Much like the custom annotation mechanism, the idea is to let -these APIs pass through preguarding, but not restrict the developer's app from -proguarding. The key benefit here is that the annotation is *blessed* to throw -linter errors on Android Studio if used by the developer from a non firebase -package, thereby providing a valuable guard rail. +We annotate APIs that meant to be used by developers with +[@PublicAPI](firebase-common/src/main/java/com/google/firebase/annotations/PublicApi.java). This +annotation will be used by tooling to help inform the version bump (major, minor, patch) that is +required for the next release. -#### Usage +## Proguarding -- Annotate the APIs with `@KeepForSdk` -- This method may be used in conjunction with @Keep annotations to annotate APIs - consumed by Firebase SDKs through reflection. +Firebase SDKs do not proguard themselves, but support proguarding. Firebase SDKs themselves are +proguard friendly, but the dependencies of Firebase SDKs may not be. ### Proguard config @@ -209,9 +186,6 @@ projects may be published as follows. publishProjectsToMavenLocal ``` -To generate the Maven dependency tree under `build/` instead, you can replace -`publishProjectsToMavenLocal` in the above command with `firebasePublish`. - ### Code Formatting Code in this repo is formatted with the google-java-format tool. You can enable diff --git a/firebase-common/preguard.txt b/firebase-common/preguard.txt deleted file mode 100644 index 41b21733ccc..00000000000 --- a/firebase-common/preguard.txt +++ /dev/null @@ -1,6 +0,0 @@ --repackageclasses 'com.google.firebase.obfuscated' - --dontwarn com.google.firebase.components.Component$Instantiation --dontwarn com.google.firebase.R --dontwarn com.google.firebase.R$string --dontwarn java.lang.invoke.LambdaMetafactory diff --git a/firebase-database/preguard.txt b/firebase-database/preguard.txt deleted file mode 100644 index c2d6072c8bd..00000000000 --- a/firebase-database/preguard.txt +++ /dev/null @@ -1,61 +0,0 @@ --repackageclasses 'com.google.firebase.database.obfuscated' --dontwarn okio.** --dontwarn com.google.j2objc.annotations.** --dontwarn java.lang.invoke.LambdaMetafactory --keepparameternames --renamesourcefileattribute SourceFile --keepattributes Exceptions,InnerClasses,Signature,Deprecated, - SourceFile,LineNumberTable,*Annotation*,EnclosingMethod - -# Keep the classes/members we need for client functionality. --keep @interface android.support.annotation.Keep --keep @android.support.annotation.Keep class * --keepclasseswithmembers class * { - @android.support.annotation.Keep ; -} --keepclasseswithmembers class * { - @android.support.annotation.Keep ; -} - -# Keep the enum classes and the values as well. --keepclassmembers @android.support.annotation.Keep class * extends java.lang.Enum { - ; - public static **[] values(); - public static ** valueOf(java.lang.String); -} -# Keep the classes/members we need for client functionality. --keep @interface com.google.android.gms.common.annotation.KeepForSdk --keep @com.google.android.gms.common.annotation.KeepForSdk class * --keepclasseswithmembers class * { - @com.google.android.gms.common.annotation.KeepForSdk ; -} --keepclasseswithmembers class * { - @com.google.android.gms.common.annotation.KeepForSdk ; -} - -# Keep the enum classes and the values as well. --keepclassmembers @com.google.android.gms.common.annotation.KeepForSdk class * extends java.lang.Enum { - ; - public static **[] values(); - public static ** valueOf(java.lang.String); -} - -# Keep the public API --keep @interface com.google.firebase.annotations.PublicApi --keep @com.google.firebase.annotations.PublicApi class * --keepclasseswithmembers class * { - @com.google.firebase.annotations.PublicApi ; -} --keepclasseswithmembers class * { - @com.google.firebase.annotations.PublicApi ; -} - -# Keep the enum classes and the values as well. --keepclassmembers @com.google.firebase.annotations.PublicApi class * extends java.lang.Enum { - ; - public static **[] values(); - public static ** valueOf(java.lang.String); -} -# Using names starting with "zz" --classobfuscationdictionary ../obfuscate_dict.txt --obfuscationdictionary ../obfuscate_dict.txt \ No newline at end of file diff --git a/firebase-firestore/preguard.txt b/firebase-firestore/preguard.txt deleted file mode 100644 index 76cba070b8d..00000000000 --- a/firebase-firestore/preguard.txt +++ /dev/null @@ -1,5 +0,0 @@ --repackageclasses 'com.google.firebase.firestore.obfuscated' - --dontwarn okio.** --dontwarn com.google.j2objc.annotations.** --dontwarn java.lang.invoke.LambdaMetafactory diff --git a/firebase-functions/preguard.txt b/firebase-functions/preguard.txt deleted file mode 100644 index e2082eef85d..00000000000 --- a/firebase-functions/preguard.txt +++ /dev/null @@ -1,32 +0,0 @@ --repackageclasses 'com.google.firebase.functions.obfuscated' - --dontwarn okio.** --dontwarn java.lang.invoke.LambdaMetafactory - -# TODO: switch to @PublicApi and @KeepForSdk at which point everything below can be removed. - --keep public class com.google.firebase.functions.* { - public protected *; -} - --keepclassmembernames class com.google.firebase.functions.* { - java.lang.Class class$(java.lang.String); - java.lang.Class class$(java.lang.String, boolean); -} - --keepclasseswithmembernames,includedescriptorclasses class com.google.firebase.functions.* { - native ; -} - --keepclassmembers,allowoptimization enum * { - public static **[] values(); public static ** valueOf(java.lang.String); -} - --keepclassmembers class com.google.firebase.functions.* implements java.io.Serializable { - static final long serialVersionUID; - private static final java.io.ObjectStreamField[] serialPersistentFields; - private void writeObject(java.io.ObjectOutputStream); - private void readObject(java.io.ObjectInputStream); - java.lang.Object writeReplace(); - java.lang.Object readResolve(); -} diff --git a/firebase-storage/preguard.txt b/firebase-storage/preguard.txt deleted file mode 100644 index 83e297763e9..00000000000 --- a/firebase-storage/preguard.txt +++ /dev/null @@ -1,10 +0,0 @@ --repackageclasses 'com.google.firebase.storage.obfuscated' --dontwarn okio.** --dontwarn com.google.j2objc.annotations.** --dontwarn java.lang.invoke.LambdaMetafactory - --keepparameternames --renamesourcefileattribute SourceFile --keepattributes Exceptions,InnerClasses,Signature,Deprecated, - SourceFile,LineNumberTable,*Annotation*,EnclosingMethod - diff --git a/root-project.gradle b/root-project.gradle index b7b528c49bf..a648e88fa17 100644 --- a/root-project.gradle +++ b/root-project.gradle @@ -126,7 +126,7 @@ configure(subprojects) { // Apply the retrolambda plugin sub.apply plugin: 'me.tatarka.retrolambda' - boolean skipPreguard = sub.getProperties().getOrDefault('firebaseSkipPreguard', 'false').toBoolean() + boolean skipPreguard = sub.getProperties().getOrDefault('firebaseSkipPreguard', 'true').toBoolean() def defaultPreguard = rootProject.getProperties().getOrDefault('firebaseDefaultPreguardFile', 'default-preguard.txt') if(!skipPreguard) {