Kotlin、proguard、Android 架构组件
Kotlin, proguard, Android Architecture Components
我有一个带有实时数据变量的视图模型。
我的 activity 观察它以更新 UI。
在调试中,一切正常。当我启用混淆器时,它不再观察到实时数据的变化。
我已检查实时数据是否已正确更新。但是,永远不会调用观察者回调。
关于如何配置 Proguard 的任何提示以及可能出现的问题?
我尝试保留 类 我的包裹但没有成功:
-keep class com.example.myapp.** { *; }
这是视图模型:
class SplashViewModelImpl : JapetViewModel(), SplashViewModel {
private val isTimeUp = MutableLiveData<Boolean>()
init {
isTimeUp.value = false
Observable.timer(2000L, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { isTimeUp.postValue(true) }
}
override fun isTimeUp(): LiveData<Boolean> = isTimeUp
}
和 activity:
class SplashActivity : MyBaseActivity() {
lateinit var viewModel: SplashViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
viewModel = kodein.with(this).instance()
// Working in debug
// viewModel.isTimeUp().observe(this, Observer(this::transitionIfTimeUp))
// Working in debug too, tried this way of writing it too
viewModel.isTimeUp().observe(this, Observer<Boolean> { t -> transitionIfTimeUp(t) })
// Also tried doing it with an object : Observer... without success either
}
private fun transitionIfTimeUp(isTimeUp: Boolean?) {
if (isTimeUp == null || !isTimeUp) return
startActivity<LoginActivity>()
finish()
}
}
已编辑:依赖关系
testCompile "android.arch.persistence.room:testing:1.0.0-alpha3"
androidTestCompile "android.arch.persistence.room:testing:1.0.0-alpha3"
compile "android.arch.lifecycle:extensions:1.0.0-alpha3"
compile "android.arch.lifecycle:reactivestreams:1.0.0-alpha3"
kapt "android.arch.lifecycle:compiler:1.0.0-alpha3"
compile "android.arch.persistence.room:runtime:1.0.0-alpha3"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha3"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha3"
我猜你是在寻找运算符 Observable.interval
而不是 Observable.timer
您正在使用的那个在指定时间后仅发出一次。但是 Observable.interval
每隔指定的时间间隔连续发射。
您必须升级到 alpha4
才能获得适当的 ProGuard 配置。
alpha3
有一个 issue in that it did not include the appropriate ProGuard configuration. As per the alpha4 release notes,已修复。
我有一个带有实时数据变量的视图模型。
我的 activity 观察它以更新 UI。
在调试中,一切正常。当我启用混淆器时,它不再观察到实时数据的变化。
我已检查实时数据是否已正确更新。但是,永远不会调用观察者回调。
关于如何配置 Proguard 的任何提示以及可能出现的问题?
我尝试保留 类 我的包裹但没有成功:
-keep class com.example.myapp.** { *; }
这是视图模型:
class SplashViewModelImpl : JapetViewModel(), SplashViewModel {
private val isTimeUp = MutableLiveData<Boolean>()
init {
isTimeUp.value = false
Observable.timer(2000L, TimeUnit.MILLISECONDS)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe { isTimeUp.postValue(true) }
}
override fun isTimeUp(): LiveData<Boolean> = isTimeUp
}
和 activity:
class SplashActivity : MyBaseActivity() {
lateinit var viewModel: SplashViewModel
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
viewModel = kodein.with(this).instance()
// Working in debug
// viewModel.isTimeUp().observe(this, Observer(this::transitionIfTimeUp))
// Working in debug too, tried this way of writing it too
viewModel.isTimeUp().observe(this, Observer<Boolean> { t -> transitionIfTimeUp(t) })
// Also tried doing it with an object : Observer... without success either
}
private fun transitionIfTimeUp(isTimeUp: Boolean?) {
if (isTimeUp == null || !isTimeUp) return
startActivity<LoginActivity>()
finish()
}
}
已编辑:依赖关系
testCompile "android.arch.persistence.room:testing:1.0.0-alpha3"
androidTestCompile "android.arch.persistence.room:testing:1.0.0-alpha3"
compile "android.arch.lifecycle:extensions:1.0.0-alpha3"
compile "android.arch.lifecycle:reactivestreams:1.0.0-alpha3"
kapt "android.arch.lifecycle:compiler:1.0.0-alpha3"
compile "android.arch.persistence.room:runtime:1.0.0-alpha3"
compile "android.arch.persistence.room:rxjava2:1.0.0-alpha3"
kapt "android.arch.persistence.room:compiler:1.0.0-alpha3"
我猜你是在寻找运算符 Observable.interval
而不是 Observable.timer
您正在使用的那个在指定时间后仅发出一次。但是 Observable.interval
每隔指定的时间间隔连续发射。
您必须升级到 alpha4
才能获得适当的 ProGuard 配置。
alpha3
有一个 issue in that it did not include the appropriate ProGuard configuration. As per the alpha4 release notes,已修复。