Is there a known issue between AGP 7.1.0-alpha03 a...
# gradle
f
Is there a known issue between AGP 7.1.0-alpha03 and Android coroutines when R8 is enabled? On AGP 7.1.0-alpha02 my app runs fine, but on alpha03 it crashes on launch with R8 enabled. I'm using Kotlin 1.5.10 and coroutines 1.5.0.
😶 1
n
This thread should be moved to the #android-studio channel.
f
Maybe the coroutines channel, the crash points to the coroutines library
g
Could you share a stacktrace
f
yes, but it's not going to be useful as I haven't decoded it yet. I can't do so right now, but I'll look into it later today
Copy code
07-10 18:33:45.845 30889 30889 E AndroidRuntime: FATAL EXCEPTION: main
07-10 18:33:45.845 30889 30889 E AndroidRuntime: Process: <http://com.example.myapp.app|com.example.myapp.app>, PID: 30889
07-10 18:33:45.845 30889 30889 E AndroidRuntime: java.lang.NullPointerException
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at kotlinx.coroutines.scheduling.a.g(Unknown Source:4)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at kotlinx.coroutines.scheduling.a.h(Unknown Source:11)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at kotlinx.coroutines.scheduling.c.N(Unknown Source:7)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at kotlinx.coroutines.internal.h.b(Unknown Source:33)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at f5.a.c(Unknown Source:15)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at f5.a.d(Unknown Source:5)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at b5.h.c(Unknown Source:74)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at b5.g.c(Unknown Source:0)
07-10 18:33:45.845 30889 30889 E AndroidRuntime: 	at com.example.myapp.app.feature.feature.one.FeatureAViewModel.M0(Unknown Source:78)
07-10 18:33:45.845 30889 30889 E
neither
retrace.sh
nor
proguardgui
deobfuscated the trace. Looking at the
mapping.txt
file, I can make these links
Copy code
07-11 10:31:28.815  4469  4469 E AndroidRuntime: 	at kotlinx.coroutines.scheduling.a.g(Unknown Source:4)
07-11 10:31:28.815  4469  4469 E AndroidRuntime: 	at kotlinx.coroutines.scheduling.a.h(Unknown Source:11)
07-11 10:31:28.815  4469  4469 E AndroidRuntime: 	at kotlinx.coroutines.scheduling.c.N(Unknown Source:7)

kotlinx.coroutines.scheduling.CoroutineScheduler -> kotlinx.coroutines.scheduling.a:
    kotlinx.coroutines.internal.Symbol NOT_IN_STACK -> p
    kotlinx.coroutines.scheduling.GlobalQueue globalBlockingQueue -> k
    java.lang.String schedulerName -> i
    kotlinx.coroutines.scheduling.GlobalQueue globalCpuQueue -> j
    java.util.concurrent.atomic.AtomicReferenceArray workers -> l
    java.util.concurrent.atomic.AtomicIntegerFieldUpdater _isTerminated$FU -> o
    long idleWorkerKeepAliveNs -> h
    int corePoolSize -> f
    int maxPoolSize -> g
    java.util.concurrent.atomic.AtomicLongFieldUpdater parkedWorkersStack$FU -> m
    java.util.concurrent.atomic.AtomicLongFieldUpdater controlState$FU -> n
    void signalCpuWork() -> C
    boolean tryCreateWorker(long) -> D
    boolean tryCreateWorker$default(kotlinx.coroutines.scheduling.CoroutineScheduler,long,int,java.lang.Object) -> I
    boolean tryUnpark() -> L
    int createNewWorker() -> a
    kotlinx.coroutines.scheduling.Task createTask(java.lang.Runnable,kotlinx.coroutines.scheduling.TaskContext) -> b
    kotlinx.coroutines.scheduling.CoroutineScheduler$Worker currentWorker() -> e
    void dispatch(java.lang.Runnable,kotlinx.coroutines.scheduling.TaskContext,boolean) -> g
    void dispatch$default(kotlinx.coroutines.scheduling.CoroutineScheduler,java.lang.Runnable,kotlinx.coroutines.scheduling.TaskContext,boolean,int,java.lang.Object) -> h
    boolean isTerminated() -> k
    int parkedWorkersStackNextIndex(kotlinx.coroutines.scheduling.CoroutineScheduler$Worker) -> l
    kotlinx.coroutines.scheduling.CoroutineScheduler$Worker parkedWorkersStackPop() -> m
    boolean parkedWorkersStackPush(kotlinx.coroutines.scheduling.CoroutineScheduler$Worker) -> o
    void parkedWorkersStackTopUpdate(kotlinx.coroutines.scheduling.CoroutineScheduler$Worker,int,int) -> s
    void runSafely(kotlinx.coroutines.scheduling.Task) -> v
    void shutdown(long) -> w

