Android Studio duplicates randomly import lines after hot reload - macos

Is this an official bug or am I doing something wrong?
I'm using Android 3.5.3 and every time I run my Flutter project, some of my import lines are randomly being duplicated or even at times even triplicated.

You can set Android Studio to auto import files.
So my bet is to disable this function or set it to Ask in
File -> Settings -> Editor -> Auto Import -> Java and Dart

Related

Playground import - No such module after updating to Xcode 12

I use playgrounds in a framework project. Sometimes, there were build issues, which always disappeared after building the library.
After updating to Xcode 12, I cannot run the playgrounds anymore.
import UIKit
import PlaygroundSupport
import MyFramework
// Error: No such module `MyFramework`
Select the playground. In the Playground Settings check the Build Active Scheme checkbox.
Note: In Xcode 12.0 you need to change something in the playground code, in order to really trigger the change and see it in Git.

How to Set Up Xamarin.Forms for MacOS Sierra?

Visual Studio seems to be having a hard time starting up, so I'm wondering if there's anything wrong in my setting it up. I'm currently using:
macOS Sierra, version 10.12.6
Visual Studio (VS) for Mac (Community edition), version 7.3.2 (build 12)
Setting up New Solution:
A (New Project):
select Multiplatform App
under Xamarin.Forms, select Blank Forms App (C#)
select Next
B (Configure your Blank Forms App, part 1):
App Name: ABCD
Organizer Identifier: com.WXYZ
Target Platforms: select both Android and iOS
Shared Code: select Use Portable Class Library and Use XAML for user interface files
select Next
C (Configure your Blank Forms App, part 2):
Project Name: ABCD
Solution Name: ABCD
Location: [choose location], select Create a project directory within the solution directory.
Version Control: select nothing
Xamarin Test Cloud: select nothing
select Create
Immediately, VS begins the Adding packages... process. After it's done, the 3 Packages folders have a variety of Xamarin-related files, one of which they all have in common: Xamarin.Forms.
Just as a test, I right-click on ABCD solution folder and select Clean ABCD. Immediately, I get hit with this:
Error XF001: Xamarin.Forms targets have been imported multiple times.
Please check your project file and remove the duplicate import(s).
(XF001) (ABCD)
Why is this happening? I've tried separately deleting each of the Xamarin.Forms file in each of the aforementioned 3 Packages folders, but that did nothing good.
Right-clicking on the error message and selecting Show Error Reference literally just takes me to a Google Search result page for the search term "XF001", which helps 0%.
What am I doing wrong?
I have encountered this as well. It seems like a bug in the current 'New Project' templates, at least in Visual Studio for Mac.
Go into the folder where the csproj file of your shared library is. edit it with Notepad or similar and find the <import> node(s) at the bottom. There should be one which has something relatable to Xamarin in it. Remove this import node, save it and open/reload your solution.
Nuget might generate (for some reason) .nuget.targets and .nuget.props files in the project directory containing Import statements for Xamarin.Forms in addition to the same Import statements in the project file (<project>.csproj).
Backup the .nuget.targets and/or .nuget.props files and try removing the .nuget.targets and .nuget.props files from the project directory.

Android Studio auto Import unavailable for classed in src/test dir

As the title said, during usual development,if I type in Activity, then android.app.Activity will be imported automatically. But during unit test developing in src/test directory, function auto import comes to be unavailable.I have to press Alt+Enter again and again to import the classes.Is any setting to make this automatically? Or some other way to make it easy...
Try do those actions:
Close the Android Studio and open it again
Reload your project, clean the project and build it again. This should ensure that all packages in your projects have been loaded
Make sure that you do not have any graphic plugin that can affect your visual highlights code. I pass through it when i was using Material UI theme.
Check if the Auto Import is switched on in your settings
If you can see the red lamp in the left side of you code and click on it, you will see every wrong thing that the Android Studio can detect on your code, else maybe you are doing something wrong with your imports
If you are using Kotlin, remenber to use the Kotlin suport plugin

Playground Import: No Such Module 'Foo'

I've diligently followed the Apple instructions to import a custom module into a playground, including the instructions here. And yet I get:
Playground execution failed: /var/folders/z3/kd0nj4ln1rgcpm8bdz7067wh0000gs/T/./lldb/1874/playground1.swift:7:8: error: no such module 'Foo'
import Foo
How can I recover to a working Playground import? [Edit: Note, two answers have produced detailed instructions to associate a playground with a framework; I have followed those instructions but no luck. The solution will need to involve reconfiguring something in Xcode; my installation is apparently broken]
Detailed images of the error and attempts:
Here is another attempt, based on the answer of #EricD, showing the directory structure, no dice.
For some of those that none of the above solutions work (and that Xcode build path setting was already set to Unique), I've found a solution.
The framework must be built with a scheme for an iOS simulator device (any in the list) and NOT a Generic iOS Device, as Playgrounds do not support it. This one worked for me :
Here's how I proceed for OS X with Xcode 7.1:
Create new project: OS X Cocoa Framework, Swift. For this example I named it "TestPlaygroundFMK".
Create a new Swift file.
Add a class to the file. The code has to be public. I made this for our example:
import Foundation
public class Talk {
public class func sayHello() {
print("Hello from framework!")
}
}
Build the project now.
In the menu bar, click on File > Save As Workspace.
Create a new Playground and save it inside the project folder next to the Swift files.
The Playground must not have the same name as the project.
Build the project again.
Import your framework in the Playground and use it:
import TestPlaygroundFMK
Talk.sayHello()
I had my playground working fine but found that when I quit Xcode and re-opened it, I would get an error like this:
error:
/var/folders/ft/bmk8wh6s5ms4my2pxhn3qbp40000gn/T/playground1-9216e0..swift:3:8:
error: no such module 'Playground_Sources' import Playground_Sources
... where "Playground" is the name of my playground file.
The solution to this (in Xcode 9.0) is to:
click any playground file in your workspace
show the Utilities panel (opt-cmd-0)
under "Playground Settings" change the "Platform" to anything else then set it back.
In my case, it's set to macOS. I changed it to iOS then back to macOS (no recompilation necessary) and it started to work fine... that is until I close Xcode and open it again.
This is the only solution I found to work with macOS playgrounds. This bug still exists in Xcode 9.3.
I'm not sure i had the exact problem as the original question - but given the mix and age of solutions and the lack of this one that DID work for me, i thought I'd share.
In Xcode 11+ (tested this on 12.2), i'd often have Playgrounds fail to run givn the "No Such Module" error when it included a framework that is a part of the workspace.
The solution for me was in the "File Inspector" for the Playground, and the "Build Active Scheme" option:
This ensures the project was being built appropriately for the target, and now my annoying compile issues are gone!
Create a workspace as below:
Choose File > New > Workspace
Enter the workspace name, and specify its location in your file system
Click Save
Now, Create a Cocoa framework with swift file which have your class
Choose File > New > Project
Select Cocoa framework > Next
Enter Product Name and Language > Next
Before clicking create, in 'Add to:' and 'Group' list choose 'Your workspace name' as shown
Framework is added to your workspace
Create swift file in your framework
In Xcode right click on the folder where you want to add swift file and select new file...
Select swift > Next > Name your file > Create
Select your framework in Xcode -> Build your framework
Create playground -> Playground should also be part of your workspace, if not drag it to your workspace, it'll be added automatically.
Right click in Xcode's files section > New file... > Playground
import
Call your method
Note: If you just wanted to add classes instead of framework to your playground check the link How to import my own class into an Xcode 7 playground?
Solution that worked for me:
Setup your workspace and project/framework.
Delete derived data (How to remove derived data?)
DO NOT BUILD YOUR PROJECT YET
Create playground file with different name then your project/target/framework name under folder with either Swift files or where .xcodeproj is located (does not matter which one you chose)
Build your project under required platform (if playground is for macOS, then build project with macOS target, etc.)
When build finishes try adding some code to your playground and run it.
P.S. you might need to restart Xcode before 6th step.
The solution, from Apple Support, was to adjust my Xcode Preferences. On Locations :: Advanced my configuration was 'Legacy'. By changing to 'Unique', and undoing any paths I'd attempted to insert, Playgrounds can now import frameworks.
I don't think it's a stretch to say that Xcode is somewhat of a blackbox. I make no claim that this will work for anyone else, but for me, after having the same issue after creating a new playground and a new framework target, and all the other proposed solutions, what finally worked was deleting the workspace file and (in my case) regenerating it with cocoapods.
I have no idea why this worked.
Build the framework with release ,this worked for me. (Xcode 10.1, swift 4.2)
Insert a var at the first line and re run
var str = ""

Swift debugger does not show variable values when importing ObjC framework

When I create a new OS X "Game" project with Sprite Kit, and set a breakpoint anywhere I can see the variable values just fine:
Then I change the code to import my own framework (TilemapKit) which is a pure Objective-C framework:
import SpriteKit
import TilemapKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
print("dang!")
}
}
No other changes made. I'm not even using any of the TilemapKit code (yet). When the breakpoint triggers, I see this:
The entire project stops being debuggable as far as observing variable values goes. This behavior is perfectly consistent. Without the framework import I can debug again.
Since I'm on Xcode 7 beta (7A121l) and OS X 10.11 developer preview I know this could simply be a (temporary) bug.
Command line Tiles are set to use the Xcode 7.0 version btw. I tried enabling modules in the framework target, made sure the deployment target is the same (10.11), disabled symbol stripping. I added a Bridging Header and #imported the TilemapKit framework in it (removing the Swift import in that case would still give me the non-debuggable app, so it doesn't seem to matter how or where I import the framework).
Does anyone have a suggestion on what could cause this behavior and how I might go about fixing it - or at least how I could try to narrow down the issue?
Is the culprit more likely to be connected to the project's vs the framework's build settings? Do I need to enable something in the app project to make it compatible with ObjC frameworks? (I already got -ObjC in the Other Linker flags)
UPDATE:
I ran po self in the debug console and found this notice:
<built-in>:3:6: error: module 'TilemapKit' was built in directory '/TilemapKit.framework' but now resides in directory './TilemapKit.framework'
#define __clang_major__ 7
^
missing required module 'TilemapKit'
Debug info from this module will be unavailable in the debugger.
How come the framework build directory changed? And why would that matter and how to fix this?
PS: the same framework in a new ObjC app can be debugged just fine.
I got a message from an Apple developer stating that they've observed this problem, and that it could be fixed by moving the .framework to a subfolder of the project.
Apparently the module .. was built in directory error appears only if the .framework is in the same folder as the .xcodeproj aka $(PROJECT_DIR).
However moving the framework to a subfolder didn't fix the issue in my case, but it's still worth a try until this gets fixed in a newer Xcode 7 beta (still occurs in beta 3).
In my case this was happening because of redundant import statements in my project.
My project mixes swift and objc files, so I have import statements in the bridging_header.h file.
In my bridging_header.h I had #import blah.h
In one of the swift files, I was importing a redundant header from a framework
#import blah // From blah.framework
I removed the redundant import from the swift file, that seems to have fixed it.
I can confirm this is happening in Xcode Version 7.0 beta 4 (7A165t). I had to remove my ObjC framework to get Debugging values to return. If removing your framework isn't an option, the print method is old-school debugging, but still works.
I had this issue a while ago. In my case the Prefix.pch was beeing included inside the Bridging-Header.h. This is not a issue per so, but inside my Prefix.pch there was many C includes that make the lldb fail to import the Bridging-Header.
So I removed the "#import Prefix.pch" from the Bridging-Header and copied just the "#includes" to the obj-c files that I need to use in swift.
The Optimization level is not set to None for the Debug configuration.
Be sure to set it to None for Objective-C apps as shown in Figure 1 and for Swift apps as shown in Figure 2.
The Build Configuration pop-up menu is set to Release in the scheme editor's Run action settings pane.
In Xcode, open the scheme editor by choosing Product > Scheme > Edit Schemeā€¦, select the Run action for your app in the scheme actions pane, then set Build Configuration to Debug as seen in Figure 3.
Go to Edit Scheme on left top corner.
And change the configurations to Debug, if it is release

Resources