Cannot watch Kotlin variable in android studio - debugging

I am not able to get android studio display the value of a calculation in the watches window.
I use Kotlin for development and when i try to add a value to watches, i get a message which says "An exception occurs during evaluate expression".
e.g.
val model = MyModel()
val pos = model.position
Now if I add model.position to watches, then it gives the above error and the value of the expression is not displayed.
How can I fix this?

That's bug in Android studio.
1) I've reported mentioned bug (or very similar) recently:
https://issuetracker.google.com/issues/62859634
2) If you find a bug in tools, report it to Google:
https://issuetracker.google.com/issues/new

This bug should be already fixed in new Dex compiler.
Try to enable it by adding:
android.enableD8=true
to your gradle.properties.file
For more details check official blogpost.

file> invalidate caches / restart .. fixed it for me

Related

VS Code debugger: failure to find module (utf-8 characters)

When I try to run a Node.js debugging session from Visual Code, the debugging console returns an error, saying that the bootloader.bundle.js could not be found. However, the bootloader.bundle.js file exists at the expected location, while the debug console specifies the folder incorrectly by substituting a UTF-8 character (letter č) with the replacement character (�). The snippet of the error message can be found below:
Error: Cannot find module 'c:/Users/xxxx xxxx�/AppData/Local/Programs/
Microsoft VS Code/resources/app/extensions/ms-vscode.js-debug/src/bootloader.bundle.js'
Can I somehow fix this in VS Code, perhaps by modifying the launch.json file in some way or some other settings?
Any help is appreciated!
EDIT:
I temporarily fixed the issue by reinstalling VS Code to another folder without that doesn't include diacritical characters. I'd like to to keep this question open, however, in case somebody knows of a way to fix this sort of problem (e.g. by by modifying some configuration files) that does not require either reinstalling or relying on a portable version of the app.
I have just dealt with the same issue. There have been Unicode characters in my folder's path and I got the same error "Cannot find module". Reasons are described in details here.
To fix it I have gone to File - Preferences - Settings and then entered "usePreview" and then I unchecked the option "Use the new in-preview JavaScript debugger for ..." under the section "Debug > JavaScript: Use Preview" and reloaded VS Code. The issue has gone.

SwiftUI / Xcode Error - Updating took more than 5 seconds

