wind0ws / rxbus2

Listen and handle event ,based on RxJava.
http://www.jianshu.com/p/7f4a709d2be5
31 stars 8 forks source link

Packaging confusing problems #1

Closed jeremyzhangpeng closed 7 years ago

jeremyzhangpeng commented 7 years ago

Cannot be used after the confusion

wind0ws commented 7 years ago

What your confusion?
There is a demo on this repo. you can read it first.

jeremyzhangpeng commented 7 years ago

If minifyEnabled true,then is failed。

wind0ws commented 7 years ago

Maybe you need add some proguard rules in your "proguard-rules.pro" file,such as your entity bean . This is not problem of this library.

jeremyzhangpeng commented 7 years ago

I have added some proguard rules ,but still failed,i don't know what is the problem?Can you guide it?

wind0ws commented 7 years ago
#beans and entity
-keep class **.*Bean {*;}
-keep class **.*Entity { *; }

here is a example in my project:


    private void listenLoginOutEvent() {
        RxBus.getInstance()
                .ofType(UserLoginOutEvent.class)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<UserLoginOutEvent>() {
                    @Override
                    public void onSubscribe(@io.reactivex.annotations.NonNull Disposable disposable) {
                        mCompositeDisposable.add(disposable);
                    }

                    @Override
                    public void onNext(@io.reactivex.annotations.NonNull UserLoginOutEvent loginOutEvent) {
                        refresh();
                    }

                    @Override
                    public void onError(@io.reactivex.annotations.NonNull Throwable e) {
                         Log.d(TAG,"error on listen user loginout event: "+e);
                    }

                    @Override
                    public void onComplete() {
                    }
                });
    }

It works fine while i set minifyEnabled = true in gradle.

Did you add rules about Annotation in your "proguard-rules.pro"?

jeremyzhangpeng commented 7 years ago

Rxjava2 and RxAndroid2 ,RxRelay2 ,Don't keep?

wind0ws commented 7 years ago

yep. no need. you just need keep annotation and your bean or entity. It works fine in my environment. If not, double check it, and try keep them one by one and find the problem.

jeremyzhangpeng commented 7 years ago

Your demo "rxbus2-master" , minifyEnabled true alse failed.

wind0ws commented 7 years ago

I build a release version of this demo(with minifyEnabled ), it also works fine. As I mention before, you need keep Activity ,Fragment,Service , Broadcast,Annotations, bean in your "proguard-rules.pro"

There is template of my "proguard-rules.pro",try this, it should work:

-dontwarn java.lang.invoke.*
-dontwarn **$$Lambda$*

-keepclassmembers class * {
   public <init> (org.json.JSONObject);
}
-keepclassmembers enum * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

#beans
-keep class **.*Bean {*;}

-optimizationpasses 5

-dontskipnonpubliclibraryclassmembers

-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-useuniqueclassmembernames

-allowaccessmodification

-renamesourcefileattribute SourceFile

-keepattributes SourceFile,LineNumberTable

-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class * extends android.support.v4.app.Fragment
-keep public class * extends android.app.Fragment
-dontwarn android.support.**
# support-v7-appcompat
-keep public class * extends android.support.v7.app.AppCompatActivity
-keep public class * extends android.support.v7.widget.** { *; }
-keep public class * extends android.support.v7.internal.widget.** { *; }
-keep public class * extends android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}
# support-design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }
# bottom navigation
-keep public class android.support.design.widget.BottomNavigationView { *; }
-keep public class android.support.design.internal.BottomNavigationMenuView { *; }
-keep public class android.support.design.internal.BottomNavigationPresenter { *; }
-keep public class android.support.design.internal.BottomNavigationItemView { *; }

-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

-keepclasseswithmembernames class * {
    native <methods>;
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

-keepclassmembers class * implements java.io.Serializable {
    static final long serialVersionUID;
    private static final java.io.ObjectStreamField[] serialPersistentFields;
    !static !transient <fields>;
    !private <fields>;
    !private <methods>;
    private void writeObject(java.io.ObjectOutputStream);
    private void readObject(java.io.ObjectInputStream);
    java.lang.Object writeReplace();
    java.lang.Object readResolve();
}

-keepclassmembers enum * {
  public static **[] values();
  public static ** valueOf(java.lang.String);
}

-keep class **.R$* { *;}

# For using annotation
-keepattributes *Annotation*
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepattributes *Annotation*
-keepclassmembers class ** {
    @com.threshold.rxbus2.annotation.RxSubscribe <methods>;
}
-keep enum com.threshold.rxbus2.util.EventThread { *; }
jeremyzhangpeng commented 7 years ago

-keepclassmembers class ** { @com.threshold.rxbus2.annotation.RxSubscribe ; } The key is that。Has been resolved。Thanks