On real devices (Nexus 5, Leeco, Xiaomi, ...). Observe the method works, but when I started the tests in Firebase Test Lab, the application worked with launch with an exception on many devices (virtual Nexus 10 with 22 api, for example):
java.lang.RuntimeException: Unable to start activity ComponentInfo ...
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.arch.lifecycle.Lifecycle$State android.arch.lifecycle.Lifecycle.getCurrentState()' on a null object reference
at android.arch.lifecycle.LiveData.observe(LiveData.java:188)
In action:
public class ActivityCabinet extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_cabinet);
vmCabinet = ViewModelProviders.of(this).get(VmActivityCabinet.class);
vmCabinet.enumSideNavigationMode.setValue(EnumSideNavigationMode.MAIN_LIST);
vmCabinet.enumSideNavigationMode.observe(this, enumSideNavigationMode -> {
...
}
}
}
in gradle:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.0.0'
implementation 'com.android.support:customtabs:27.0.0'
implementation 'com.android.support:cardview-v7:27.0.0'
implementation 'com.android.support:recyclerview-v7:27.0.0'
implementation 'com.android.support:design:27.0.0'
implementation 'com.android.support:support-v4:27.0.0'
implementation 'com.android.support:transition:27.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'android.arch.lifecycle:extensions:1.0.0-rc1'
implementation 'android.arch.persistence.room:runtime:1.0.0-rc1'
annotationProcessor "android.arch.persistence.room:compiler:1.0.0-rc1"
implementation 'com.android.support:multidex:1.0.2'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation 'com.google.android.exoplayer:exoplayer:r2.5.0-beta1'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.3.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.3.0'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.thoughtbot:expandablerecyclerview:1.3'
implementation 'com.facebook.android:facebook-android-sdk:4.25.0'
implementation 'com.appsflyer:af-android-sdk:4.8.3@aar'
implementation 'com.google.firebase:firebase-core:11.4.2'
implementation 'com.google.android.gms:play-services-ads:11.4.2'
implementation('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
transitive = true
}
}
apply plugin: 'com.google.gms.google-services'
main gradle
buildscript {
repositories {
google()
jcenter()
mavenLocal()
mavenCentral()
maven { url 'https://maven.google.com' }
maven { url 'https://maven.fabric.io/public'}
maven { url 'https://oss.sonatype.org/content/repositories/snapshots'}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0-alpha01'
classpath 'com.google.gms:google-services:3.1.1'
classpath 'io.fabric.tools:gradle:1.24.1'
}
}
allprojects {
repositories {
google()
jcenter()
mavenLocal()
mavenCentral()
maven { url 'https://maven.fabric.io/public'}
maven { url 'https://oss.sonatype.org/content/repositories/snapshots'}
maven { url "https://maven.google.com"}
}
}
I cannot understand the reason for the exception on devices in the test lab.
source
share