Android Studio plugin Gradle errors - android-studio

So i just wanted to creat a hello world app and this happened
Build file 'C:\Users\Yuness\AndroidStudioProjects\MyApplication2\build.gradle' line: 3
Plugin [id: 'com.android.application', version: '7.1.2', apply: false] was not found in any of the following sources:
Try: Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Exception is: org.gradle.api.plugins.UnknownPluginException: Plugin [id: 'com.android.application', version: '7.1.2', apply: false] was not found in any of the following sources:
Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
Plugin Repositories (could not resolve plugin artifact 'com.android.application:com.android.application.gradle.plugin:7.1.2') Searched in the following repositories: Gradle Central Plugin Repository Google MavenRepo

if your project is open in android studio, follow these simple steps as seen in the below screenshot
click on the project tab at the top - left of your android studio app.
Down your project structure, click on Gradle Scripts. In the drop down, you will see two build.gradle files
Open the build.gradle with (Module:Application_Name.app)
Inside the build.gradle file opened, make sure the it contains the following at the top.
plugins { id 'com.android.application'}
Then build your application.
if you still receive this error, then open the other build.gradle file with (Project:Application_Name)
check for plugin section and paste this below
plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
}
Build your application.
if you dont find any of these file, it means you need to create the build.gradle. but as a beginner, is better to delete the project and create it again.
please make sure your internet is active to sync your gradle
gradle

Can you try this
Go to 'File'
Click on 'Sync Project with Gradle files'
Make sure you have internet connected

Related

Sync failed and "Unable to find Gradle tasks to build" after upgrading from Android Studio 2021.3.1 to 2022.1.1

I found several SO posts describing similar issues, but they are outdated and none were found to be helpful in regard to my upgrade to the latest version of Android Studio.
After upgrading my Android Studio from version 2021.3.1 to version 2022.1.1, my attempt to File > Sync Project with Gradle Files results in Sync failed (within less than 200ms).
When I try to Build > Rebuild Project, I get the following error:
Unable to find Gradle tasks to build: [:].
Build mode: REBUILD.
Tests: None.
There is no :app in any of my settings.gradle files.
I did File > Invalidate Caches... (all of them) and restarted AS, but this didn't help.
I also deleted all build folders, but this didn't help.
Any idea how to solve this?
Right-clicking the Sync failed to Reload Gradle Project results in the same failure but it opens now a bar on top of the editor window with the Show Log in Explorer link. When I click it, I indeed find idea.log in C:\Users\WebViewer\AppData\Local\Google\AndroidStudio2022.1\log. I am inspecting it now...
Update:
The first thing I noticed in idea.log is the following exception:
org.gradle.tooling.GradleConnectionException: Could not run phased build action using connection to Gradle distribution 'https://services.gradle.org/distributions/gradle-7.4-bin.zip'.
...
Caused by: org.gradle.internal.jvm.JavaHomeException: The supplied javaHome seems to be invalid. I cannot find the java executable. Tried location: C:\Program Files\Android\Android Studio\jre\bin\java.exe
Thanks to this SO tip, I did mklink /D "jre" "jbr" which all of a sudden revived Android Studio and started to download lots of Gradle related packages.
I still have "Gradle Sync issues" but at least Android Studio prompts me now how to solve them:
but... according to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, why is Android Studio asking for a minimum of 7.5?
Problem solved.
For the benefit of all, I am posting here a summary of what I did to solve it:
When a laconic "Sync failed" is all Android Studio provides, C:\Users\<yourname>\AppData\Local\Google\AndroidStudio2022.1\log\idea.log is key to finding clues to the mystery.
In my case, it was failure to find and run the embedded Java version. So, I did mklink /D "jre" "jbr" which miraculously revived the build process (see https://github.com/flutter/flutter/issues/106674#issuecomment-1381685888).
Under File > Settings > Build Tools > Gradle, this is the Java version that works for me:
I then tried to follow Sync's output to use Gradle 7.5.0. It could not be found on any of the repositories in my top level build.gradle and resulted in chasing my tail... According to https://developer.android.com/reference/tools/gradle-api Gradle's current release is 7.4.0, so I reverted to using it (why didn't it work the first time, I don't know) and here is my working top level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.0'
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1")
classpath("org.mockito:mockito-inline:4.11.0")
}
}
allprojects {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
}

