Error when adding new Activities to the Android Studio Project - android-studio

I am carrying out a project on Android Studio, but when I try to add a new empty activity to an open project, after the creation when I launch the app on the emulator it closes by itself giving an error message that disappears if I delete the activity created.
I tried to change the name of the activity, or make it some other type and not empty, but nothing seems to work.

Frist you (Synk project and it's not work -go ahead).
01 - Go to the file - invalidate cache and restart.
02 - Clean project and rebuild project.
03 - Update the latest version android studio.

Related

Views in Layout Not Getting Created Properly

Recently, I came across an issue with my layout files. Whenever I click enter to add a view in an .xml file like so:
And then when I click enter:
As you can see it did not generate the attributes like 'layout_width' and 'layout_height' etc.
This problem only happened after connecting my Git account to Android Studio.
This issue is only in the 'Text' tab of the layout file, so the 'design' tab works fine
I have 'Invalidated Caches & Restarted' but that didn't work.
EDIT: I opened up another project and added a view throughout the text tab and it worked - the working project is not connected to Git.
Thanks.
Try this steps below
1 Sync your project (If it's doesn't work) try this below
2 Invalidated Caches & Restarted
3 Restart Your System or Android Studio
What's your android version?. maybe that's a bug in that android studio version please try updating studio.
The problem was in my gradle.build (Module:app). My target SDK version was set to 26 which it gave a warning about compatibility issues. So after changing it to 28 and syncing my project the issue was solved.

Android studio 3.1.2 create new project gradle sync failed

I use this Android studio import existing project all the time and everything goes well. Today ,I first create new project which support c++ ,and after every step to the final, I got the error.Picture like below:
I don't know what's wrong,because when I importing existing project ,this error haven't shown.
And the project structure panel like below:
When I check connection in "Http Proxy" ,it returns successful :
Delete the corrupt files
When Gradle files are not completely downloaded or corrupted by some other reason,we have to redownload the files. The easy way is to delete the old files in.
C:\Users\username.gradle\wrapper\dists
Then rebuild the project.
Then Android Studio will automatically download the new files from the system.

Why does Android Studio show errors in my code but app still runs

I have recently upgraded my laptop and re-installed Android Studio to the latest version and imported my app. The problem I am facing now is that when Android Studio start it finishes the gradle build etc, but shows errors all over my code. I can still debug the app on my phone and all is working.
How can I get this resolved?
Thanks
I finally resolved this when it happened to me. The steps I did to resolve my problem
Build -> clean
File -> invalidate caches / restart
Delete .idea folder, close and reopen project
Normally one of the first two first steps is enough but today I actually had to delete the entire .idea folder and reopen the project to get rid of the "errors" (only IDE errors, project still ran for me).
If Methods named (A) (B) (C) (D), do not help you, then the following 4 steps are AGNI ASTRA.
Step 1 : Go To App Folder In Android Studio.
Step 2 : Locate Build Folder.
Step 3 : Delete Build Folder.
Step 4 : Sync File.
I will advise to use AGNI ASTRA, after trying, Methods named (A) (B) (C) (D) .
The Methods Are :
Method (A)
CLICK ON FILE IN ANDROID STUDIO
CLICK ON SYNC PROJECT WITH GRADLE FILES
Method (B)
CLICK ON FILE IN ANDROID STUDIO
CLICK ON INVALIDATE CACHES
Method (C)
CLICK ON BUILD IN ANDROID STUDIO
CLICK ON CLEAN PROJECT
Method (D)
CLICK ON BUILD IN ANDROID STUDIO
CLICK ON REBUILD PROJECT
In my case (Windows), I have faced the same issue with 2 version of Android Studio,
1. Android Studio Arctic Fox | 2020.3.1 Patch 4 (My previous/normal IDE used)
2. Android Studio Dolphin | 2021.3.1 Patch 1 (My updated/current IDE used)
First, I thought this problem can be solve by Build>Clean Project, or Build>Rebuild Project, or File>Invalidate Caches..., but sadly won't work. So, I decided to update my IDE Arctic Fox to Dolphin.
Download from official site, installed with different folder (C:\Program Files\Android\Android Studio1), but project folder still same. During opening project, it won't run unless change Java version to Java 11 (File>Settings>Build, Exectuion, Deployment>Build Tools>Gradle>Gradle JDK>11 version).
Try opening several projects, however the IDE sometime still show the redline code, but the app can still debug/run as usual. Latest method I used, File>Invalidate Caches... And IDE haven't show any redline code.
*Remark: Don't know how long the latest method I used will work.

Android studio suspended on indexing

When i run android studio it freeze on indexing and show me message:
indexing suspended (context: Gradle Sync)
it take more then 42 min and still show me this message i can't stop process and almost every thing is disable
Solutions I've tried
1- enable offline mode
2- select local gradle
3- invalidate caches/ Restart
but no one of this is solve my problem .
I've solved closing project (Menu File -> Close Project) and reopening it selecting his build.gradle.
Hope that helps
In my case, syncing the project with file system helped. But the project uses react-native and many gradle modules are located in the node_modules folder which could be updated by yarn/npm.

Android Studio keeps selecting an unusable API by default

I'm running Android Studio 2.1.2 on Ubuntu 14.04. When installing I chose to download API 24 without thinking and now it gets selected every time I start a new project. Because umake provided Android Studio with JDK 1.7, the Design View always shows an error 'Android N requires JDK 8'.
I can get past this by unchecking 'Automatically Pick Best' and choosing a lower API, but now the Design View is blank. I have to edit the xml and remove the following line;
app:layout_behavior="#string/appbar_scrolling_view_Behavior"
Now I can finally see the Activity I'm building in the Design View.
What I'm looking for is a way to stop Android Studio from always having 'Automatically Pick Best' checked and API 24 selected every time i start a new project. Is this possible? It's a pain to have to go through all those steps each time.
Android Studio installs API 24 by default there is no way around this when you first install (at least that's the way it is with my ubuntu distro - you cannot uncheck API 24 even when you choose to do custom installation settings). sudo umake android
After the install, and before I created a new project I clicked the cog to open 'Configure' which allowed me to open the SDK Manager. In here I was able to install API 23 Marshmallow and delete API 24 Android N.
Now when I create a new project API 23 is selected and the Design View works fine.

Resources