0

I have encountered a problem which I think is caused by the android studio. I am developing on the stable version of the android studio. when it's on debug everything works fine. but the moment that I switch to release variant or generate a signed APK the app will crash on different occasions. the stack trace is:

java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.finishComposingText()' on a null object reference
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
                                                                  at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)

troubleshooting steps:

  1. changing the test phone.
  2. trying D8 compiler
  3. going back and forth between DEbug and Release variant

so the last try was to run the exact same project on different android studio (actually a different PC). the app started I played with it for a while it was just fine. no crashes and nothing suspicious. even tried different phones but the crash did not happen.

My setup:

  1. Mac version 10.13.4
  2. Android Studio version 3.0.1

the other computer setup:

  1. Windows 10
  2. Android Studio version 3.0.1

any help will be appreciated.

UPDATE:

After trying disabled proguard release version is now fine but now the problem is the same rules and dependencies have been applied to both PCs yet proguard functions differently!

dependencies:

def dependencyGroup(Closure closure) {
    closure.delegate = dependencies
    return closure
}

project.ext {
    supportLibrary = "27.0.0"
    multidex = "1.0.1"
    archComponent = "1.1.0"
    pagingComponent = "1.0.0-alpha6"
    dagger = "2.14.1"
    butterKnife = "8.8.1"
    rxJava = "2.1.6"
    rxBinding = "2.0.0"
    rxAndroid = "2.0.1"
    rxBroadCast = "2.0.0"
    timber = "4.6.0"
    constraint = "1.0.2"
    google = "12.0.1"
    oneSignal = "3.8.3"
    retrofit = "2.3.0"
    moshi = "1.5.0"
    okHttp = "3.9.1"
    autoValue = "1.5"
    autoMoshi = "0.4.5"
    autoRedacted = "1.0.1"
    autoWith = "1.0.0"
    autoParceler = "0.2.6"
    fresco = "1.5.0"
    frescoProcessor = "2.1.0"
    leakCanary = "1.5.4"
    btmNav = "2.1.0"
    store = "3.0.0"
    dexter = "4.2.0"
}

