简体   繁体   中英

Android App works in debug but not in release

I'm developing an Android app and I have a problem when I run the app in release mode. If I start the app in debug mode I get this type of message in the Logcat (the app doesn't start):

E/AndroidRuntime: FATAL EXCEPTION: GoogleApiHandler Process: it.planner, PID: 27326 java.lang.SecurityException: In order to use mock mode functionality app it.planner must be selected as the mock location application in developer settings. at android.os.Parcel.readException(Parcel.java:2008) at android.os.Parcel.readException(Parcel.java:1954) at com.google.android.gms.internal.zzeu.zzb(Unknown Source:10) at com.google.android.gms.internal.zzcfa.zzbj(Unknown Source:9) at com.google.android.gms.internal.zzcfd.zzbj(Unknown Source:13) at com.google.android.gms.internal.zzcfk.zzbj(Unknown Source:2) at com.google.android.gms.internal.zzcee.zza(Unknown Source:4) at com.google.android.gms.common.api.internal.zzm.zzb(Unknown Source:8) at com.google.android.gms.common.api.internal.zzc.zza(Unknown Source:6) at com.google.android.gms.common.api.internal.zzbo.zzb(Unknown Source:9) at com.google.android.gms.common.api.internal.zzbo.zzaiw(Unknown Source:82) at com.google.android.gms.common.api.internal.zzbo.onConnected(Unknown Source:16) at com.google.android.gms.common.internal.zzac.onConnected(Unknown Source:2) at com.google.android.gms.common.internal.zzn.zzakr(Unknown Source:130) at com.google.android.gms.common.internal.zze.zzw(U nknown Source:64) at com.google.android.gms.common.internal.zzi.zzaks(Unknown Source:51) at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source:270) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loop(Looper.java:166) at android.os.HandlerThread.run(HandlerThread.java:65) E/iMonitor: FaultDetect: DUMPTOOL_PRINTF return.

Obviously, if I select the mock location in Developer Options , the app starts and works fine .

If I install the release apk and I try to start the app, the app doesn't start and I get this kind of messagge in Logcat:

E/AndroidRuntime: FATAL EXCEPTION: main Process: it.planner, PID: 29448 java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at android.support.v4.app.FragmentManagerImpl.checkStateLoss(FragmentManager.java:2054) at android.support.v4.app.FragmentManagerImpl.enqueueAction(FragmentManager.java:2077) at android.support.v4.app.BackStackRecord.commitInternal(BackStackRecord.java:678) at android.support.v4.app.BackStackRecord.commit(BackStackRecord.java:632) at it.planner.Home.mainMenu(Home.java:374) at it.planner.Home.computeGeolocation(Home.java:487) at it..planner.Home.access$100(Home.java:80) at it.planner.Home$3$1.onLocationResult(Home.java:344) at com.google.android.gms.internal.zzcff.zzu(Unknown Source:4) at com.google.android.gms.common.api.internal.zzci.zzb(Unknown Source:8) at com.google.android.gms.common.api.internal.zzcj.handleMessage(Unknown Source:16) at android.os.Handler.dispatchMessage(Handler.java:109) at android.os.Looper.loop(Looper.jav a:166) at android.app.ActivityThread.main(ActivityThread.java:7377) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)

There is no possibility to select the mock location once the app is in release mode, so it doesn't want to start. I've been dealing with this problem for many days. I also tried with minifyEnabled false in the Gradle file but it doesn't work.

The gradle file is the following:

buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.release
        }
        debug {
            debuggable true
        }
    }
    sourceSets {
        main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] }
        debug {
            manifest.srcFile 'src/main/AndroidManifest.xml'
        }
    }

This issue is probably because of the Fragment transaction was not committed using the proper API. try to find

transaction.commit();

and replace it with

transaction.commitAllowingStateLoss();

Some more discussion is here: https://github.com/OneBusAway/onebusaway-android/issues/529#issuecomment-224974339

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