Android Studio: build.gradle (project) not visible in "Project" - android-studio

I am trying to rebuild an old (working) project in AndroidStudio. It builds Ok but strangely, the project's build.gradle is not visible in the AS Project tab.
Note that the module's build.gradle appears but not the project's build.gradle.
Both files ARE indeed there
Directory of C:\dev\AndroidProjects\apps\Passwords\app
11/09/2020 04:16 PM 767 build.gradle
1 File(s) 767 bytes
Directory of C:\dev\AndroidProjects\apps\Passwords
11/09/2020 03:13 PM 352 build.gradle
1 File(s) 352 bytes
The project otherwise builds just fine.
The projects build.gradle IS active: If I make changes to it outside AS using a text editor, the changes DO take effect.
What I've Tried:
Restart PC and AS
Cleaned/Rebuilt Project
Invalidate Caches & Restart
Searched SO for problem. Question 47406517 was similar but solution didn't work
Copy build.gradle from another known-good project.
Notes:
Android Studio: V3.6.3
PC: Win10-64
Project Name: "Passwords"
I'm at a loss for other things to try. Any suggestions?
(I guess as a work-around, I can always use an external text editor but that's annoying).

I found the answer in SO question #46230078. The solution was simple: Close AndroidStudio, delete the directory ".idea" from the project directory, restart AndroidStudio. This did it!

Related

Android Studio cannot open Android project with Kotlin DSL

I have converted one of our Android projects from the old Groovy settings.gradle and build.gradle files to the new Kotlin DSL, i. e. settings.gradle.kts and build.gradle.kts.
While "it works on my machine" - in particular: the original project I converted from Groovy to Kotlin works fine in its original directory - all my co-workers are unable to open the project when they clone the repo. Importantly, neither can I open the project myself (with the same AS installation on the same machine) when I clone the repo to some other directory. So, I suspect there is some additional detail missing in some configuration file but I cannot seem to figure out which...
Details:
When I just use File > Open... and then select the project folder, I only get the error message "The project 'xxx' is not a Gradle-based project"
When I instead go through Import Project (Gradle, Eclipse ADT, etc.) and then select Import project from external model and Android Gradle Android Studio will create an empty build.gradle file and fail with the error message "ERROR: Plugin with id 'com.android.library' not found." Deleting the build.gradle just goes back to the error message I described in the first bullet point.
I am aware of this Github issue, which seems to describe the same problem, but it's been very quiet and I thought someone around here must have figured out a solution to this...
Oh, command line builds work everywhere - this is purely an Android Studio problem.
UPDATE: When I copy the whole project to a new folder (instead of cloning the repository) I can open it without any problems. So, am I correct in assuming that there must be something inside the folder - but not in Git - that makes it work?
I was able to 'fix' it by deleting the .idea directory and reopening the project. The .idea directory is usually not committed in git but I guess copying the directory invalidates the directory structures in the files within the .idea directory.
The whole bug is easily reproducible when you click on File > Re-import Gradle project.
#Boni2k answer does not work for me.
I have to rename the root build.gradle.kts back to build.gradle, fix the syntax error, sync the project (which works fine immediately), and rename the file back to build.gradle.kts. Then the error is gone and I can sync the project successfully.
What I did to raise the error was that I moved the project to a different folder, and rename the project.

Android Studio ignores module

I have application module, 4 android lib modules, and 2 java modules. I'm trying to add one more android lib module, but AS ignores it.
New module is created and added to settings.gradle. AS does not add *.iml file to module folder, and .idea/gradle.xml and ./idea/modules.xml files don't contain records about new module. I tried to generate *.iml file by myself, and added records to .idea/ files. It starts working, but then i got message
The modules below are not backed by Gradle anymore. Check those to be
removed from the ide project too
, and *.iml file was removed.
AS 2.2.3, gradle 2.14.1
UPD 1.
The problem was in unexpected place. I tried this solution, because it was very similiar to my problem, tried to delete module and add it again (with new name). But nothing helped. After opening Gradle tab (right top corner), I found that new module was highlighted with dark grey color, right-clicked on it, and saw that "Ignore Gradle project" was checked by default.
I unchecked this item, but after next gradle sync I got above message, and this item was checked again automatically. Also in event log
Unsupported Modules Detected: Compilation is not supported for following modules: modulename. Unfortunately you can't have non-Gradle Java modules and Android-Gradle modules in one project.
UPD 2.
Seems like https://code.google.com/p/android/issues/detail?id=77983 and https://code.google.com/p/android/issues/detail?id=230550
The solution that helped me:
Close AS
Remove all *.iml files
Remove .idea dir
Remove .gradle dir
Rename project
Open project with AS
android {
...
buildTypes {
...
dexOptions {
preDexLibraries true
}
}
}

I don't have gradle.build, why?

I am using Android-Studio to build my app. In order to add libraries, I need to edit build.gradle file but I don't see it anywhere. Even if I changed files-view from android to project and vice-versa .
Why don't I see/have build.gradle ?
Check in your git repository if it contains the build.gradle files.
If not, you can just add manually to your project.
You should have something like this:
root
|--app
|----build.gradle
|--build.gradle
|--settings.gradle
You can also create a new blank project and copy the build.gradle files into your existing project (of course in the app/build.gradle file you have to change the values and the dependencies).
With huge help from #JuLes (commentting on my question) I figure out how to solve it. Here is what I did:
I totally removed Android-Studio following this guidance, then ...
I installed Gradle from this link, then ...
I re-installed Android-Studio following this link:
I am gussing the main problem was that I didn't installed Gradle manually and hence Android-Studio was using some sort of Gradle-Wrapper to allow the application to run.
Now, finally I can edit build.gradle.
BIG THANKS TO: JuLie

Android studio configuration with Gradle

I am having an issue to configure Android studio after importing gradle project. My project structures is as following:
Root Project
|_.config
|_settings.gradle
|_build.gradle
|_app_module
|_lib1_module
|_lib2_module
|_ etc.
Please note, that for several reasons I am not able to move settings.gradle and build.gradle files to project root . Also, the files mentioned above are configured correctly, so there is no problem with the build.
So the problem is that once the project in imported, the all gradle related file and folders are are generated inside .config folder, which doesn't disturd me.
Also the .idea folder and all relevant sub-folders are generated in this very folder.
So this is the problem. For some reason, the studio doesn't recognize all sub-modules are under source control. I.e. it's vcs.xml is empty and contains only project root. Actually the problem is resolved by adding the modules via settings--> subversion menu, but I'd really like out-of-the-box solution. I've tried to put .idea folder under source-control - doesn't help. Upon project creation, the vcs.xml is re-written and empty again.
So, the main question is:
Is there a possibility to
Force studio to generate .idea folder and the root project folder without changing location of .gradle files OR
Make studio NOT to re-write it's settings files upon project import (e.g. keep predefined vcs.xml)
PS. I'm aware the putting all generated files (including gradle folder, gradlew, etc.) will probably solve the issue, but I wouldn't like to go so far.
Thank all in advance
It should be a comment, but it is too long.
Android Studio works with a project.
Inside this project you can configure more modules but it need this structure:
Root Project
|_.idea
|_.gradle
|_.config
|_build.gradle
|_app_module
|_build.gradle
|_lib1_module
|_build.gradle
|_lib2_module
|_build.gradle
|_ etc.
|_settings.gradle
|_build.gradle
Inside the settings.gradle you have to define all modules:
include ':config' , ':app_module' , ':lib1_module', ':lib2_module'
Under the root folder, Android Studio when builds the project with gradle, makes same folders, like the .idea.
I read that your are not able to move the settings.gradle file.
In this case Android Studio recognizes the config folder as the root of a project and build the .idea folder inside.
|_.config (root)
|_.idea
|_.gradle
|_build.gradle
|_settings.gradle
|_myModule
Force studio to generate .idea folder and the root project folder without changing location of .gradle files OR
As I know you can't avoid this.
Also ,
Make studio NOT to re-write it's settings files upon project import
The .idea, the .gradle folder, the .iml files are built locally by the IDE when the project is built. The IDE re-writes these resources, also these files contain local paths and usually they are not commited in VCS for this reason.

Renaming root directory for Android Studio project breaks code

In Android Studio, I wanted to rename the root directory. There was no way to do this within Android Studio, so I exited AS and renamed the folder and then opened the project again. But when I went to run the app, it indicates:
AndroidManifest.xm does not exist or has incorrect root tag
The manifest does exist, but apparently something breaks by renaming the file. I tried invalidating the cache but that didn't help.
Closing the project and then removing it from the list and then reimporting the project as a non-Android project corrected the problem. Still, this seems to be a hack. It should be possible to rename the root folder without having to take this approach.

Resources