Android Studio and gradle home issue - Ubuntu - android-studio

I'm using Ubuntu 18.04
Android Studio Version 3.6.3
I think I have two installed Gradle locations If I'm not wrong
One of them installed using sdkman, when I use terminal to locate the Gradle
which gradle
Also, I've found (I don't remember if I installed Gradle in another way instead of sdkman) in my home directory, this is the one which Android Studio is using (I think) and make issues when opening a project
I think I need to use sdkman as it's easier to update the Gradle version etc.
So, my question is should I remove the gradle from: "/home/khaledomara/.gradle". If so, what is the best method to do that and what path should I put in the settings of Android studio?
Should it be "/home/khaledomara/.sdkman/candidates/gradle/current/bin/gradle"?

You only have one Gradle installed - the ~/.gradle directory is where a running Gradle process stores data and it can be safely deleted (assuming you don't have a gradle.properties or similar with any settings you want to save - but there is no need to delete it).
It is not a bad idea to do a gradle init in your Android Studio project - this will give your project its own Gradle that you can upgrade at your leisure without having to rely on the globally installed Gradle.

Related

Is there a way to prevent Android Studio or Intellij IDEA from downloading older version of gradle over and over?

I have the latest version of gradle (7.4) installed on my machine, every time I open a new project on Android Studio or Intellij to write Kotlin codes, it starts downloading old versions of gradle, is there a way to stop it or to run AS/IDEA offline ?
You can modify the distributionUrl property in the gradle-wrapper.properties file to point to a local file. So download a single copy of the necessary Gradle version from https://services.gradle.org/distributions/. Then before you open a project in the IDE, edit its gradle-wrapper.properties file to point to this local copy. It will copy the local file instead of downloading it.
For example, change
distributionUrl=“http\://services.gradle.org/distributions/gradle-3.3-bin.zip”
to
distributionUrl=file\:///C:/gradle-7.4-all.zip
I found a post about doing this here.

Android Studio “cannot resolve symbol R” but project compiles and runs

Android Studio displays in all java files in red : “cannot resolve symbol R” but the project compiles and runs.
I have tried every solution here:
Android Studio "cannot resolve symbol" but project compiles and works, but with no luck.
I tried to :
invalidate caches and restart android studio
delete .gradle and .idea folders
clean and rebuild the project
install a new version of android studio
mess up with gradle file then undo changes and sync project
One thing that I want to try, but I don't know how to achieve, is to reopen the project from scratch as I was opening it for the first time, but I don't know how to do this.
I also tried answers from here:
Android Studio says "cannot resolve symbol" but project compiles,
but again with no luck.
Android studio version = 3.2.1
dependency versions in gradle project file:
classpath 'com.android.tools.build:gradle:3.4.0-alpha01'
classpath 'com.google.gms:google-services:4.0.0'
For some reason that i do not understand ,
this combination of build versions made the issue :
grade version = 4.10.1
classpath 'com.android.tools.build:gradle:3.4.0-alpha01'
when i switched to these build versions :
grade version = 4.6
classpath 'com.android.tools.build:gradle:3.2.1'
The issue was solved !
File -> Close project
Open an existing Android Studio Project
Open you project
Hope it will work.
sometimes, R file is not generated because of package name on android manifest is not match with package module that you have.
Is any wrong syntax or spelling in your xml?
Check your layout or any xml file.
Android Studio seems to have a caching issue with R.java occasionally. I rarely have a problem with this, but when I do, I actually open R.java (double press shift and type "R.java") or navigate to R.java under "app/build/generated/source" directory, opening the file and checking if the relevant XML id has been created. If it has, it forces Android Studio to now recognise the id's that are not being resolved. It's quick to try, and doesn't require clean and rebuild.
From your programs menu, open android studio. instead of opening your project from the recent files, select to open a project from your computer and then locate the path to your project. When all else fails, sometimes this works.
Also, try commenting out the support libraries from your gradle implementation, sync your project, and after sync fails comment them back in and sync again. (not sure if that's what you tried already when you said you messed with the gradle file)
In my case,
I am using
- Android Studio version 3.3.1 at home
- Android Studio version 3.2.1 at office
When i pulled projects to my office computer that are firstly created at my home computer ,
Android Studio can not resolved R file but runs application with no error. Because projects gradle and Android Studio version are incompatible.
Only thing that you sholud do, change the gradle version in project level gradle file
classpath 'com.android.tools.build:gradle:3.3.1'
to
classpath 'com.android.tools.build:gradle:3.2.1'
I was facing same issue,
first thought the issue might because of some xml file or naming of drawable resources incorrectly. After analysing, this case wasn't applicable to me.
So
Updating Android studio from older version 3.2 to newer version 3.3.2 along with new build tool version from SDK manager resolved this issue
for me.
I've tried invalidate cache and Restart AS with clean rebuild all the options but didn't work for me.
It says cannot resolve symbol, but it can run.
In my case, I just reload the needed *.jar files to the libs folder.
File >> invalidate caches/restart
Rebuild Project
Sync
Run
Works for me!
It looks like the library did not load my "imports" properly the first time.
That's why the import methods cannot be seen in my main_activity.xml.
This happened to me when I was going back and forth between different SDK versions.
Apparently SDK manager copied all the source files but it didn't finish cleanly. As a result I could compile and run my project just fine but IDE didn't recognize the SDK and reported all java symbols unresolved.
None of the above and other solutions in SO didn't work for me, but just uninstalling/reinstalling the specific SDK version did a job.
If you renamed your package (inside java folder), make sure you change your Manifest package name to the same
The only thing that worked for me was,
replacing,
import package_name.R
with
import package_name.*
simply go to project settings : settings.gradel and change the rootProject.name to your current name
rootProject.name = "write the project name here"

Finish can only be called once : Android

Recently updated Build: 2.3.1, AI-162.3871768, 20170401,
AI-162.3871768, JRE 1.8.0_112-release-b06x64 JetBrains s.r.o, OS Mac OS X(x86_64) v10.11.6 unknown, screens 1440x900; Retina
Switching back to Android 2.2.2 did not help either. Successfully able to build from command Line though(MacOX Terminal)
Delete your $HOME/.gradle directory (or on Windows, %HOME%\.gradle folder). The next execution of gradle will rebuild this. (It will require some downloads, so make sure you have an internet connection).
You can try just deleting $HOME/.gradle/caches, but this will not solve the problem in all cases.
I have similar issue on 2.3.1
I tried using the Android 2.4 Preview 4 but that did not help. I am able to build from command line too.
Android-Studio-2.3.1-Gradle-Sync
It happens when Android Studio creates two instances of gradle. I tried clearing the gradle cache or even deleting the .gradle but did not help. All this problem started when I deleted my old project repo and re-pulled it and imported to my Android Studio.
Best is to delete all your gradle instance from your home directly before your re-import your project Android Studio.
Android Studio started behaving like this after I tried building with the command line(osx) using ./gradlew
What helps is running the studio with sudo:
sudo /Applications/Android\ Studio.app/Contents/MacOS/studio
I wonder if theres a fix to this problem that allows the studio to be started normally as well.

Android Studio can't open project

I've recently get update notification of android studio 2.3, after the update it's not opening any project and throwing error:
[plugin: com.darkklord.gradle.metric.core]
after downgrading and reinstalling i still have this issue, can anyone please help me on this topic ?
Download latest plugin from here: https://plugins.jetbrains.com/plugin/9197-android-gradle-metrics--checkstyle
Install Plugin manually from disk.
Restart Android Studio (The error will still occur)
Remove plugin in IDE.
Restart
You might also uninstall the refrenzed plugins Checkstyle and PMD
You need to change your dependency
classpath 'com.android.tools.build:gradle:3.1.0'
Sometimes you need to change name of project manually(look at AndroidStudioProjects folder) that you opened lastly.
After changing name, android studio will show all projects,
open one of them,
in file menu,
click open button,
then open your desire project (or change its name to its previous name)
change build:gradle plugin to:
classpath 'com.android.tools.build:gradle:3.3.2'
(in app gradle file)
I made sure that my Gradle version was compatible with my android gradle plug in. In my case I was using Gradle 6.0.1 and when I changed my android gradle plug in to version 3.5.3 the problem went away.
Project Structure----->> Project ------>> Android Gradle plug in version 3.5.3.
[https://docs.gradle.org/6.0.1/release-notes.html
[Java 14 and later versions are not yet supported.
Compatibility Notes
A Java version between 8 and 13 is required to execute Gradle.
Java 6 and 7 can still be used for compilation and forked test execution. Just like Gradle 5.x, any supported version of Java can be used for compile or test.
This version of Gradle is tested with
-------->>>>>>>>Android Gradle Plugin 3.4, 3.5 and 3.6
Kotlin 1.3.21 through 1.3.50
Other versions may or may not work.]]]]
I hope this helps

