android studio settings.gradle duplicated, not recognized. - android

My android studio project is ostensibly error-free and (usually) builds just fine. But as seen in the following picture, there is a set of files that shows up twice in the file tree:
...once at the same level as the root project folder, and once within the project folder. NOTE: The actual files on the file system are ONLY located within the project folder.
In Android Studio, when I try to edit the settings.gradle within the project folder, it tells me "This folder does not belong to a Gradle project. Make sure it is registered in settings.gradle.", as shown here:
So, I try to instead edit the settings.gradle outside the project folder. In that case the Non-Project Files Access window comes up: this file is not part of my project. As shown here:
Who knew Android Studio was designed by Franz Kafka! But seriously, has anybody seen this? Or do you have any thoughts? Because of this issue, I can't add any new libs, so it is quite a show-stopper.
You may be interested to know that there in my git repo, there are existing versions of several auto-generated files including app.iml and project.iml and some other files from .idea/. When I git checkout back to the ones in the repo, the duplicate-file-trees briefly disappear. (I am still unable to access/edit settings.gradle, though).
If you want more information let me know. Thanks!

Related

What are the files that i can remove and the project will still be working

I have made an Android Studio project. I want to know what folders can i remove from the project. And i can still import it without problems.
As you can see in the screenshot, the project folder contains all those folders and files.
As example is i can remove the release folder.
Now, i want to know what other folders or files can i remove (.gradle, .idea .....)?
Or i mean what are the files that are not related to the project and just generated by the IDE.
In Android Studio, there are generally no useless files. The files that you delete, will be recreated by Android Studio.
You can delete .gradle folder(which contains settings and other files used by gradle to build the project).
Also, app/build, which will be again recreated by Android Studio. And if you want to know what folders/files are generated by IDE, then anything except
app/src
app/proguard-rules.pro
app/libs
app/build.gradle
Project level build.gradle
Anything except above files is generated by IDE.
In short, everything in app folder except app/build is user generated. I'd give a few simple tricks to import other people's project without getting boat-load of gradle errors, but StackOverflow forbids to make statements based on personal experience.

Gradle file push to github repository

I was pushing my Android application project to my github repository. I saw two folder .gradle and gradle were not pushed but another folder called gradle/wrapper instead got pushed. I am not sure where this gradle/wrapper folder came from and if this is a normal thing that happens when pushing an Android app.
Edit: I closely inspected a bit more and the gradle folder that I was talking about is the gradle/wrapper folder. It is just that I didn't expand that folder initially. The .gradle folder is still not showing up in my Github repository though.
The .gradle folder should not be committed and should be included as part of the gitignore
https://www.gitignore.io/api/android,androidstudio
This is the directory used by the wrapper on your local machine to store the downloaded Gradle dependencies (as compared to installing Gradle separately yourself and configuring the IDE to use that)
build.gradle and settings.gradle should be the least amount of required files for any Gradle project, the wrapper is optional but recommended to standardize the version of Gradle used to build the project
if you don't see a file that you have pushed via git, please check your .gitignore file.
Gradle/wrapper folder is generated upon building.

Is there a way to clone an IntelliJ IDEA gradle project?

I'm trying to move my IntelliJ IDEA (2017.3) Android project to another computer just copying the files and it does not work. I am aware of this and this, but in the case of Android project it does not work. All the xml files inside .idea store paths relative to the home ($USER_HOME$) instead of project home ($PROJECT_DIR$). Oddly, Maven projects seem to generate paths relative to the project home and those ones can be copied. But not with gradle projects.
Anyone knows how to solve this ?
EDIT: Bear in mind that I want to copy ALL project settings included running configurations. I want that someone opens the project and find exactly what I have. I know I can reimport the project, but then I'll loose some configuration.
Here's the files and folders that need to be excluded from the copy (assuming that your project has a module called app), preferably if you copy the entire project folder to some where else on the same computer and then deleting the unneeded one by one:
folders .idea, .gradle or any folder who's name starts with a .. They are usually found within the root folder of the project and within the module root folder.
build folder found in the project root folder and in module root folder.
any file who's extension is .iml, found in the project root folder and in module root folder.
local.properties found in project root folder.
The rest of the files and folders need to be kept. With the above excluded, the project can be re-imported in Android Studio properly with the correct configurations relative to your second PC.
On a side note, these are the typical exclusions added in .gitignore of an Android Project Git Repo.
Ok, I found the problem. It is related to how gradle resolve symlinks. This is the issue. Summarizing, if you open your project with a path that contains a symlink, absolute paths will be created in the configuration files and your project won't be portable.
I have reopened the project again using an absolute path and then all the configuration files use PROJECT_DIR instead of USER_HOME