When I try to preview one of my views in the canvas I keep getting the following error:
PreviewUpdateTimedOutError: Updating took more than 5 seconds
All my other views load perfectly fine.
Why is this happening and how do I resolve?
I am using SwiftUI in Xcode 11.4 (public release)
I stopped using the simulator and chose "Any iOS Device" and that solved the problem.
In my case the issue was this line in Build settings:
Something I did accidentally changed signing settings in my project. Specifically, "signing identity" was set to "Sign to Run Locally.".
For some reasons, SwiftUI Previews don't work then.
Simply deleting this line from build settings (aka setting default value) solved the problem.
Some time, the error displaying is not the real error.
For me it was because i missing : .environmentObject(...)
As of Xcode 12.5.1, the message PreviewUpdateTimedOutError: Updating took more than 5 seconds most likely means that your app crashed and thus updating the preview failed. The real reason for the crash is unfortunately obscured by this useless message (why Apple would do that is beyond me). To get at the real reason, you'll need to:
click Diagnostics at the top of the preview next to the useless error message
in the next dialog, click Generate Report > Reveal in Finder
This will take a bit. Then Finder will open with a folder highlighted. Open that folder. Inside you'll see a lot of log files and folders.
If your app indeed crashed, you'll see a folder called CrashLogs which contains crash logs for your app, including the error message and stack trace. This should help you resolve the actual error causing the preview to break.
Note that for me, sometimes the CrashLogs were not included in the report even though my app really did crash. Retrying the preview and generating another report fixed this for me. The whole error reporting process seems to be rather unstable for the previews, unfortunately.
Try Clean (Shift + ⌘ + K) and Build (⌘ + B) to build again the SwiftUI project, it works in Xcode 11.6. Try building a basic hello world app.
In my case the issue was that the PreviewProvider was marked private. Simply make it internal or remove the private access modifier.
private /* <- remove */ struct YourView_Previews: PreviewProvider {
static var previews: some View {
// Your previews
}
}
I am using Version 13.2.1 (13C100). I have Clean (Shift + ⌘ + K) and Build (⌘ + B) the project. But, the problem remains.
Then, just restarted Xcode. And the problem gone.
In my case viewModel required to display SwiftUI_preview was doing a call to a CoreData (fast call) in the init of the viewModel.
Moved actual call of that "reload() method" so it's not called on preview, fixed.
(I believe the correct way is to use mocked protocol instead of instance of the viewModel)
If you have an .onAppear clause, try commenting that out for preview.
None of these suggestions helped me but I did discover that you can't rely entirely on a successful build to pick up all issues. In my case I had '.modifier(modifier:)' entered incorrectly as 'modifier(modifier:)'. My code built successfully but my preview did not work until I added the period before modifier.
For me the issue was related to a force unwrapping of an element not being found at preview time.
Note: Always check the diagnostics report. The issue will be at the top section after termination reason.
In my case the canvas/screen size was smaller than the content, so simply wrapping my content in the scrollView do remove the error and displaying the content in the canvas.
I had a fatalError("...") in my code, which I only figured out after reading the diagnostic logs. Would be nice if SwiftUI actually hinted this!
You can get the diagnostics by clicking "Diagnostics" next to "Try Again" at the top of the preview window.
To summarise lots of answers here, it seems that the preview taking a while to update is the equivalent of a crash, when running on a real device or on the simulator.
First comment out all the environment Objects are used for the particular View. Once you get preview then uncomment it to run the build. This trick works for me
//#EnvironmentObject var observerObj:PropertyObserver
I had this issue as well, and nothing fixed the problem. I am now on 11.6 and after updating the issue went away. I think it might be a problem with Xcode 11.4.
I'd suggest updating Xcode if possible.
In SwiftUI, you couldn't add more than 10 subviews into your contentview, otherwise it couldn't compile.
I had the same problem, then I started to comment out the subViews inside my main view, one by one & try to preview again then I found out the problem was caused because I forgot to put a dot before one of the subViews attributes.
So that's how I fixed it.
The reason is because its unable to find the landmarkData.json file. To resolve this,
select landmark.json file in Resources.
Show Inspectors ( top right icon )
Select show file inspector
Under Target membership, select / check Landmarks
This should resolve the preview issue.
For some reason, in SwiftUI, when I embeded Text in Scroll View and VStack, this error occurred. After few unsuccessful attempts to fix this by clearing and building project, I deleted code and wrote it down again, same as it was. Now it is working.
I had my run device set to a real device I use for testing. When I changed that to one in the simulator it started working again.
Similar to #YannSteph, this happened to me because I put the .environmentObject() at the app entry point where it creates the first view:
#main
struct RecipeApp: App {
var body: some Scene {
WindowGroup {
RecipeTabView()
.environmentObject(RecipeModel())
}
}
}
But this prevented the preview from working. I thought I was being smart putting it there, so all the views could have access to it, but it just crashed the preview.
Moving it back into the main View.Swift file that is my app's starting view fixed the preview issue.
^^^
EDIT: Ran into this again when I didn't put the .environmentObject() in the struct for the preview. Probably a rookie mistake but there appears to be many ways to trigger this error.
I had the same issue after creating a brand new Multiplatform App project using Xcode 12.5. Based on the solutions above I followed a hunch and now believe that the issue is due to invalid path parameters.
After renaming the Schemes and Targets from (iOS) to .iOS (and the same for macOS), to remove spaces and brackets, it is now working.
I had this issue after changing bundle id and signing from personal to team.
After changing device to Any device as advised here, I received another error description, saying
Could not install the preview host "AppName.app" on iPhone 12 Pro Max
agentBundle = com.bundle.Its.AppName {
url: file:///Users/macbookair/Library/Developer/Xcode/DerivedData/AppName-> desupjbpqvjlegfbskxydixpouvc/Build/Intermediates.noindex/Previews/AppName/Prod> ucts/Debug-iphonesimulator/AppName.app
> version: 49557
signingInformation: Code Signing {
identifier: com.bundle.AppName
hasGetTaskAllow: false
isSandboxed: false
}
}
Clean build, deleting Derived, Deleting all apps installed on simulators, cleaning Xcode Cache, restarting Xcode and Mac didn't help.
What had helped was creating new project with initially correct bundle id and copying all my files there.
I have got into the same issue on Xcode 12.4, but the code works fine on Xcode 13.0.
I was following the IOS App Dev Tutorial, where one creates an app named ScrumDinger. I ran into this issue at Displaying Data in List
In my case the problem was that I wrote in CardView.swift
HStack {
Label("\(scrum.attendees.count)", systemImage: "person.3")
accessibilityLabel("\(scrum.attendees.count) attendees")
instead of
HStack {
Label("\(scrum.attendees.count)", systemImage: "person.3")
.accessibilityLabel("\(scrum.attendees.count) attendees")
The missing dot before accessibilityLabel was the problem.
Tutorial:
https://developer.apple.com/tutorials/app-dev-training/displaying-data-in-a-list
In my case the issue was that I was trying to preview a view with a fixed width (.previewLayout(.fixed(width: 344, height: 220))) wider than the selected simulator (iPhone SE 1st generation) 😬
I get this error often. My last time of occurrence, I had "gesture" instead of ".gesture". Usually its best to just need to find the error in your code yourself because Xcode does not point out the issue directly.
I only had Xcode 14 Beta installed on my machine and the previews did not work. All of the other answers did not work for me.
Installing Xcode 13.4.1 and running the preview with it did solve my problems and now I can also see the preview in Xcode 14 Beta as well.
In my case, I disabled automatic canvas refresh by going to Editor -> Canvas -> Automatically Refresh Canvas and making sure it.
Then I use ⌥⌘P (Command-Option-P) to refresh the canvas preview.

Can't see values while debugging

I'm using Visual Studio 2015, and when I hit a breakpoint, I cannot get any info on the values of variables.
When hovering over a variable, nothing comes up.
In Immediate Window or Watches, I get:
error CS0648: '' is a type not supported by the language
This happened all of a sudden, as it used to work until yesterday.
I've tried a few things including resetting all user settings, deleting *.user files, restarting Visual Studio, and even restarting Windows.
What else can I try?
Update: I've written a blog post about this problem and how to reproduce it.
You won't believe this but it seems that this is somehow related to a const expression I had. Removing const and using a variable solved the problem.
How weird. Didn't manage to reproduce on a simple console application. The problem originally occurred on an ASP .NET 5 Web Application.
Update: see more details in my blog post which also explains how to reproduce the issue.
This is a bug currently being tracked by aspnet/Home issue #955.
Console Application repro for reference:
REPRO
Open VS2015 (Windows 10, ASP.NET 5 Beta 7)
Click File > New > Project > Web > Console Application (Package) > Ok
Edit Program.cs to reflect code snippet below.
Add a breakkpoint just after Console.WriteLine(a);
Run the project
Right-click variables a and b click Add Watch
CODE
public void Main(string[] args)
{
const int a = 3;
int b = 4;
Console.WriteLine(a);
}
EXPECTED
Watch window displays values for variables a and b
ACTUAL
Watch window Value column for variables a and b displays:
error CS0648: '' is a type not supported by the language
NOTES
The value of a is written correctly to Console
Removing const from the snippet reverts to EXPECTED bevahiour
I had one variable that had CONST and once I removed that all my types showed up and had values in them.

Unable to display variable values

Environment: Xcode Version 5.0.1 (5A2034a)
Scenario:
1) I've create a simple Apple-supplied iOS project template.
2) I create a local string value with an initial value; plus a local integer variable with value.
3) I did a debug 'po' & 'p' for the object and integer.
Xcode's debugger apparently doesn't see these values.
The following are a couple of snippets of the debugger's environment:
As you can see, the debugger's symbol-generator is ON and the optimization is set to NO (zero).
1) Here's another example.
Note: NSLog() does work.
Notice the 'Turkey' for 'testString' value. Why this value?
'Turkey' was used in ANOTHER project and has no relevance to this one sample project.
It appears that I'm getting variable bleed from some xcode environment peculiar to Xcode 5;
...not found/experienced in Xcode 4.
Okay, this is weird. I've tried the NSLog() and got the values displayed. Then just for kicks I did a 'po' again and got the correct value.
However I still have the 'Turkey' value:
2) Here's a second example.
Starting with a new application from the Apple-supplied view template:
This time, the NSLog() works but again, can't get the 'po' value.
I still haven't figured out the pattern here.
What else can I do?
How can I get my debugger 'po' & 'p' commands to show data?
Or... why am I'm getting inconsistent debugger behavior (Xcode5 appears to work okay; re 'NSLog()')?
I had this recurrent problem so I tried logging via a different account to find the problem disappeared.
So there's something wrong with my Xcode account; specifically:
So I emptied the Xcode folder found under ~/Library/Developer and restarted Xcode.
Apparently the problem(s) is/are solved.

