编辑解决方案:如果情况相同,请不要使用以下组合。
RxJava,Jack& Jill Java 8 Support and Proguard
我禁用了Jack& Jill来自我的gradle文件并为lambda支持添加了复古lambda插件。问题解决了!
proguard-rules.pro 应包含以下RxJava规则:
-dontwarn sun.misc.**
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
问题
我正在使用Observable's fromCallable
函数来生成测试数据。代码运行良好没有proguard ,但当我激活proguard 时,Subscription's onNext
函数不会调用。
可观察的电话
public void loadNearbyUserEvents() {
Log.w(TAG, "loadNearbyUserEvents");
try {
getMvpView().showProgress();
Subscription subscription = dataManager.getEventImplementer().getNearbyUsersEvents()
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(getSubscriber());
subscriptions.add(subscription);
Log.w(TAG, "aaaa");
} catch (Exception e) {
e.printStackTrace();
getMvpView().showError(e.getMessage());
getMvpView().hideProgress();
}
}
private Subscriber<List<Event>> getSubscriber() {
return new Subscriber<List<Event>>() {
@Override
public void onCompleted() {
Log.w(TAG, "onCompleted");
}
@Override
public void onError(Throwable e) {
Log.w(TAG, "onError");
e.printStackTrace();
}
@Override
public void onNext(List<Event> events) {
Log.w(TAG, "size of list : " + events.size());
getMvpView().hideProgress();
if (events.size() == 0) {
getMvpView().showEmpty();
return;
}
getMvpView().showEvents(events);
}
};
}
EventImplementer的getNearbyUserEvents
@Override
public Observable<List<Event>> getNearbyUsersEvents() {
return Observable.fromCallable(() -> EventProducer.produce(20));
}
以上代码在没有proguard的情况下运行良好。
proguard-rules.pro
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in D:\developer\Android\Application\windows\android-sdk-windows/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# Add any project specific keep options here:
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# okhttp rulez
-dontwarn okio.**
# okhttp rulezzz
# retrofit rulez
# Platform calls Class.forName on types which do not exist on Android to determine platform.
-dontnote retrofit2.Platform
# Platform used when running on RoboVM on iOS. Will not be used at runtime.
-dontnote retrofit2.Platform$IOS$MainThreadExecutor
# Platform used when running on Java 8 VMs. Will not be used at runtime.
-dontwarn retrofit2.Platform$Java8
# Retain generic type information for use by reflection by converters and adapters.
-keepattributes Signature
# Retain declared checked exceptions for use by a Proxy instance.
-keepattributes Exceptions
# retrofit rulezzz
# searchView rulez
-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }
-keep class android.support.v7.app.** { *; }
-keep interface android.support.v7.app.** { *; }
-keep class android.support.v7.widget.SearchView { *; }
-keep public class * extends android.support.v7.widget.SearchView {
public <init>(android.content.Context);
public <init>(android.content.Context, android.util.AttributeSet);
}
# searchview rulezzz
# parcel rulez
-keep interface org.parceler.Parcel
-keep @org.parceler.Parcel class * { *; }
-keep class **$$Parcelable { *; }
# parcel rulezzz
# picasso rulez
-dontwarn com.squareup.okhttp.**
# picasso rulezzz
# rx rulez
# rxjava
-keep class rx.schedulers.Schedulers {
public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
public <methods>;
}
-keep class rx.schedulers.TestScheduler {
public <methods>;
}
-keep class rx.schedulers.Schedulers {
public static ** test();
}
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
long producerNode;
long consumerNode;
}
# rx rulezzz
我的代码出了什么问题?为什么只有onCompleted函数可以工作,但onNext和onError函数不会调用?
注意:当我使用Observable.just(() -> EventProducer.produce(20))
功能时,它正常工作。
答案 0 :(得分:0)
# rxjava
-keep class rx.schedulers.Schedulers {
public static <methods>;
}
-keep class rx.schedulers.ImmediateScheduler {
public <methods>;
}
-keep class rx.schedulers.TestScheduler {
public <methods>;
}
-keep class rx.schedulers.Schedulers {
public static ** test();
}
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
long producerIndex;
long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
rx.internal.util.atomic.LinkedQueueNode producerNode;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueConsumerNodeRef {
rx.internal.util.atomic.LinkedQueueNode consumerNode;
}
也许会有所帮助。
欢呼声