Android Studio keeps adding additional files to GitHub

I'm using Android Studio 2.2.2, using the built in VCS tool. For some reason, Android Studio automatically adds a bunch of extra xml files and folders that I did not add nor edit.
More specifically, it's adding the following files when I don't want it to:
/_windows
IntelliLang.xml
debugger.xml
diff.xml
vcs.xml
web-browsers.xml
This makes making pull requests downright impossible as the master branch doesn't have these files, and none of my other group members seem to have this problem either.
Any help in removing / configuring Android Studio to stop this pesky bug?
--
edit: I am already using a gitignore file already. The weird thing is that my additional files are in the wrong folder too. Basically, my root folder, has a subfolder for my app. All the junk files are created in my root folder for some reason by Android Studio.
/root/
/_windows
IntelliLang.xml
debugger.xml
diff.xml
vcs.xml
web-browsers.xml
/my_android_app/
gitignore for my app
/files actually needed for my project
Turns out this feature is called "Settings Repository", and it's intended to save IDE settings automatically. I guess I might accidentally agree on some popup from IDEA which look like add files to the git repository, so this started working.
FIX: Open Preferences → Tools → Settings Repository → Delete. I also disabled Auto-Sync. Dunno where it's going to save if I delete everything, but I switch it off to be extra safe..
Use gitIgnore file.. i am currently using this .
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
.externalNativeBuild
/captures
check if the same works for you or not ..
if you want to know the details please check here
If the IDE you are using is adding files that it requires, but which you don't want to be included in your repository, then this is a good candidate for additions to your .gitingore file.
Are you currently using a .gitignore file?
More information can be found here:
https://git-scm.com/docs/gitignore
You basically add an entry for each file or folder you want to ignore, and as a result, git will no longer try to include these files in commits going forward.
There is a good resource here:
https://github.com/github/gitignore
For creating a default .gitignore file. You would pick the .gitignore template that closely matches the type of development that you are doing, and customize from there. For example, I always start with the default Visual Studio template.
Probably the best suggestion would be to use the template .gitignore file for Android Development which is located here:
https://github.com/github/gitignore/blob/master/Android.gitignore
NOTE: I would copy the contents of this linked file into this answer, however, these template .gitignore files are always changing, as new recommendations are being added. It is best to keep referring to the source file for the most up to date version.
It doesn't explicitly ignore the files that you have mentioned, but it could be that those files are created within a folder that is being ignored.

Android: Source path not being included

In my project I have added some folders that I want included in my project for source files. But no matter what I do, the source never gets recognized. I tried refreshing, clean up, restarting but nothing works. Here is the project's source folder:
I want the folders integration/android added. This is how it is showing up in Eclipse:
And here is what my build configuration looks like:
I could be wrong, but it looks like you have added them as a folder, but not actually added the folder to your project.
The folder should show up in your src folder in the solution explorer window under your other package.
Try creating the package name in your project, then move all the src files into it.
And when its in the src folder, in its correct package, you dont need to include any extra build paths.
(You can have multiple packages in a single application)
Importing someone elses project that is over 2 years old is almost always problematic. I found the easiest solution just to create a fresh project and add the files manually from the old project.

Categories

Resources