From b0f269b30ca48520b35348dd3b57e0e3dafaae2b Mon Sep 17 00:00:00 2001 From: janisharali Date: Tue, 3 Apr 2018 16:15:05 +0530 Subject: [PATCH] Add Consumer proguard rules --- app/proguard-rules.pro | 4 ++++ .../java/com/mindorks/demo/ActivityTinder.java | 1 - .../placeholderview/annotations/Keep.java | 18 ++++++++++++++++++ .../placeholderview/annotations/Layout.java | 2 +- .../LoadMoreViewBinderClassStructure.java | 4 +++- ...ipeDirectionalViewBinderClassStructure.java | 4 +++- .../SwipeViewBinderClassStructure.java | 4 +++- .../structures/ViewBinderClassStructure.java | 4 +++- placeholderview/build.gradle | 1 + placeholderview/proguard-rules.pro | 5 +++++ 10 files changed, 41 insertions(+), 6 deletions(-) create mode 100644 placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Keep.java diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 65f205b..935a386 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -15,3 +15,7 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} +-keepattributes *Annotation* +-keepclassmembers class ** { +@com.mindorks.butterknifelite.annotations.** ; +} diff --git a/app/src/main/java/com/mindorks/demo/ActivityTinder.java b/app/src/main/java/com/mindorks/demo/ActivityTinder.java index 3fd547d..4fdc9c6 100644 --- a/app/src/main/java/com/mindorks/demo/ActivityTinder.java +++ b/app/src/main/java/com/mindorks/demo/ActivityTinder.java @@ -4,7 +4,6 @@ import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; import android.util.Log; -import android.view.Gravity; import com.mindorks.butterknifelite.ButterKnifeLite; import com.mindorks.butterknifelite.annotations.BindView; diff --git a/placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Keep.java b/placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Keep.java new file mode 100644 index 0000000..7029a37 --- /dev/null +++ b/placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Keep.java @@ -0,0 +1,18 @@ +package com.mindorks.placeholderview.annotations; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Created by janisharali on 18/08/16. + */ + +/** + * Will keep any class after proguard minify + */ +@Retention(RetentionPolicy.CLASS) +@Target(ElementType.TYPE) +public @interface Keep { +} diff --git a/placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Layout.java b/placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Layout.java index 1b3785a..d8cacc3 100644 --- a/placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Layout.java +++ b/placeholderview-annotations/src/main/java/com/mindorks/placeholderview/annotations/Layout.java @@ -10,7 +10,7 @@ /** * Created by janisharali on 18/08/16. */ -@Retention(RetentionPolicy.SOURCE) +@Retention(RetentionPolicy.CLASS) @Target(ElementType.TYPE) public @interface Layout { @LayoutRes int value(); diff --git a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/LoadMoreViewBinderClassStructure.java b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/LoadMoreViewBinderClassStructure.java index 6bf0238..8a9ab2f 100644 --- a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/LoadMoreViewBinderClassStructure.java +++ b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/LoadMoreViewBinderClassStructure.java @@ -1,5 +1,6 @@ package com.mindorks.placeholderview.compiler.structures; +import com.mindorks.placeholderview.annotations.Keep; import com.mindorks.placeholderview.annotations.infinite.LoadMore; import com.mindorks.placeholderview.annotations.internal.BindingSuffix; import com.mindorks.placeholderview.compiler.RClassBuilder; @@ -55,7 +56,8 @@ protected TypeSpec.Builder createClassBuilder() { .superclass(parentClassName) .addSuperinterface(ParameterizedTypeName.get(loadMoreCallbackClassName, TypeVariableName.get(getClassDetail().getTypeElement().asType()))) - .addModifiers(Modifier.PUBLIC); + .addModifiers(Modifier.PUBLIC) + .addAnnotation(Keep.class); } public LoadMoreViewBinderClassStructure addConstructor() { diff --git a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeDirectionalViewBinderClassStructure.java b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeDirectionalViewBinderClassStructure.java index 598b0e5..4d88b0f 100644 --- a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeDirectionalViewBinderClassStructure.java +++ b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeDirectionalViewBinderClassStructure.java @@ -1,5 +1,6 @@ package com.mindorks.placeholderview.compiler.structures; +import com.mindorks.placeholderview.annotations.Keep; import com.mindorks.placeholderview.annotations.internal.BindingSuffix; import com.mindorks.placeholderview.annotations.swipe.SwipeInDirectional; import com.mindorks.placeholderview.annotations.swipe.SwipeOutDirectional; @@ -52,7 +53,8 @@ protected TypeSpec.Builder createClassBuilder() { getClassDetail().getFrameViewClassName(), getClassDetail().getSwipeDirectionalOptionClassName(), getClassDetail().getSwipeDecorClassName())) - .addModifiers(Modifier.PUBLIC); + .addModifiers(Modifier.PUBLIC) + .addAnnotation(Keep.class); } @Override diff --git a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeViewBinderClassStructure.java b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeViewBinderClassStructure.java index 6f7601f..ed7fc3e 100644 --- a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeViewBinderClassStructure.java +++ b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/SwipeViewBinderClassStructure.java @@ -1,5 +1,6 @@ package com.mindorks.placeholderview.compiler.structures; +import com.mindorks.placeholderview.annotations.Keep; import com.mindorks.placeholderview.annotations.internal.BindingSuffix; import com.mindorks.placeholderview.annotations.swipe.SwipeCancelState; import com.mindorks.placeholderview.annotations.swipe.SwipeHead; @@ -56,7 +57,8 @@ protected TypeSpec.Builder createClassBuilder() { getClassDetail().getFrameViewClassName(), getClassDetail().getSwipeOptionClassName(), getClassDetail().getSwipeDecorClassName())) - .addModifiers(Modifier.PUBLIC); + .addModifiers(Modifier.PUBLIC) + .addAnnotation(Keep.class); } @Override diff --git a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/ViewBinderClassStructure.java b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/ViewBinderClassStructure.java index 757f063..3571a63 100644 --- a/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/ViewBinderClassStructure.java +++ b/placeholderview-compiler/src/main/java/com/mindorks/placeholderview/compiler/structures/ViewBinderClassStructure.java @@ -1,6 +1,7 @@ package com.mindorks.placeholderview.compiler.structures; import com.mindorks.placeholderview.annotations.Click; +import com.mindorks.placeholderview.annotations.Keep; import com.mindorks.placeholderview.annotations.Layout; import com.mindorks.placeholderview.annotations.LongClick; import com.mindorks.placeholderview.annotations.NonReusable; @@ -57,7 +58,8 @@ protected TypeSpec.Builder createClassBuilder() { getClassDetail().getSuperClassName(), TypeVariableName.get(getClassDetail().getTypeElement().asType()), TypeVariableName.get(getClassDetail().getViewTypeParameterClassName().simpleName()))) - .addModifiers(Modifier.PUBLIC); + .addModifiers(Modifier.PUBLIC) + .addAnnotation(Keep.class); } public ViewBinderClassStructure addConstructor() { diff --git a/placeholderview/build.gradle b/placeholderview/build.gradle index 02f01a5..d8ec2f2 100644 --- a/placeholderview/build.gradle +++ b/placeholderview/build.gradle @@ -9,6 +9,7 @@ android { targetSdkVersion rootProject.ext.libTargetSdkVersion versionCode rootProject.ext.libPublishVersionCode versionName rootProject.ext.libPublishVersionName + consumerProguardFiles 'proguard-rules.pro' } buildTypes { release { diff --git a/placeholderview/proguard-rules.pro b/placeholderview/proguard-rules.pro index 65f205b..47b42bb 100644 --- a/placeholderview/proguard-rules.pro +++ b/placeholderview/proguard-rules.pro @@ -15,3 +15,8 @@ #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} +-keep @com.mindorks.placeholderview.annotations.Layout public class * +-keep @com.mindorks.placeholderview.annotations.Keep public class * +-keepclassmembers @com.mindorks.placeholderview.annotations.Layout class ** { *;} +-keepclassmembers @com.mindorks.placeholderview.annotations.Keep class ** { *;} +