How to import a android project into android studio?

I want to study the source code of android-smspopup .But when I download the source code and import this into android studio, the android studio pop up a dialog with a title"Import Gradle Project" and a blank to fill named Gradle home. Does any one know why this happens? And what to fill in Gradle home?
The source code doesn't include the Gradle wrapper files, which it should; the Gradle wrapper is responsible for automatically downloading the correct version of Gradle so you don't have to go through this trouble. I would recommend that you copy the Gradle wrapper over from another project into this source tree and use it. In another project that you've created with the New Project wizard, copy these files to the root directory of the project:
gradlew
gradlew.bat
gradle (directory)
When you open up the project in Android Studio it's likely to complain about the version of the Android Gradle plugin and offer to fix it for you; let it do that. If you're running the latest version of Android Studio (0.4.6 as of this writing), it's fairly smart about getting the versions of Gradle and the plug-in right, but in older versions it could get a little confused and have to ask you multiple times.
NOTE: instead of copying the wrapper files over, you can instead install a compatible version of Gradle and put the installation directory in when it asks for Gradle home. That will work, but be aware that Android Studio is very finicky about what version of Gradle it's compatible with; usually it requires a specific version that isn't forward-compatible, so for example, if it wants 1.10, 1.11 won't work. As you upgrade Android Studio you'll have to upgrade Gradle as well and it will be a bit of a drag; if you use the wrapper it's easier to make that change.
By the time Android Studio hits 1.0, it will sort out the version issues with Gradle, and it won't be so picky about version numbers, but in the short term, it's a limitation.

Resources