简体   繁体   中英

Proguard Warning: can't find referenced class on Observable

When I build with Proguard, I got the 'can't find referenced class on Observable' warning on Observable.

But I'm using the Observable in many places, but the warning point to only below code.

viewModel.data.observe(this, Observer<Boolean> {

    // Warning: can't find referenced class
    Single.fromCallable {
        updateSomething()
    }
    .delay(2, TimeUnit.SECONDS)
    .subscribe({}, {
        it.printStackTrace()
    })
})

Maybe it related to the ViewModel observe? If I comment out 'Single.fromCallable...' block, I can build without any warning.

How can I fix this problem?

[Edit] my current proguard-rules.pro

############################################################
## Retrofit2
############################################################
-dontwarn retrofit2.**
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
-dontwarn javax.annotation.**
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}

############################################################
## okhttp3
############################################################
-dontwarn okhttp3.**
-dontwarn okio.**

############################################################
## For picasso
############################################################
-dontwarn com.squareup.okhttp.**

############################################################
## For com.caverock:androidsvg
############################################################
-dontwarn com.caverock.androidsvg.**

############################################################
## For Gson
############################################################
-keep class com.google.** {*;}
-keep interface com.google.** {*;}

# For using GSON @Expose annotation
-keepattributes *Annotation*

# Gson specific classes
-dontwarn sun.misc.**
#-keep class com.google.gson.stream.** { *; }

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

# Prevent proguard from stripping interface information from TypeAdapterFactory,
# JsonSerializer, JsonDeserializer instances (so they can be used in @JsonAdapter)
-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

############################################################
## For NonSwipeableViewPager
############################################################
-keep class android.support.v4.view.ViewPager { *; }

############################################################
## For RxJava
############################################################
-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;
}

-dontnote rx.internal.util.PlatformDependent

The error messages,

Warning: com.test/view.list.PhotoListFragment$observeUpdates$2$1$1$3: can't find referenced class com.test/view.list.PhotoListFragment$observeUpdates$2$1 Warning: com.test/view.list.PhotoListFragment$observeUpdates$2$1$1$3: can't find referenced class com.test/view.list.PhotoListFragment$observeUpdates$2$1 Warning: com.test/view.list.PhotoListFragment$observeUpdates$2$1$1$4: can't find referenced class com.test/view.list.PhotoListFragment$observeUpdates$2$1 Warning: com.test/view.list.PhotoListFragment$observeUpdates$2$1$1$4: can't find referenced class com.test/view.list.PhotoListFragment$observeUpdates$2$1

observeUpdates() method contains the above codes.

You can try keeping this line in your Proguard :

-keepnames class rx.Single



 #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();
}

-keep class rx.internal.util.unsafe.** {
    *;
}
-keepclassmembers class rx.internal.util.unsafe.*ArrayQueue*Field* {
    long producerIndex;
    long consumerIndex;
}
-keepclassmembers class rx.internal.util.unsafe.BaseLinkedQueueProducerNodeRef {
    long producerNode;
    long consumerNode;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM