How to restore build.gradle and .Gradle folder - android-studio

When I was trying to solve an issue with Android Studio I accidentally deleted .Gradle folder at the top of the project and build.gradle from within the app. I will post a screen shot of my project in Android Studio. The build tab also produces "make module my app project name" and "deploy module to app engine". The usual clean project, rebuild.... are not there.
How can I restore them?

If your are not using a VCS:
try use the local history to recovery the build.gradle file in your root folder (right click on the root folder)
If it fails. you can create a new project and copy the build.gradle. Usually this file contains generic info (like android gradle pluging and the repos to be used in the modules)
the .gradle folder is not a problem. Gradle wrapper will recreate this file

I copied both from a different project and pasted them in my project. That didn't solve the problem and I imported the project File->new->import project but that only created a duplicate within my project. I closed the project and deleted it from the list of project in Android studio. Then I created a project by importing it from Android Studio Projects folder. It took forever stuck in the gradle build and I have to restart AS manually. Now I have all my files and the project is compiling as it should.

You just need to reimport your project it will by default create the new gradle folder

Related

Android Studio "Scanning For Files To Index"

I am trying to achieve the following project structure in Android Studio
project/
projectA/
projectB/
Where projectA is an "app" module created by Android Studio which I have renamed, and projectB is a Kotlin project I wish to depend on in the app. I can get the projects to appear correctly as modules in my project however no matter what I try, as soon as I add projectB to my Android Studio project, it seems to get stuck in a loop "searching for files to index". When I look at the files it is always just looping through the same 2-3 files. They are always META-INF files but not always the same ones.
How do I successfully add a module to an Android Studio Project without hitting this error or how can I set out my project from the start to achieve this structure?
Thanks.
The problem seemed to be that I had a gradle/ directory under my project/projectB directory that was there because the project was originally created as a standalone project by IntelliJ. Deleting that fixed the issue.

Why is Android studio not automatically cleaning my project

I recently renamed my project by closing Android Studio, renaming the root project directory then opening A.S again.
A.S names the project using the new directory name, then I open it. A new .iml file is created with the new name. I deleted the old one and cleaned the project.
Everything went fine but now when I build it just deploys the app instead of cleaning it first. I have to manually clean it and it's annoying.
Is there a setting that might have gotten messed up?
Platform Details: Android Studio 3.0.1, Windows 10
Ok. So, apparently if you add flavors to your project then you have to manually clean the project otherwise when you build, Android Studio will launch the previous APK.

unable to import library project in android studio

I have modified library project of finestwebview here
I tried to add this library project in to my android studio's project but I got several errors saying configuration with name 'default' not found android studio.need help. I wasted my 1 whole days trying this but unable to add.
what I tried is
I copied the library project into the libs folder of my root project,and added 'include:libs:finestwebview' in setting.gradle file.
Also going to
file->project structure->app->dependencies
added the module and sync the project but cannot achieve the desired outcome.
You are including a project, so for that you should add it as a module, and say compile project in your app's gradle dependencies to use it in your app module.
go to
File->New->Import module and add your library project folder
you will have to name your library project there
then you need to say
`compile project(':yourlibraryProjectname')`
in your gradle dependency

Why does Android Studio download gradle each time a new gradle project is imported?

Why does Android Studio download gradle every time I try to import a new project?
Initially, I imported one gradle project for which Gradle 2.1 was auto-downloaded. Subsequently, for a second project import, it downloaded Gradle 1.10. Now again while importing a third project, it has downloaded Gradle 2.2.1.
What is happening?
Projects can declare which Gradle they require to run (see gradle.properties file in gradle directory in the root of the project).
Android Studio uses this information to download and run the right version (it's actually not Android Studio, it's the Gradle Wrapper running inside it). And it's a good thing.
What you can do?
Wait. Once you have the version downloaded in ~/.gradle directory, it will be used for any project declaring the same version. It's one-time cache.
Disable the usage of the wrapper when you import the project. I really recommend against it! You project might not build because of that.
Same happens to me.
The answer of JBaruch is allright.
1.- When you're opening a file on the option Gradle project: select the build.gradle that cames on your project
2.- Select the option "Use local grade distribution" and in Gradle home option; go and select in C:\Program Files\Android\Android Studio\gradle\gradle-2.2.1
It will not ask you to download it again (except if needs other version)
...well, here's what I normally do to speed up the initial build on opening a project (target):
1- open a project you already have working and open the file gradle-wrapper.properties a copy the following line (your project most likely will have a different version):
distributionUrl=https://services.gradle.org/distributions/gradle-6.7-bin.zip
2- paste it and replace the code on the same file on the target project
3- open the file build.gradle (project code) from a project you already have working and copy the following classpath, (again, your project most likely will have a different version)
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0-alpha15'
// ...
}
4- paste it on the same file on the target project
This way you can speed up the build of the target project while avoiding the usual 100Mb or so Gradle download.
Basically it downloads the Gradle build files for your current project according to its version and this whole work is done by your gradle wrapper which actually looks towards the basic requirement for your project and downloads the files according to that so whenever you are going to use any another projects of same version or with same requirements then it will not download any additional file at that time.Its just a one time shot!!!!
It usually downloads the Gradle updated version & and external dependencies for each project rather than fetching it from the cache.
So follow these steps:-
Go to settings
Search for Gradle
Untick Download External Dependencies Option.

Android Studio project files not showing up

I have a library project in Android Studio that has been working fine, but today I went to work on it and all of the files are missing except for a few git files. The folders/files are there when I look in the project's folder on my hard drive, they just aren't displaying in Android Studio. Here is a screenshot:
I tried reinstalling and updating Android Studio, but it didn't work. Any ideas as to what is going on here? How can I fix it?
Try Import Project... and navigate to your project. Select build.gradle file.
Be sure to wait for a while, so that android studios can load all your stuff. Sometimes a restart will help, but since you reinstalled it, that shouldn't be the problem.
Go to File > Project Structure > Project Settings > Modules.
Click on the green colored + and add new module. select Application module and set the content root to your project module.
Click next and then finish.
This should do the trick and the complete project structure will appear. It worked for me.
I had to Sync Project with Gradle Files in Android Studio to get my files back after they disappeared in Android Studio's Project window.
Go to
File > Project Structure> click on + > then set it to android
Go to:
File > Sync Project with Gradle files.
It will show up all the files linked with the gradle.
You can reset the IDE configurations by removing the configurations folder manually.
First close your project in Android Studio
In the project's root folder run:
rm -r .idea
Open your project again.
In my case i have a slash in the subproject
settings.gradle
As an example, this did not work:
include ":somedir/library"
But changing it to this fixed it:
include ":somedir-library"
project(":somedir-library").projectDir = new File(settingsDir, "somedir/library")
In my case, it was because of the NDK version
In my case only File -> Invalidate Caches / Restart... works.

Resources