Android Studios unable to find gradle tasks to build a program - java

When I try to build a kotlin program on android studio, it displays the notification:
*Unable to find Gradle tasks to build: [:].
Build mode: COMPILE_JAVA.
Tests: All.*
This happens when I try to debug or run a code like
fun main(){
println "hello world \n I am Michael Girum."
}

In Android studio, under the project source files, under android>app>src, right click on build.gradle, and click Run 'android'
This will than compile, you can than run the project.

I tried to build an old Android project
classpath 'com.android.tools.build:gradle:2.3.1'
and I solved it by adding a
settings.gradle
with content
include ":app"

Related

Run task not found Gradle Java Project in vscode

There is this Project i am dealing with, you can check it's Git Repository here :
Arcore repo
The Project builds successfully and runs on emulator or physical device while using android Studio .
Problem: I cloned this project and opened it with vscode, and run ./gradlew clean build; this goes as expected!!
But it seems to always get stack at :
./gradlew run
with "error" run task is not found in the root project
Just add this code to your build.gradle file:
plugins {
id 'com.android.application'
}
The com.android.application plugin already includes the task run, so your error should be fixed.
For more information regarding this plugin, read the official documentation here (Android), and here.
For Future visitors of this thread, I will answer my Question here:
As a contribuer stated to implement com.android.application plugin to root build.gradle, this did not implement the application and run task within the root project. Instead the plugin needed simply was:
// root build.gradle
plugins {
id('application')
}
Now re-running ./gradlew build does add the run task, provided by the plugin above .

The project uses Gradle 2.10 which is incompatible with Android Studio 2020.3

While learning android studio from udacity they asked me to download a project; I did so but while I was importing it to android studio I got an error message:
The project uses Gradle 2.10 which is incompatible with Android Studio 2020.3.
Why did I get this error?
If you did not figure this out yet, I am just starting the same project too. I changed the classpath like above. I then found a website to use the latest version of gradle and the plugin. It says "You can specify the Gradle version in either the File > Project Structure > Project menu in Android Studio, or by editing the Gradle distribution reference in the gradle/wrapper/gradle-wrapper.properties file." I did the first one.
Then, I got errors for both build.gradle files in the project and app version. I get this error: Could not find com.android.tools.build:gradle:7.0.3
If you get this error, click the link "Add google Maven repository and sync project". Then you have to click "Do refactor".
Now you come across another error in one of the build.grade files. This stackoverflow link will tell you: Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]
Finally, replace testCompile with testImplementation and then you should get BUILD SUCCESSFUL.
The project's Gradle version you're trying to clone is outdated. Change it based on your android studio version.
on your build.gradle(Project) change the version and sync
classpath "com.android.tools.build:gradle:4.1.2"
Got the solution :)
In gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip
In build.gradle project level:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In build.gradle module level:
Replace all "compile" with "Implementation" and do other suggested version updated and you are done here :)
Hope this works for you, if yes just press that up button :)
If not getting any solution, the best you can do is copy the "app" folder of your project(using file explorer) and paste it in a newly created project(should be of same name as of your project), in that way you'll get already synced gradle and newly created version of your app.
Because, every important thing in your project is present in its app folder and when you create a new project with same name and copy app folder from your older version of your project, you will have a newer version of your project with all same resources.
Note: You can't move through branches and other commits
I saw this issue several times with Android studio. Below trick worked me the best.
Android Studio suggests to upgrade to newer version, please upgrade it and let it sync
Mostly you would see error message again
Now, Go to File -> Invalidate Caches/Restart
It should work now
If it shows same error then I don't know what to do.
If it shows different error then repeat from step 1 to 3 for new error.
Hope, it helps some..

Android Studio, R is error, can not resolved

I updated Android Studio to have 2.2 version.
Unfortunately, I got this error (R is in red color)
I reinstall Android studio but no change.. R still in red color
I did not even write any code
syn gradle
Error:Failed to resolve: org.hamcrest:hamcrest-core:1.1
Open File<br>Show in Project Structure dialog
Error:Failed to resolve: javax.inject:javax.inject:1
Open File<br>Show in Project Structure dialog
Error:Failed to resolve: com.google.code.findbugs:jsr305:2.0.1
Open File<br>Show in Project Structure dialog
Error:Failed to resolve: com.squareup:javawriter:2.1.1
Open File<br>Show in Project Structure dialog
please I need help
I had exactly the same problem.
Go to File->Project Structure->app->dependencies and
remove all the dependencies except these:
com.android.support:appcompat-v7:25.1.0 Compile
com.android.support:design:25.1.0 Compile
junit:junit:4.12 Test compile
This will change the dependencies structure under build.gradle.
Hope this works!!
This may caused, your build to not compatible with current version.so, Open your root build.gradle file and change Gradle version like this
Old version:
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
New version:
dependencies {
classpath 'com.android.tools.build:gradle:2.2.1'
}
You can find further details ,For Gradle version compatibility see this.
This is a common error in android studio. I fix it by doing build - clean. That usually works BUT if it doesnt, save and exit AndStudio and then restart

How to use gradle run with Intellij IDEA?

I have the following build.gradle file:
apply plugin:'application'
mainClassName = "MyMain"
allprojects {
sourceCompatibility = 1.7
targetCompatibility = 1.7
}
repositories {
mavenCentral()
}
dependencies {
compile 'org.jsoup:jsoup:1.8.3'
}
So when I do gradle run it works perfectly, it uses jsoup and so.
Now, I've imported this project at my Intellij Idea IDE, I created a gradle build run/debug configuration, so when I press the green arrow 'run', it's building the application, but not running it, so I guess it's executing gradle build.
I've searched for an way to run the application, and the Intellij Idea says that I must create a new Application run/debug configuration. I did it, told where my main class was, but when I click run, it tries to make the source code, and claims that it can't find Jsoup for compiling.
How can I mimic gradle run in intellij idea's IDE?
You need to delegate IDE build/run actions to Gradle
Open the gradle window in Intellij. View->Tool Windows->Gradle.
On the right hand side you will see a list of all your gradle tasks. Double click to run or right click and assign a shortcut to any of them.
Look for the Gradle Tool Window. The rest is self-explanatory :)
Do not forget to click "Refresh all Gradle projects" in that tool window each time you change the build script.

Android Studio Gradle error after update from 0.2.x to 0.3.1

I have recently updated my Android Studio from 0.2.9 to 0.3.1 and when I try to compile my project i get the error:
org.gradle.tooling.GradleConnectionException: Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.7-bin.zip'.: Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.7-bin.zip'.
I have tried to use the terminal and successfully cleaned and rebuilt by using gradlew clean and then gradlew build. I have even invalidated the caches by using File -> Invalidate Caches / Restart but I still can't build using Android Studio.
Do you have any ideas on why I have this problem and how can I fix it?
Edit #1 : When I go into Settings -> Gradle I get an error: "Gradle location is unknown". Is that the problem? Where should that path point to?
I have fixed the issue by using the advice from this post.
I have updated gradle-wrapper.properties from <AppNameProject>/gradle/wrapper/:
distributionUrl=http\://services.gradle.org/distributions/gradle-1.7-bin.zip
to
distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip
and build.gradle from <AppNameProject>/<AppName>/:
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
to
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}

Categories