Could not find com.android.tools.build:gradle:7.5.1 - android-studio

So I was building out a test APK in Android Studio tonight that had to be signed. It failed and said my Gradle was out of date. So I upgraded my gradle from 7.3.3 to the newest 7.5.1
I changed the wrapper setting to distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
and then I changed my build.gradle dependency to classpath 'com.android.tools.build:gradle:7.5.1'
Note that after doing the changes, and restarting Android Studio, it did upgrade the version in the app directory.
Here's the error getting thrown below:
* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all files for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:7.5.1.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.5.1/gradle-7.5.1.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.5.1/gradle-7.5.1.pom
Required by:
project :
Note that this was a project from a client, and I did not write this originally. These dependencies were in place, but fairly recent, and the app would build fine with it using 7.3.3. However it wouldn't let me sign my app.
I suppose I could use some wisdom on both of these issues. What I'm going to do is go back to version 7.3.3, build the signed APK again, and copy that exact error to report back here with. It was a gradle version error.

For any any Flutter noobs like myself passing through, this error occured because the Android Tools Plugin version DOES NOT match the Gradle Version:
https://developer.android.com/studio/releases/gradle-plugin#groovy
They match up just vaguely enough in number, that you would think that my line com.android.tools.build:gradle:7.5.1. uses gradle 7.5.1, but instead, Android Tools for Gradle is actually a separate entity, and at 7.3.3 as of typing this reply.
So you CAN set your Gradle to the newest version somewhere else in your project, but it has to match the compatible Android Tools version, which is set here. Its silly and confusing at first, and can easily trip up newcomers. Hopefully the versions diverge enough, or the code syntax changes for some better clarity, but as of now, this is it.

Related

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"

Kotlin app build failed due to "Could not initialize class com.intellij.ide.highlighter.JavaFileType"

I've just updated Android Studio to 2.2 and now my Kotlin project won't build. The gradle synch works fine, but when attempting to build I'm immediately presented with an error that reads:
Error:Execution failed for task ':app:compileDebugKotlin'.
> Could not initialize class com.intellij.ide.highlighter.JavaFileType
I've checked that my Kotlin plugin is up to date. This error sounds like something to do with the IDE and highlighting Java code? Any help would be appreciated.
Open Tools | Kotlin | Configure Kotlin Plugin Updates in the main menu,
then choose Check for Updates. Be sure that yo're using Stable channel.
Close Android Studio, go to your project's directory, and delete build and app/build folders. Run Android Studio. Deleted folders would be recreated.
Hope it will help
In my case the kotlin plugin was not updated as #piotrek1543 said in other answer.
In addition to that the build.gradle had an old Kotlin version number 1.0.1-2 and the IntelliJ said in a warning on top of to switch to the current bundled version 1.0.4.
Now with the kotlin version like this the error is gone:
ext.kotlin_version = '1.0.4'

ARToolKit ARSimpleProj Error

When I open the ARSimpleProj in Android Studio and try to update the gradle version I get this message:
Failed to update the version of the Android Gradle plugin.
Please click 'OK' to perform a textual search and then update the build files manually.
After this, I'm getting this error:
Error:(58, 0) Gradle DSL method not found: 'android()'
Possible causes:
* The project 'ARSimpleProj' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0). Fix plugin version and sync project
* The project 'ARSimpleProj' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file
* The build file may be missing a Gradle plugin. Apply Gradle plugin.
I tried removing the android->buildToolsVersion and dependencies tag from the top-level, build.gradle file (as indicated in the AS_Migration document) but still it doesn't work.
I finally make it work. When opening the project on the Android Studio, I select "Remind me later" to the Android Gradle Plugin Update recommendation. After this, I could execute and install the application on my cell phone.
Make sure you are using JDK 1.7 in Project Structure. I had problems when using the JDK 1.8 with ARToolkit for Android.

Missing generated folders in Android Studio

I'm using Android Annotations in my project and I followed the instructions in this blog post http://www.jayway.com/2014/02/21/androidannotations-setup-in-android-studio/
Everything worked fine.
Today I updated Android Studio to latest version (build of 5th june). This requires an update of gradle build tools from 19.0.3 to 19.1.0. And i configured this in my build.gradle.
Annotaion processing still works. The generated files are located in build/source/apt. But this folder isn't visible any more in project explorer. And starting the build complains about the configuration.
But the project seems to run correctly.
This behavior is very annoying. Do I have to change anything in Android Studio? Has anyone a solution or is this just a bug in Android Studio?
The author of android-apt has already updated his plugin to support Gradle's new version, just change this line in your build.gradle
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.2+'
To
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.3'
The Android Studio Team changed the behavior of the IDE "for better IDE integration". Therefore the output directory of the apt-plugin v 1.2 will not be recognized as generated sources folder any more.
the plugin author knows about it and will provide a fix
https://bitbucket.org/hvisser/android-apt/issue/13/compatibility-with-011-android-plugin

Android studio preview 0.4.5: The project is using an unsupported version of the Android Gradle plug-in

I got the following error message when I was importing a project from github:
Failed to refresh Gradle project 'XXX'
The project is using an unsupported version of the Android Gradle plug-in.
Fix plug-in version and re-import project
This is not a duplicate of this because your get thee error message before
gradle/wrapper/gradle-wrapper.properties
is generated.
The problem appeared after updates. The updated Android Gradle plug-in did not support the outdated version of Gradle I had. But the error message is misleading, if you don't attempt different build options you won't see what the problem is.
After downloading a newer version of Gradle, Imported the project again, then:
Use local gradle distribution
Then Gradle home set to the folder where the new version of gradle was downloaded
that solved it
Edit: From Scott (below comments) : It's preferable to use the wrapper and to change the Gradle version in gradle-wrapper.properties instead of downloading and installing Gradle yourself. As for the Android-Gradle plugin, that's set in the dependencies.classpath block in your build file; see this
I get this gradle-errors in 4 Studio updates! My solution: I copy the Studio-folder, and if gralde throws an error, I copy the old version back. It's not a good way, but until google is not able to deliver an update without producing always the same errors (even if mentioned in many forums), I stay on 4.9 and wait for the first final release.

Resources