Android Studio Layout Inspector stuck on Loading - android

I haven't been able to get the Android Studio Layout Inspector to work for some time on a specific project. I have tried few things found from searching around, like upgrading AS and restoring to the default settings. I am currently using the inspector image for "API 31 and T" I have also tried the others.
Looking in the idea log file, I see this exception when loading the Inspector.
2022-05-19 16:19:35,530 [ 802382] INFO - transport.TransportFileManager - Pushing layoutinspector-view-inspection.jar to /data/local/tmp/perfd/...
2022-05-19 16:19:35,666 [ 802518] INFO - transport.TransportFileManager - Successfully pushed layoutinspector-view-inspection.jar to /data/local/tmp/perfd/.
2022-05-19 16:19:35,989 [ 802841] WARN - ayoutinspector.LayoutInspector - java.lang.NoSuchMethodError: No static method mapNotNull(Lkotlin/sequences/Sequence;Lkotlin/jvm/functions/Function1;)Lkotlin/sequences/Sequence; in class Lkotlin/sequences/SequencesKt; or its super classes (declaration of 'kotlin.sequences.SequencesKt' appears in /data/app/~~O7aoUUFLvI3ubR8HLfx25g==/com.something.android.debug-ZXXoStc-19BHJGftwM6nRw==/base.apk!classes2.dex)
at com.android.tools.agent.appinspection.framework.SkiaQWorkaround.getFieldValue(SkiaQWorkaround.kt:43)
at com.android.tools.agent.appinspection.framework.SkiaQWorkaround.startRenderingCommandsCapture(SkiaQWorkaround.kt:66)
at com.android.tools.agent.appinspection.ViewLayoutInspector.startCapturing(ViewLayoutInspector.kt:371)
at com.android.tools.agent.appinspection.ViewLayoutInspector.access$startCapturing(ViewLayoutInspector.kt:71)
at com.android.tools.agent.appinspection.ViewLayoutInspector$handleStartFetchCommand$3.invoke(ViewLayoutInspector.kt:412)
at com.android.tools.agent.appinspection.ViewLayoutInspector$handleStartFetchCommand$3.invoke(ViewLayoutInspector.kt:410)
at com.android.tools.agent.appinspection.util.ThreadUtils$runOnMainThread$1.run(ThreadUtils.kt:56)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)

I figured from the error that these functions were not being included in the final apk. I wrote some code that would force it to be included like:
fun makeLayoutInspectorHappy() {
sequenceOf("").mapNotNull(null)
(0F).roundToInt()
}
But the list of functions kept growing. Looking into why these functions were not there in the first place, I saw that another developer had enabled minification for the debug build.
debug {
minifyEnabled true
}
I changed it to false and the Layout Inspector now works!

Related

Android release build crash - Doesn't find the shared module from yarn workspaces monorepo

I am using monorepo created using Yarn Workspaces which has a react-native project (mobile folder) and a common folder which contains the common files to be shared across projects. Here the mobile project is dependent on common files.
The Android app runs fine in debug mode. When I run in release mode, it crashes as soon as it opens. I am getting the below error.
E/ReactNativeJS: Invariant Violation: Module AppRegistry is not a registered callable module (calling runApplication). A frequent cause of the error is that the application entry file path is incorrect.
This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.
--------- beginning of crash
2022-06-07 23:48:09.865 5772-5799/? E/AndroidRuntime: FATAL EXCEPTION: mqt_native_modules
Process: com.myapp.mobile, PID: 5772
com.facebook.react.common.JavascriptException: TypeError: t is not a function. (In 't(u)', 't' is undefined), stack:
<unknown>#460:2846
map#-1
<unknown>#460:2825
N#457:7733
<unknown>#455:172
h#2:1585
<unknown>#453:262
h#2:1585
<unknown>#403:148
h#2:1585
<unknown>#6:57
h#2:1585
d#2:958
global code#529:3
at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.java:72)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:188)
at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
at android.os.Looper.loop(Looper.java:223)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$4.run(MessageQueueThreadImpl.java:228)
at java.lang.Thread.run(Thread.java:923)
While researching about this, I came across this suggestion and tired it. Found out that the functions which I import from common is causing this error. It is present in node_modules but not sure whether it is getting packed into the bundle or not.
Mobile's package.json:
Any Suggestions?
I think you should change the import flow the way you are importing the package in your package.json file.
See the example below of the react-native-image-crop-picker importing the library in their example code.
And the library code is in the same parent directory.

Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError

