Android Studio on Ubuntu 18.04: No Fragments Found... How do I "create one or more Fragments in code"? - android-studio

Scenario
I'm starting to learn Android Development on my Ubuntu laptop, but having issues with creating layouts with fragments.
Steps Taken
I created a new project with an Empty Activity
I right-clicked my app folder and performed: New > Fragment > Fragment (Blank),
Named it TestingFragment
Unchecked "Include fragment factory methods?"
Unchecked "Include interface callbacks?"
Under res > layout I updated the fragment (fragment_testing) to recognize it within the main activity
I went to the activity_main.xml file, added the FrameLayout to the layout
I tried to drag the < fragment > component to the FrameLayout
I receive an error message with just an OK button:
No Fragments Found
You must first create one or more Fragments in code.
My Best Guess
It appears that my Android studio is not recognizing that I have the fragment code created and just need to add it to the layout.
Perhaps I need to configure the Gradle scripts to be able to find the TestingFragment class?
What I've Tried from Googling Around
I have installed, uninstalled and re-installed Android Studio using Snapcraft
I have installed, uninstalled and re-installed Android Studio using android-studio-ide-191.5791312-linux.tar.gz from the official Android Download site within the /opt directory.
I have made sure all plugins are checked via File > Settings > Plugins
I have verified that my Android SDK Location is pointing to the right folder via Tools > SDK Manager.
Under SDK Platforms the following SDKs are installed and checked:
Android 10.0 (Q)
Android 7.1.1 (Nougat)
Android 7.0 (Nougat)
I have tried the File > Invalidate Caches / Restart... option choosing the Invalidate and Restart button
I have tried the File > Sync Project with Gradle Files option.
I have tried the File > Sync with File System option
Edit:
I have been able to go into the xml of the main_activity layout file and add a fragment tag manually and found that it can work. The following is the manual tag I managed to add:
<fragment
android:id="#+id/fragment"
android:name="android.example.testfragments.ListFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="#layout/fragment_list" />
Still working on fixing the drag-drop "No fragments found" issue.
Where to go from here?
Does anyone know where I can go from here other than virtualizing another OS like Windows to see if it works there?

Solution
So after hours of poking around the settings and googling around, I discovered the reason why it wasn't working by accident.
While creating a new project, the application's Package name field cannot follow the "android.example.packageName" pattern.
After being unsuccessful for so long, I decided to try a new project and change all the options to completely start anew from scratch. During the process, I changed the package name to "com.frags.testing".
I then proceeded with the steps described above to make a fragment and I was successfully able to add the fragment using the drag-drop method into the main_activity layout.
I also verified that this worked by going back to my previous project where it wasn't working and creating a new package named fragments and refactored the fragment class to that new package. I then went back to the main_activity layout and dragged the < fragment > component to the layout and it successfully found the fragment.
Hope this helps someone else out there.
Cheers,
Justin

Related

Kotlin Multipplatform - can't see Greeting.kt in Android Studio folder tree