07-11 10:31:28.815  4469  4469 E AndroidRuntime: 	at kotlinx.coroutines.internal.h.b(Unknown Source:33)

kotlinx.coroutines.internal.DispatchedContinuationKt -> kotlinx.coroutines.internal.h:
    kotlinx.coroutines.internal.Symbol UNDEFINED -> a
    kotlinx.coroutines.internal.Symbol REUSABLE_CLAIMED -> b
    kotlinx.coroutines.internal.Symbol access$getUNDEFINED$p() -> a
    void resumeCancellableWith(kotlin.coroutines.Continuation,java.lang.Object,kotlin.jvm.functions.Function1) -> b
    void resumeCancellableWith$default(kotlin.coroutines.Continuation,java.lang.Object,kotlin.jvm.functions.Function1,int,java.lang.Object) -> c
    boolean yieldUndispatched(kotlinx.coroutines.internal.DispatchedContinuation) -> d
the code that appears to crash, in
onStart
is subscribing to a
flow
Copy code
timerJob = timerService
            .runningFlow
            .onEach { running ->
                if (preferences.keepScreenOn) {
                    if (running) {
                        window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
                    } else {
                        window?.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
                    }
                }
                invalidateOptionsMenu()
                overflowVisible = !running
            }
            .launchIn(lifecycleScope)