Getting some very odd behaviour on my Google Play Pre-Launch report, and it's only just started occurring, but I can't pin it down to anything I have changed. I also can't reproduce the issue myself.
Every test device seems to be failing in the pre-launch report (6/6 devices all fail the same way). However repeating the steps on the same build on a real device, I can never recreate it. The stack trace is as follows:
FATAL EXCEPTION: Thread-8
Process: uk.myapp.test, PID: 25312
java.lang.NoSuchMethodError: No static method createWithResource(Landroid/content/res/Resources;Ljava/lang/String;I)Landroidx/core/graphics/drawable/IconCompat; in class Landroidx/core/graphics/drawable/IconCompat; or its super classes (declaration of 'androidx.core.graphics.drawable.IconCompat' appears in base.apk)
at androidx.core.app.NotificationCompat$Action.<init>(NotificationCompat.java:4572)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.createPlaybackActions(PlayerNotificationManager.java:1439)
at com.google.android.exoplayer2.ui.PlayerNotificationManager.<init>(PlayerNotificationManager.java:757)
at com.google.android.exoplayer2.ui.PlayerNotificationManager$Builder.build(PlayerNotificationManager.java:564)
at uk.myapp.test.AudioPlayerService.onCreate(AudioPlayerService.java:96)
at android.app.ActivityThread.handleCreateService(ActivityThread.java:3570)
at android.app.ActivityThread.access$1300(ActivityThread.java:200)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1672)
at android.os.Handler.dispatchMessage(Handler.java:106)
at androidx.test.espresso.base.Interrogator.loopAndInterrogate(Interrogator.java:10)
at androidx.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:7)
at androidx.test.espresso.base.UiControllerImpl.loopUntil(UiControllerImpl.java:1)
at androidx.test.espresso.base.UiControllerImpl.injectMotionEvent(UiControllerImpl.java:5)
at androidx.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:6)
at androidx.test.espresso.action.MotionEvents.sendUp(MotionEvents.java:1)
at androidx.test.espresso.action.Tap.sendSingleTap(Tap.java:5)
at androidx.test.espresso.action.Tap.-$$Nest$smsendSingleTap(Unknown Source:0)
at androidx.test.espresso.action.Tap$1.sendTap(Tap.java:1)
at androidx.test.espresso.action.GeneralClickAction.perform(GeneralClickAction.java:4)
at androidx.test.espresso.ViewInteraction$SingleExecutionViewAction.perform(ViewInteraction.java:2)
at androidx.test.espresso.ViewInteraction.doPerform(ViewInteraction.java:21)
at androidx.test.espresso.ViewInteraction.-$$Nest$mdoPerform(Unknown Source:0)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:2)
at androidx.test.espresso.ViewInteraction$1.call(ViewInteraction.java:1)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Not exactly sure but I think it's an issue with the Robo tests that Firebase test lab uses. I haven't tried using their instrumented tests instead, but it's the only explanation I can currently think of.
I implemented reverting the Firebase BOM version like the other answer suggested, but it didn't (or at least didn't fully resolve) the issue for me. Reverting this other dependency finished solving it for me:
Crashing version:
implementation 'com.google.android.gms:play-services-location:19.0.1'
Working version:
implementation 'com.google.android.gms:play-services-location:18.0.0'
EDIT: initially reverting to 29.0.2 release of Google Firebase BOM (from 29.0.3) fixed the issue for me, however problem has reared it's ugly head again, and excluding all firebase components doesn't fix it, so my original fix was merely a plaster.
I am now using Firebase Test Lab to conduct runs (it's much quicker than pushing builds to Google Play, and having to bump the number each time and wait a day). Firebase Test Lab fails the same way, and much quicker (you get 5 runs a day for free). I can now see that it's something related to R8 code obfuscation.
Setting minifyEnabled to false and it works just fine, setting it to true, it crashes every time.
So it appears to be be releated to this R8 bug: https://issuetracker.google.com/issues/213617215#comment22
For me, I have worked around this issue by adding this to my Proguard rules file. It now passes on Firebase Test Lab.
-keep class androidx.core.graphics.drawable.** { *; }

React Native: ViewManager for tag could not be found

We are getting several of the following errors when running logcat in our React Native Android app. Intially they seem harmless and they doesn't crash the app. However, if possible I'd like to get some guidance on how to debug them to understand what's going on.
Unable to update properties for view tag 323
com.facebook.react.uimanager.IllegalViewOperationException: ViewManager for tag 323 could not be found.
View already dropped? false.
Last index 0 in last 100 views[I#1eeace9
at com.facebook.react.uimanager.NativeViewHierarchyManager.resolveViewManager(NativeViewHierarchyManager.java:112)
at com.facebook.react.uimanager.NativeViewHierarchyManager.updateProperties(NativeViewHierarchyManager.java:135)
at com.facebook.react.uimanager.UIImplementation.synchronouslyUpdateViewOnUIThread(UIImplementation.java:309)
at com.facebook.react.uimanager.UIManagerModule.synchronouslyUpdateViewOnUIThread(UIManagerModule.java:396)
at com.facebook.react.animated.PropsAnimatedNode.updateView(PropsAnimatedNode.java:94)
at com.facebook.react.animated.NativeAnimatedNodesManager.updateNodes(NativeAnimatedNodesManager.java:544)
at com.facebook.react.animated.NativeAnimatedNodesManager.runUpdates(NativeAnimatedNodesManager.java:453)
at com.facebook.react.animated.NativeAnimatedModule$1.doFrameGuarded(NativeAnimatedModule.java:100)
at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:29)
at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:172)
at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:84)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:965)
at android.view.Choreographer.doCallbacks(Choreographer.java:791)
at android.view.Choreographer.doFrame(Choreographer.java:722)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:952)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
EDIT: Just for reference we are using react-native 0.60.5, react-navigation 3.13.0 and react-native-paper 3.10.1. Also, we see these errors when we first open the app.
Thanks!
In my case, I was using the properties flex and padder of a View from Native Base after the property style. When I moved the two properties before the style property everything starts working 🤦‍♂️
Faced this problem recently, we had a common package that had UI Components for both web and mobile. A component was using the css property 'inherit'. This is fine in web, but it caused the crash in mobile.
In my case, it was a mistake it was a typo in a style.