def testLibs = dependencyGroup {

    testImplementation 'junit:junit:4.12'
    testImplementation 'org.mockito:mockito-core:1.10.19'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

def support = dependencyGroup {
    implementation "com.android.support:appcompat-v7:$project.supportLibrary"
    implementation "com.android.support:design:$project.supportLibrary"
    implementation "com.android.support:support-v13:$project.supportLibrary"
    implementation "com.android.support:support-v4:$project.supportLibrary"
    implementation "com.android.support:support-media-compat:$project.supportLibrary"
    implementation "com.android.support:support-fragment:$project.supportLibrary"
    implementation "com.android.support:support-core-utils:$project.supportLibrary"
    implementation "com.android.support:support-core-ui:$project.supportLibrary"
    implementation "com.android.support:support-annotations:$project.supportLibrary"
    implementation "com.android.support:support-vector-drawable:$project.supportLibrary"
    implementation "com.android.support:transition:$project.supportLibrary"
    implementation "com.android.support:customtabs:$project.supportLibrary"
    implementation "com.android.support:cardview-v7:$project.supportLibrary"
    implementation "com.android.support.constraint:constraint-layout:$project.constraint"

    implementation "com.android.support:multidex:$project.multidex"
}

def archComponent = dependencyGroup {
    implementation "android.arch.lifecycle:extensions:$project.archComponent"
    implementation "android.arch.lifecycle:common-java8:$project.archComponent"
    implementation "android.arch.paging:runtime:$project.pagingComponent"
//    implementation "android.arch.lifecycle:reactivestreams:$project.archComponent"

}

def analytics = dependencyGroup {

    implementation "com.google.firebase:firebase-core:$project.google"
    implementation "com.google.firebase:firebase-crash:$project.google"

    implementation "com.onesignal:OneSignal:$project.oneSignal"
}

def google = dependencyGroup {
    implementation "com.google.android.gms:play-services-base:$project.google"
    implementation "com.google.android.gms:play-services-identity:$project.google"
    implementation "com.google.android.gms:play-services-auth:$project.google"

    implementation "com.google.android.gms:play-services-gcm:$project.google"
    implementation "com.google.android.gms:play-services-location:$project.google"
    implementation "com.google.android.gms:play-services-maps:$project.google"
    implementation "com.google.android.gms:play-services-places:$project.google"
//    implementation "com.google.android.gms:play-services-auth-api-phone:$project.google"
}

def RX = dependencyGroup {
    implementation "io.reactivex.rxjava2:rxandroid:$project.rxAndroid"
    implementation "io.reactivex.rxjava2:rxjava:$project.rxJava"

    implementation "com.cantrowitz:rxbroadcast:$project.rxBroadCast"
}

def rxBinding = dependencyGroup {
    implementation "com.jakewharton.rxbinding2:rxbinding:$project.rxBinding"
//    implementation "com.jakewharton.rxbinding2:rxbinding-design:$project.rxBinding"
//    implementation "com.jakewharton.rxbinding2:rxbinding-support-v4:$project.rxBinding"
    implementation "com.jakewharton.rxbinding2:rxbinding-appcompat-v7:$project.rxBinding"
//    implementation "com.jakewharton.rxbinding2:rxbinding-recyclerview-v7:$project.rxBinding"
}

def butterKnife = dependencyGroup {
    implementation "com.jakewharton:butterknife:$project.butterKnife"
    annotationProcessor "com.jakewharton:butterknife-compiler:$project.butterKnife"
}

def autoValue = dependencyGroup {
    provided "com.jakewharton.auto.value:auto-value-annotations:$project.autoValue"

    annotationProcessor "com.google.auto.value:auto-value:$project.autoValue"
    annotationProcessor "com.gabrielittner.auto.value:auto-value-with:$project.autoWith"
    annotationProcessor "com.squareup.auto.value:auto-value-redacted:$project.autoRedacted"
}

def parceler = dependencyGroup {
    annotationProcessor "com.ryanharter.auto.value:auto-value-parcel:$project.autoParceler"
    implementation "com.ryanharter.auto.value:auto-value-parcel-adapter:$project.autoParceler"
}

def moshi = dependencyGroup {
    implementation "com.squareup.moshi:moshi:$project.moshi"
    annotationProcessor "com.ryanharter.auto.value:auto-value-moshi:$project.autoMoshi"
    provided "com.ryanharter.auto.value:auto-value-moshi-annotations:$project.autoMoshi"
}

def dagger = dependencyGroup {
    implementation "com.google.dagger:dagger:$project.dagger"
    annotationProcessor "com.google.dagger:dagger-compiler:$project.dagger"
}

def daggerAndroid = dependencyGroup {
    implementation "com.google.dagger:dagger-android-support:$project.dagger"
    // if you use the support libraries
    annotationProcessor "com.google.dagger:dagger-android-processor:$project.dagger"
}

def annotation = dependencyGroup {
    implementation 'org.jetbrains:annotations-java5:15.0'
    implementation 'javax.annotation:jsr250-api:1.0'
}

def retrofit = dependencyGroup {
    implementation "com.squareup.retrofit2:retrofit:$project.retrofit"
    implementation "com.squareup.retrofit2:adapter-rxjava2:$project.retrofit"
    implementation "com.squareup.retrofit2:converter-moshi:$project.retrofit"
    implementation "com.squareup.okhttp3:okhttp:$project.okHttp"
    implementation "com.squareup.okhttp3:logging-interceptor:$project.okHttp"
}

def timber = dependencyGroup {
    implementation "com.jakewharton.timber:timber:$project.timber"
}

def fresco = dependencyGroup {
    implementation "com.facebook.fresco:fresco:$project.fresco"
    implementation "jp.wasabeef:fresco-processors:$project.frescoProcessor"
}

def leakCanary = dependencyGroup {

    debugImplementation "com.squareup.leakcanary:leakcanary-android:$project.leakCanary"
    releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$project.leakCanary"
}

//noinspection GroovyUnusedAssignment
def store = dependencyGroup {
    implementation "com.nytimes.android:cache3:$project.store"
    implementation "com.nytimes.android:store3:$project.store"
    implementation "com.nytimes.android:middleware-moshi3:$project.store"
    implementation "com.nytimes.android:filesystem3:$project.store"
}

def ui = dependencyGroup {
    implementation "com.aurelhubert:ahbottomnavigation:$project.btmNav"
    implementation 'me.zhanghai.android.materialratingbar:library:1.2.0'
    implementation 'com.github.ashokslsk:SquareRatingView:1.2'
    implementation 'com.github.stfalcon:frescoimageviewer:0.5.0'

//    implementation 'org.zakariya.stickyheaders:stickyheaders:0.7.6'
//    implementation 'com.bignerdranch.android:recyclerview-multiselect:0.2'
    implementation 'com.bignerdranch.android:simple-item-decoration:1.0.0'
    implementation 'com.klinkerapps:android-chips:1.3.0@aar'
    implementation 'com.sothree.slidinguppanel:library:3.4.0'
    implementation 'com.github.jakob-grabner:Circle-Progress-View:v1.3'
}

//noinspection GroovyUnusedAssignment
def job = dependencyGroup {
    implementation 'com.evernote:android-job:1.2.1'
}

//noinspection GroovyUnusedAssignment
def jwPlayer = dependencyGroup {
    implementation 'com.longtailvideo.jwplayer:jwplayer-core:+'
    implementation 'com.longtailvideo.jwplayer:jwplayer-common:+'
}

def utils = dependencyGroup {
    implementation "com.karumi:dexter:$project.dexter"
    implementation 'com.f2prateek.rx.preferences2:rx-preferences:2.0.0-RC3'
    implementation 'com.linchaolong.android:imagepicker:1.5'
    implementation 'com.google.maps.android:android-maps-utils:0.5+'
//    implementation 'com.beloo.widget:ChipsLayoutManager:0.3.7@aar'
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testLibs()
    analytics()
    google()
    support()
    archComponent()
    RX()
    rxBinding()
    retrofit()
//    store()
    autoValue()
    parceler()
    moshi()
    timber()
    butterKnife()
    dagger()
    daggerAndroid()
    fresco()
    leakCanary()
    annotation()
    ui()
    utils()
//    job()
//    jwPlayer()
}

and proguard rule:

#########################auto value
# Retain generated classes that end in the suffix
-keepnames class **_MoshiTypeAdapter

# Prevent obfuscation of types which use @GenerateTypeAdapter since the simple name
-keep class **.AutoValue_*
#########################

#ButterKnife
#########################
-keep public class * implements butterknife.Unbinder { public <init>(**, android.view.View); }
-keep class butterknife.*
-keepclasseswithmembernames class * { @butterknife.* <methods>; }
-keepclasseswithmembernames class * { @butterknife.* <fields>; }
#########################
#Moshi
#########################
-dontwarn okio.**
-dontwarn javax.annotation.**
-keepclasseswithmembers class * {
    @com.squareup.moshi.* <methods>;
}
-keep @com.squareup.moshi.JsonQualifier interface *
#########################

#Dagger
#########################
-dontwarn com.google.errorprone.annotations.*
#########################

#Retrofit
#########################
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions
#########################

#OkHttp
#########################
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-dontwarn org.conscrypt.**
# A resource is loaded with a relative path so the package of this class must be preserved.
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase
#########################

#Fresco
#########################
# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip
-keep,allowobfuscation @interface com.facebook.soloader.DoNotOptimize

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
    @com.facebook.common.internal.DoNotStrip *;
}