how to using NSZombieEnabled on intrument Xcode 3.2.5

i have some problem in memory management, and then i try to fix it using intrument tool.
Base on mark j video on you tube
about using NSZombieEnabled in intrument, i try to do like that. The problem is i never find a checkbox to set NSZombieEnabled active in my instrument. In this case i use xcode 3.2.5 and still on IOS 4.2.
This is the screenshot from the instrument that show no one check box for NSZombieEnabled activated :
am i doing something wrong??
help me please
thank you
Try running your application on simulator and see if you get the option in instruments. You may refer this tutorial to see how it is done in XCode 3.2 or you may refer the accepted answer in this thread for XCode 4.
Why not installing the new xCode 4? There you can easily set the EnvironmentVariables in the Scheme under the tab Arguments for Debug.
To check if it is actually set I use this code...
if(
getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled")
) {
NSLog(#"--------------------------------------->NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
}
There is a simple way to enable NSZombie if you are dealing with XCode version 4 through implementation of the following simple step:
Please click on the scheme drop down bar named Product choose -> edit scheme -> arguments tab and then add NSZombieEnabled in the Environment Variables column and YES in the value column...Now you are done with enabling NSZombie to find bugs in program.
When you run your app,you get an error message where the app crashes setting NSZombie state to enabled,but originally before enabling NSZombie,you might find it difficult to find out what's exactly wrong,like crash at autorelease pool,gdb break currently using objective-c,BAD_ACCESS errors etc... By enabling NSZombie you can find what is exactly the problem such as improper deallocation and trying to re-access,or improper release of memory etc..The errors may be of the following kind:
-[ExampleProgramViewController alertView:didDismissWithButtonIndex:]: message sent to deallocated instance 0x7068f70

Resources