I'll keep messing with it to see if I can get
retrace.sh
to provide any useful info
Copy code
FATAL EXCEPTION: main
Process: com.example.myapp.app.dev, PID: 5527
java.lang.NullPointerException
	at kotlinx.coroutines.scheduling.CoroutineScheduler.dispatch(:384)
	at kotlinx.coroutines.scheduling.CoroutineScheduler.dispatch$default(:383)
	at kotlinx.coroutines.scheduling.ExperimentalCoroutineDispatcher.dispatch(:66)
	at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(:332)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(:30)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(:25)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(:170)
	at kotlinx.coroutines.BuildersKt.withContext(:1)
	at com.example.myapp.app.feature.full.FeatureAViewModel.matchPreset(:860)
	at com.example.myapp.app.feature.full.FeatureAViewModel.access$matchPreset(:60)
	at com.example.myapp.app.feature.full.FeatureAViewModel$launchMatchPreset$1.invokeSuspend(:875)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(:33)
	at kotlinx.coroutines.internal.DispatchedContinuationKt.resumeCancellableWith(:377)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(:30)
	at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable$default(:25)
	at kotlinx.coroutines.CoroutineStart.invoke(:110)
	at kotlinx.coroutines.AbstractCoroutine.start(:126)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(:56)
	at kotlinx.coroutines.BuildersKt.launch(:1)
	at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(:47)
	at kotlinx.coroutines.BuildersKt.launch$default(:1)
	at com.example.myapp.app.feature.full.FeatureAViewModel.launchMatchPreset(:873)
	at com.example.myapp.app.feature.full.FeatureAViewModel.removeNdFilter(:751)
	at com.example.myapp.app.feature.full.FeatureAViewModel.setNd1FilterVisibility(:703)
	at com.example.myapp.app.feature.full.FeatureAViewModel.setNdFiltersVisibility(:688)
	at com.example.myapp.app.feature.full.FeatureAViewModel.setWheelsVisibility(:651)
	at com.example.myapp.app.feature.full.FeatureAViewModel.onParamsChanged(:388)
	at com.example.myapp.app.feature.full.FeatureAViewModel.start(:364)
	at com.example.myapp.app.feature.full.FeatureAViewModel.onStart(:326)
	at androidx.lifecycle.FullLifecycleObserverAdapter.onStateChanged(:39)
	at androidx.lifecycle.LifecycleRegistry$ObserverWithState.dispatchEvent(:354)
	at androidx.lifecycle.LifecycleRegistry.forwardPass(:265)
	at androidx.lifecycle.LifecycleRegistry.sync(:307)
	at androidx.lifecycle.LifecycleRegistry.moveToState(:148)
	at androidx.lifecycle.LifecycleRegistry.handleLifecycleEvent(:134)
	at androidx.fragment.app.Fragment.performStart(:3024)
	at androidx.fragment.app.FragmentStateManager.start(:568)
	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(:277)
	at androidx.fragment.app.FragmentStore.moveToExpectedState(:113)
	at androidx.fragment.app.FragmentManager.moveToState(:1327)
	at androidx.fragment.app.FragmentManager.dispatchStateChange(:2757)
	at androidx.fragment.app.FragmentManager.dispatchStart(:2707)
	at androidx.fragment.app.Fragment.performStart(:3028)
	at androidx.fragment.app.FragmentStateManager.start(:568)
	at androidx.fragment.app.FragmentStateManager.moveToExpectedState(:277)
	at androidx.fragment.app.FragmentStore.moveToExpectedState(:113)
	at androidx.fragment.app.FragmentManager.moveToState(:1327)
	at androidx.fragment.app.FragmentManager.dispatchStateChange(:2757)
	at androidx.fragment.app.FragmentManager.dispatchStart(:2707)
	at androidx.fragment.app.FragmentController.dispatchStart(:273)
	at androidx.fragment.app.FragmentActivity.onStart(:486)
	at androidx.appcompat.app.AppCompatActivity.onStart(:210)
	at com.example.myapp.app.feature.MainActivity.onStart(:161)
	at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1435)
	at android.app.Activity.performStart(Activity.java:8024)
	at android.app.ActivityThread.handleStartActivity(ActivityThread.java:3475)
	at android.app.servertransaction.TransactionExecutor.performLifecycleSequence(TransactionExecutor.java:221)
	at android.app.servertransaction.TransactionExecutor.cycleToPath(TransactionExecutor.java:201)
	at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:173)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:97)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
	at android.os.Handler.dispatchMessage(Handler.java:106)
	at android.os.Looper.loop(Looper.java:223)
	at android.app.ActivityThread.main(ActivityThread.java:7656)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
I've deobfuscated the stack trace
my comment earlier about the
flow
was incorrect, the crash happens when I call
withContext(Dispatchers.Default
to run some code while in a coroutine context (the viewmodel's)
g
So it looks as an issue with R8, maybe proguard configs for coroutines should be updated, or maybe it’s an issue of R8 on latest beta
I assume without obuscation there is no issue
f
yes, the problem only happens w ith R8 enabled and with AGP 7.1.0-alpha03, alpha02 is fine
j
are you using this?:
Copy code
android.enableR8.fullMode=true
☝️ 1
g
I think you probably should report it to Android issue tracker
1
f
I'm not using
android.enableR8.fullMode
n
Why not try the latest beta05?
f
I don't understand the question. I'm using
7.1.0-alpha03
which is the latest
j
If r8 with alpha02 works and r8 with alpha03 does not, when you've made 0 changes to the project aside from
alpha02 -> alpha03
, and you're cleaning the project etc, then I can't see how that'd be anything other than a bug in most scenarios
I assume you're using gradle 7.1.1?
f
a bug in which component, in your opinion?
to confirm, I have changed nothing other than the AGP from alpha02 to alpha03 and I am using gradle 7.1.1
j
I would say it's r8
"Android Public Tracker > App Development > Android Studio > Build Tools > Shrinker (R8)"
f
thanks, I'll file a bug
👍 1
n
Sorry, i misread that as 7.0.0-alpha03 not 7.1.0-alpha03
👍 2
f
closing the loop, Google's R8 team confirmed this is a recent regression and a fix is already in place but not deployed yet.
✔️ 2