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

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.

Related

Android Studio: file-> "Project Structure" missing options to change application id, version, version name, etc

So every time i updated my app, i use file -> project structure to increase the version and put version name. I also use it to name application id when i want to fork my codes into different app.
but today I can't find application id, version, version name, etc on file-> "Project Structure".
a few months ago i also got this problem and the options suddenly come back by itself.
so I don't know how to fix it. I need those options...
What I've tried
loading old projects
refreshing Gradle files and sync
rebuilding the project
If the "Sync Project with Gradle" does not appear, open the Android folder separately.i.e like an independent project. File->Open. In my case, I was working on a Flutter/Kotlin project. When I opened the Android folder it automatically started syncing and downloading the required gradle files.
oh my God, fixed it by
File > Sync Project with Gradle
File > project structure > modules (will still be blank)
File > project structure > suggestion -> click APP (bottom right will say "loading" with tiny fonts)
File > project structure > modules (now the options will appear)
I don't see "Sync Project with Gradle", but I saw "sync with file system". This worked once, but now Project structure is gone again. Clicking "sync with file system" doesn't work anymore.
Try the keyboard shortcut, for example on Windows is "ctrl+alt+shift+S"
I fixed by Open module settings (Right-click the project -> Open module settings) change some value and apply it
then the project structure is showing up

How to add a new directory/folder in a package in Android Studio

I'm trying to simply add a new directory in a package in my Android Studio project (I'm new to AS and Android dev). I want to categorize some java files and my hierarchy is: app/src/main/java/com.company.foo.bar and I want to add a folder under bar. I right-clicked on com.company.foo.bar and selected New->Folder->Java Folder (I took a guess that this was the correct way). After doing so, a dialog popped up with no way to even name the new folder, so I clicked "Finish" to see what would happen, and it just started doing a gradle build and whirled around for over 15 minutes. I canceled but I think it might have messed something up. There's no new folder.
What is the correct way to simply add a new directory to a package in Android Studio?
Right-click an existing package and choose New -> Package on Android Studio 3.2.1.
Here is a screenshot:
I was able to resolve this with trial-by-error. I just right-clicked on the Java folder, selected New->Java Class, then in the dialog, typed the package name that already exists and added an extra name for the namespace. This generated the folder/directory/package or whatever you want to call it. Android Studio is so convoluted. There's a New Folder, New Directory, New Package, that's not really apparent at what it does until you try it (and mess up your project). I tried New Folder and I have no idea what it did other than kicking off a build that lasted 15 minutes. Ugh.

Trying to convert projects that werent built using Gradle

I have tried to clone the following repository on GitHub using Android Studio, https://github.com/AlexKang/favr.git, but I have the error:
Before this I selected build project using Gradle and then accepted anything it wanted to install. I am having similar problems with, https://github.com/mb16/RemindEm.git, where I get that
Each time I selected "create project from existing sources" and then accepted everything it suggested.
What am I doing wrong?
The projects have eclipse .classpath files in the folder. I'm guessing you should be able to import the project into eclipse.
As an alternative to using Eclipse you might want to try using a feature of IntelliJ IDEA (Android Studio's parent project). File > New > Project from Existing Sources... Then select the .project file for the import

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).

AndroidStudio doesn't recognize R

I am teaching android app programming at a highschool. I found Eclipse to fragile so we are now trying out Android Studio. But a couple of students get that Android Studio with R. in red font, showing that it is not recognized.
This happened for example when the student copied the contents of my files.
It sometimes happens when you open a proyect from other sources. Just Synchronize it or press Ctrl-Alt-Y.
R.java file issues : 1) check the naming convention of images in drawable folder with size.
2) check the style of your application
In your case it may be missing style .. So upadate the style in value folder as per application .
The most common reason for this error is bad XML coding. For example using android:src="#drawable#drawable/picture" in ImageView will give you R error as it will not let R.Java file to build. Its hard to trace such errors as XML file will not show any error.
Also take a look if your resources are of good quality!
Hope it helps! Cheers
Build -> Clean Project
Tools -> Android -> Sync Project with Gradle Files
and all OK!
Try adding the following:
android.enableAapt2=false
to gradle.properties and Refresh:
You can also do the following: Clean Project and Sync Project with Gradle Files.
try importing your project :
To migrate existing Android projects, simply import them using Android Studio:
In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.
Click Import Non-Android Studio project.
Locate the project you exported from Eclipse, expand it, select the build.gradle file and click OK.
In the following dialog, leave Use gradle wrapper selected and click OK. (You do not need to specify the Gradle home.)
Android Studio properly updates the project structure and creates the appropriate Gradle build file.
First if the existing project was developed in eclipse you need to import the project and then check what are the error. If your students are coping codes from your project then after coping the codes they need to clean and sync the project. If still your problem not solved try this in android studio :-
File/invalidate caches/restart.
Hope it helps you :)
Especially, for regeneration of R.Java file.
If you have tried all these options:
Clean Project
Rebuild Project
Invalidate Caches / Restart
deleted .gradle folder
deleted .idea folder
deleted app/build/generated folder
checked your xml files
checked your drawables and strings
and still face problem then check your classpath dependency in your Project Gradle Scripts and if it's, this:
classpath 'com.android.tools.build:gradle:3.3.2'
then downgrade it to, this:
classpath 'com.android.tools.build:gradle:3.2.1'
clean and rebuild it will sync your project.
I had the same issue, and the lint gave me a hand...
If you're using lint, it can help too.
In gradle.build(Module:app) add the lintOptions sub-element in android element as shown below, then lint will fix it for you!!.
android {
lintOptions {
abortOnError false
}
}
I hope it helps!!

Resources