# Do not strip any method/class that is annotated with @DoNotOptimize
-keep @com.facebook.soloader.DoNotOptimize class *
-keepclassmembers class * {
    @com.facebook.soloader.DoNotOptimize *;
}

# Keep native methods
-keepclassmembers class * {
    native <methods>;
}
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**
-dontwarn com.facebook.infer.**
#########################

#Timber
#########################
-dontwarn org.jetbrains.annotations.NonNls
#########################

#LeakCanary
#########################
-keep class org.eclipse.mat.** { *; }
-keep class com.squareup.leakcanary.** { *; }
#########################

#printing mapping for firebase
#########################
-printmapping build/outputs/mapping/release/mapping.txt
#########################

-ignorewarnings

UPDATE 2. I just managed to update my android studio to version 3.1.1 and updating gradle and plugin to the latest version.

unfortunately error still exist only stack trace has changed:

java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.inputmethod.InputConnection.finishComposingText()' on a null object reference
    at android.view.inputmethod.InputConnectionWrapper.finishComposingText(InputConnectionWrapper.java:78)
    at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:362)
    at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:78)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:148)
    at android.app.ActivityThread.main(ActivityThread.java:7407)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
seyed Jafari
  • 1,235
  • 10
  • 20

2 Answers2

6

I don't know exactly how to solved it, but something similar happened to me and I managed to fix it by removing android studio completely and reinstalling.

remove from mac remove from windows

Masoud Mokhtari
  • 2,390
  • 1
  • 17
  • 45
0

I actually found the solution!. Advance profiling option is making this problem. by disabling the in

Run->Edit Configurations-> Profiling

the problem is now gone.

hope it helps future readers!

seyed Jafari
  • 1,235
  • 10
  • 20