Expo - APK bundle must contain the expected embedded asset

I'm new on react, and i tried to run my app but i got this following error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bits.bee.bwc, PID: 12601
java.lang.AssertionError: APK bundle must contain the expected embedded asset asset_c2f3d742a18a28238b7cd34a5d4b7316.png
at expo.modules.updates.loader.EmbeddedLoader.copyAllAssets(EmbeddedLoader.java:174)
at expo.modules.updates.loader.EmbeddedLoader.processManifest(EmbeddedLoader.java:137)
at expo.modules.updates.loader.EmbeddedLoader.loadEmbeddedUpdate(EmbeddedLoader.java:57)
at expo.modules.updates.UpdatesController.start(UpdatesController.java:286)
at expo.modules.updates.UpdatesController.initialize(UpdatesController.java:96)
at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1011)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4552)
at android.app.ActivityThread.access$1500(ActivityThread.java:147)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1342)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5255)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Can someone explain to me how it's work because i looked it up in my asset folder there's nothing named like that. And how do i fix this? Thanks
Info
This exception only happened to me when running a debug build with react-native run-android and the exception did not appear when running a release build with react-native run-android --variant=release.
Solution
Check whether you have the following line in MainApplication.java and if it's there then remove that line:
import com.facebook.react.BuildConfig;
Explanation
The line import com.facebook.react.BuildConfig; causes UpdatesController.initialize(this); to be called in Debug mode which shouldn't happen.
More detail:
When you look at your Stacktrace you posted the line
at com.bits.bee.bwc.MainApplication.onCreate(MainApplication.java:98)
points to UpdatesController.initialize(this);. Including the line above and below that's how it looks like:
if (!BuildConfig.DEBUG) {
UpdatesController.initialize(this);
}
This BuildConfig here points to the BuildConfig class of your package (com.bits.bee.bwc in your case) which is created during the build. If you import com.facebook.react.BuildConfig it will point to another BuildConfig class which does not contain the correct DEBUG value you want.
Since BuildConfig.DEBUG will then be undefined or false, UpdatesController.initialize(this); is called although it shouldn't during a debug build. Hence, because assets will be not embedded for debug builds, the copyAllAssets function which is eventually called will not find any assets and we get the above error.
Some Context of why I ended up importing com.facebook.react.BuildConfig;
I was facing the issue of java.lang.UnsatisfiedLinkError: couldn't find DSO to load: libhermes.so in my release build and followed the advice to add that line as stated here https://stackoverflow.com/questions/57036317/react-native-java-lang-unsatisfiedlinkerror-couldnt-find-dso-to-load-libherm/63048532#answer-62119615. It didn't make a change for the release build and I forgot about it. Only later when I attempted to make a debug build I got this error.. took me quite a while to realize that this added line is the cause of the issue!
What I learned from debugging this issue:
Don't just add things because you think it won't hurt. If it doesn't fulfill a certain purpose or has no effect, remove the change immediately. It can otherwise cause strange side effects later.
If you have build issues with Android, debug with Android Studio instead of Flipper. Flipper doesn't display you the entire Stacktrace and in Android Studio you can easily browse through all the Java files which eventually helped me to understand this Exception.