I am just starting to learn KMM (I'm an Android java guy right now) and going through the default Greeting version of Hello World that is automatically put into a new application. My environment seems to be working as I was able to run the default app on both Android and iOS emulators.
However I can't see the file Greeting.kt in the Project tree. I can certainly search for it and open it from Find, but when I drill down the tree shared/commonMain/kotlin/com.myapp... it only shows Platform.
I have a screen cap that shows the path of the open Greeting.kt at the top, but not visible in the tree:
(screen cap)
Unfortunately I can't post an image (not enough reputation), but when I open the file Greeting.kt by doing a Find In Project, it shows the path at the top of the screen (My Application > shared > src > commonMain > kotlin > com > example > myapplication > Greeting), but when I manually drill down the Project tree on the left side of Android Studio Greeting.kt does not show up.
I can also find the file in the Mac Finder. My guess a preference in Android Studio is incorrect?
Any ideas on what might be wrong?
Thanks in advance
Turns out it was an official bug. Solution is to upgrade to Beta version of Android Studio (Chipmunk)
I submitted a bug report to Google and they looked into it:
The root cause is that before [Android Studio]Chipmunk the source set
setup was incorrect, so even though it says commonMain in your
screenshot (from #2), if you open the Platform.kt under that source
set, you'll see that it is in fact
shared/src/androidMain/kotlin/com/example/myapplication/Platform.kt.
[Android Studio] Chipmunk fixes this issue.

Can't add a new activity on android studio

I'm trying to improve my android development skills, so working on some project about it. In my project, I added a new "Navigation Drawer Activity", then I deleted it because I wanted to create a new one but I can not able to add even another type of activitiy. Android studio adds ,
<activity
android:name=".ExampleActivity"
android:label="#string/title_activity_main" >
</activity>
tag in AndroidManifest.xml but It doesn't create any classes and xml layout files.
Also studio says:
ide internal error occurred android studio.
I tried regenerate R.java and clean my project ,but it doesn't work. How can I get rid of this problem?
Try to add a simple JavaClass and write an "extends Activity" behind the class name. And put this new Activity in the Manifest like in your example. You can add a menu and a layout like this, too, when you add xml-Files in the layout and menu folders. This should work.
I can not find a exact solution to that problem. Re-installed the Android Studio . It does the solution manually
If it's about how Activities is not showing up as an option in either the shortcut menu in the Layout folder or File + New in the menu, you can try File + "Sync Project with Gradle files" and give it some time.
This also adds options to the Tools menu (great if AVD or SDK Manager is missing).

Android Studio is installing old apk on device

I am developing an Android app using Android Studio (0.89 Build #AI-135.1404660, Built on Sept 3,2014) using both emulator and Nexus 4 device.
I had the same issue with a version prior to that.
The problem is that after I changed my code and resource files, I still get the old apk installed on the device or emulator.
What do I need to do to get it to run current code? Is it a building config?
Is it a known issue with Android Studio?
Or with a Nexus 4 device?
This is the second time it has happened, and I resolved it(then) after trying one of the steps below. They have not worked for me again.
Here is what I've tried
Build > Clean Project > Restart Android Studio > Run
Build > Rebuild Project > Run
Step 1 plus Uninstalling of apk on device
Step 2 plus Unistalling of apk on device
Adding erroneous resource entry then running.
I have read the following:
Android apk install: How to clear files from old version?
adb - How to reinstall an app, without retaining the data?
Device still has the old apk
Android build doesn't update code base or resources for target .apk on device
None has worked so far.
I had the same problem. After trying numerous methods that didn't work, I realized that I had accidentally changed an option in my "Run Configuration". Here's exactly what I did to fix the issue.
Run --> Edit Configurations
With your configuration selected on the left panel (mine says "app"), in the General tab on the right panel, there is a section called "Before launch". This section should have an option added called "Gradle-aware Make", but I had accidentally removed it.
I re-added it by pressing the "+", then clicking OK in the popup (leave the input box in the popup blank).
Click apply.
This fixed the problem immediately. Hope this helps someone!
Run / Debug Configurations / Miscellaneous TAB
[] Uncheck: Skip installation if APK has not changed
Android Studio doesn't always detect small changes in code.
The behaviour is erratic. I solved it by reviewing my code.It turned out that there was a resource file that was invalid. Try reverting back to the last working version of your code before the current changes... Probably a known issue that will be/was resolved out of Beta
Google thinks it is a feature, not a bug
https://code.google.com/p/android/issues/detail?id=156263
Their proposed solution is to copy the apk(s) instead of manipulating the filename, as in e.g.
Copying APK file in Android Gradle project
I've spent way too many hours to keep this to myself. The way I fixed it was that I noticed some hours later that I was using different layout version in res/ .... I have actually two versions of layout (layout-v26) and (layout). All this time I was modifying the other one and uploading different one. Maybe its just a newbie mistake but I hope somebody will find it useful.
The reason why there are 2 version was because of " autofillHints="" -> quickfix -> create new version of layout "
image of my tree
I am using android studio for building flutter app, I was facing the same issue untill I did the following:
From Android Studio, go to Tools-Flutter-FlutterClean
It resolved my problem as of now.
Check Your Layout Files.
I ran into the same problem and I realized, it gives some problem if you have same layout in multiple orientations(portrait and landscape). If one is changed other remains unchanged and then it creates a conflict. So android studio installs the one with the previous layout
PS: This was happening in my case.
The problem occurred on my Android 11 devices. I guess ART ran old code dex2oated.
Solution:
Run / Debug Configurations - General - Always install with package manager (disable deploy optimization on Android 11 and later), and check the option.
I was also facing this issue and get solution by deleting build folder manually because some time ide cannot be able to delete this. So go to the app folder and find build folder delete this and after clean and build project and run again.
projectname->app->build
You should select "Deploy default APK" option in Run/Debug Configurations. After that Android Studio will upload and install new apk to your emulator/device when you run application.
In android studio. at right side. see gradle option. click it. and then press circular arrows button shown in red square.
Same problem, none of the solutions mentioned here had any effect. I had to disable the "Allow parallel run" in "Menu > Run > Edit configurations...".
You can read more about this option here: How to run the same project multiple times in IntelliJ IDEA?
The solution to this issue is actually very simple.
Android studio is actually not detecting some small changes that you have made to the application. That is why it is installing the previous builds.
The solution is easy -> Remove the previous builds.
In the right side, go to gradle tab.
Expand Tasks. Find "clean" or "cleanCache" task or any task that starts with "clean". Double click to run that task.
Expand "app". and do the same.
Then File> Invalidate cache and restart.
Enjoy!! Your problem is solved...
My devices also ran old states - dont know from where in my git it has taken these.
I created a new configuration (default is "app") and it worked.

Android studio no main activity, no layouts on a new project

I installed new Android Studio. I created new Project and asked the wizard to create main activity. But there were no layouts, no main activity class, no nothing. Error on trying to make new Java class files. The new project tree looks like this:
No (main/java) folder.
No (res/layout) folder.
Other words project is useless.
From what i learned is that you may be picking the "no layout" option when prompted to pick one. Try picking the basic activity and the rest of the files will show
After creating the project, you need to go to File menu and then Import Project. Then browse to the location of your project and import it. Then you will see all of these files and folders. I had this problem too, and it seems to be something that they overlooked in the newer versions of Android Studio (which is quite pathetic if you ask me).
Empty Activity
Choose "Empty Activity" instead of "No Activity",
while creating a NEW PROJECT in Android Studio.
I don't know if anyone is having the same problem right now but i solved this issue by changing the Android Gradle plugin version and the Gradle version.
For doing this you have to open the project you're having issues with and click on
File->Project Structure->Project
and there you will see the two options.
Android Gradle Plugin Version 4.0.0 and Gradle version 6.1.1 worked for me. After that I went to the file directory, right click on the package folder "com.example.myProject" and manually created an empty activity. The layout folder with my new activity was created automatically after that.
I found it's because I changed the Java runtime version before through the Android Studio plugin Choose Runtime. I changed to JDK 8 from JDK 11 then the problem occured. It worked for me to change back to JDK 11 through plugin Choose Runtime.
Try
Typing main activity (without quotes) in the search box and
Press enter.
For me it got restored. Search window is useful in finding many hidden tools quickly.
I created a new activity by right clicking on java then selected activity and the layout file was automatically written
When you open a new project, you can't select "empty project" you have to select and activity project. I just went through this had to delete my project and start a new one now everythings there.

Visual Studio 2012 Add New Class Missing Template

I've just installed VS2012 Ultimate side by side with VS2010 and it seems the standard templates are broken. I cannot add a class nor a console application.
File > New > File dialog contains the "Visual C# Class" template
but Right Click Project > Add > Class dialog does not contain the "Visual C# Class" template
Also File > New Project only contains MVC4 and not things like Console Application even if I change framework version and left filter.
EDIT: This only occurs after installing update 1. We have tried reinstalling, repairing, deleting the templates cache and reinstalling templates. We're considering working without update 1 at the moment, but there doesn't seem to be a way to uninstall just the update.
Corrupted ISO supplied, tried another from msdn and all fine now.

Resources