Running first Kotlin example in Android Studio with failure

I am new to Android development and created my first Android Studio project (Empty Activity type).
However when I am presented with the following error message:
5:09 PM Gradle sync failed: Plugin [id: 'org.jetbrains.kotlin.android', version: '1.6.21', apply: false] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (could not resolve plugin artifact 'org.jetbrains.kotlin.android:org.jetbrains.kotlin.android.gradle.plugin:1.6.21')
Searched in the following repositories:
Gradle Central Plugin Repository
Google
MavenRepo (9 s 311 ms)
I am running Windows 10 and have no clue how to resolve this. Can anybody provide some input?
thanks

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.

Android Studio: Module won't show up in "Edit Configuration"

I've imported a project to Android Studio with several subprojects.
I want to run a subproject.
I successfully made this subproject's build.gradle as a module.
In order to run it, I went to Run > edit configurations > + > Android Application.
Problem: When I try to select a module, none show up in the drop down list.
Why is this?
EDIT: it shows up as a module under Groovy but not showing under Android Application. How do I get it to show up under Android Application?
Make sure your build.gradle is
apply plugin: 'com.android.application'
not
apply plugin: 'com.android.library'
After you have changed, please sync your gradle again.
I had similar issue when I selected parent directory of my project, I resolved by Close Project -> Delete Project from Android Studio -> Import Project by selecting right build.gradle file.
Make sure you select right build.gradle file while import.
I fixed this by adding facets in Module settings. They were missing.
right click on project > open Module settings > Facets > Add facets ( "+" sign at the top ) > Android.
After adding facets you will have modules.
UPDATE:
For latest version of gradle, Facets have been removed, you can directly add modules now.
right click on project > open Module settings > Add module ( "+" sign at the top ) > Phone and Tablet Application (Now you can create a new module and configure it).
In Android Studio 3.1.2 I have faced the same issue. I resolved this issue by click on "File->Sync Project with Gradle Files".This works for me. :)
resolved this issue by clicking on "File->Sync Project with Gradle Files"
New project. Fixed this issue by clicking on "File->Sync Project with Gradle Files"
I have tried all the options with no luck. So I have ended up with my working solution. Just make following steps:
Close android studio if open.
Copy module(project) in your current workspace.
Start android studio.
You will see added module in project structure.
Open settings.gradle of your project and include ':YOUR_MODULE_NAME'.
Sync gradle and you can see module is successfully added to your project.
Try,
Files > Sync Project with Gradle Files
or
Files > Sync with File System
Should do the trick.
goto Android >> Gradle Scripts>>Build Gradle(Module :app)
make sure the first line of this file is like this.
apply plugin: 'com.android.application'
not like this
apply plugin: 'com.android.library'
The following worked for me:
edit the overall project's 'settings.gradle' file and add a line at the bottom to include your new module (include ':myNewModule') - e.g:
include ':myNewModule'
Synch gradle.
Add a build.gradle file into your new module directory. You need to make sure the first line says 'apply plugin: 'com.android.application'. Simply copying a build.gradle from another module in your project, if you have one, seems to work.
Synch Gradle
Your module should now show up in 'Edit Configurations'
This mainly happens when you copy a library project and try to build it. The solution would be to add
apply plugin: 'com.android.application'
in the build.gradle file, instead of
apply plugin: 'com.android.library'
Then do a gradle sync
This worked for me: File > Project Structure... > Modules > Green Plus Symbol > Import > Then Select The Project
In your module build.gradle file make sure you have the correct plugin set. it should be
apply plugin: 'android'
No configuration was deteched because IDE was unable to detech modules (<no module>).My compileSdkVersion and buildToolsVersion was 28 in build.gradle (app module)
android {
.
.
compileSdkVersion 28
buildToolsVersion 28
.
.
}
But SDK was not installed. So then I installed it first and it worked for me !!!
It appears different solutions work for difference people, for me just closing the project and importing it again resolved the problem.
I finally figure out why the module is not showed up when I add configuration for AndroidTests for a com.android.library module.
If you include your library module in your application's build.gradle like this:
compile project(':yourlibrary')
Since for library module it is compiled with release mode by default, you can't run Android Tests for it, that's why it won't show up in the module list.
I fixed it with following modification:
Add following configuration to the build.gradle of your library module:
publishNonDefault true
By make following changes, you can debug compile your library by editing the build.gradle of your application module like following:
- compile project(':yourlibrary')
+ debugCompile project(path: ':yourlibrary', configuration: 'debug')
+ releaseCompile project(path: ':yourlibrary', configuration: 'release')
Then sync it and you'll find it shows in the list.
Android Studio 4+
1- File -> Close project
2- Delete .idea folder
3- Open project again
It was fixed for me after removing and re-adding the Android and Android-Gradle Facets in the Module Settings dialog.
I managed to fix it in Android Studio 1.3.1 by doing the following:
Make a new module from File -> New -> New Module
Name it something different, e.g. 'My Libary'
Copy an .iml file from an existing library module and change the name of the file and rename references in the .iml file
Add the module name to settings.gradle
Add the module dependency in your app's build.gradle file 'compile project(':mylibrary')'
Close and reopen Android Studio
Verify that Android Studio recognises the module as a library (should be bold)
Rename module's directory and module name by right clicking on the newly created module.
Enjoy :)
The following are methods to help you:
Close and Open Project again
Close and Open Android Studio
Clean Project
Rebuild Project
Instantiate and Restart
Make sure you have included :app
Import the Project
I added this line to my app.iml file and it works
orderEntry type="library" exported="" name="appcompat-v7-19.1.0" level="project" />
For me it was fixed by simply restarting Android Studio.. Like the good old days of Eclipse
In my case problem was from a higher (or not downloaded) compileSdkVersion and targetSdkVersion in build.gradle(app).
This was happened because of cloning project in another pc that not downloaded that sdk image.
Close all Android Studio projects
Remove the project from the recent projects in Android Studio wizard
Restart Android Studio
Use import option (Import project- Gradle, Eclipse ADT, etc.) instead of open an existing
Project AS project
File -> Sync project with gradle files
Sometimes the errors exists in Android-manifest because of that there
is cross like image over run/debug configuration hence try to look
over if Android-manifest has any errors in just case.
For my case, a newbie I boogered up my project, not sure how but it would not longer run and complained about the manifest, the R, everything. I realized that some how in my settings.gradle did not have include ':app' once I added this, I was back on my way.
Well, nothing worked for me from all the answers. Finally, I clicked Run > Edit Configuration. On the left, u can choose a new main module and remove to deleted ones.
Add your module in your applications .iml file like:
orderEntry type="module" module-name="yourmoudlename" exported=""
It works for me.
If all the above doesn't work. Try to update your Android studio version.
Steps:
1. In Android Studio, select File > Settings (or Android Studio > Preference on Mac).
2. In the left pane, select Appearance & Behavior > System Settings > Updates.
3. Be sure that Automatically check for updates is checked, and then select a channel from the drop-down list.
4. Click OK.
For me it was:
Right click on app project folder & select Load/Unload Modules...
Select app module, click Unload >, & click OK
Right click on app again & select Load/Unload Modules...
Select app module, click < Load, & click OK
app then appeared for me in the configurations list again.

Resources