Flutter firestore force close (error) in build apk release

I got error at firestore stuff when build apk release, the app force close when access that firestore code. But its fine when direct running (debug) in AS/VS code. Any one can explain this?
java.lang.RuntimeException: Internal error in Firestore (19.0.0).
at com.google.firebase.firestore.g.j.a(:379)
at com.google.firebase.firestore.g.g.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
Caused by: java.lang.AbstractMethodError: abstract method "b.b.g.w$d b.b.g.w$d.b(int)"
at b.b.g.r.a(:1319)
at b.b.e.a.da.C(:5440)
at b.b.e.a.da.a(:5509)
at b.b.e.a.da.a(:13)
at b.b.e.a.da$a.a(:6589)
at com.google.firebase.firestore.f.y.b(:730)
at com.google.firebase.firestore.c.h.a(:215)
at com.google.firebase.firestore.c.va.c(:103)
at com.google.firebase.firestore.c.va.a(:142)
at com.google.firebase.firestore.c.t.a(:530)
at com.google.firebase.firestore.c.q.run(Unknown Source:6)
at com.google.firebase.firestore.c.na.a(:180)
at com.google.firebase.firestore.c.t.a(:520)
at com.google.firebase.firestore.b.P.a(:178)
at com.google.firebase.firestore.b.m.a(:91)
at com.google.firebase.firestore.b.z.b(:152)
at com.google.firebase.firestore.b.v.run(Unknown Source:4)
at com.google.firebase.firestore.g.j.a(:311)
at com.google.firebase.firestore.g.f.call(Unknown Source:2)
at com.google.firebase.firestore.g.j.a(:287)
at com.google.firebase.firestore.g.e.run(Unknown Source:4)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at com.google.firebase.firestore.g.j$a.run(:205)
at java.lang.Thread.run(Thread.java:764)
To fix this error, update android.enableR8=false in gradle.properties. You need to add this row cause default value true.
There seems to be an issue with the resource optimization (shrink code and obfuscation) when dealing with the Firestore package as seen from java.lang.AbstractMethodError: abstract method "b.b.g.w$d b.b.g.w$d.b(int)" which appears to be obfuscated code.
The help message from flutter build apk -h states that
--[no-]shrink Whether to enable code shrinking on release mode.When enabling shrinking, you also benefit from obfuscation, which shortens the names of your app’s classes and members, and optimization, which applies more aggressive strategies to further reduce the size of your app. To learn more, see: https://developer.android.com/studio/build/shrink-code (defaults to on)
You can use the --no-shrink tag when building the apk such as flutter build apk --release --no-shrink to disable shrink code and obfuscation but note that this results in a larger apk.

Categories

Resources