Could not get unknown property 'assembleRelease' while using gradle 2.14.1 - android

When using older version then gradle 2.14.1 then below statement compiled and
run successfully but after updating with gradle 2.14.1, its not working.
code:
assembleRelease.dependsOn 'increaseVersionCodeAndName'
Thanks,
Devang

You may change your task increaseVersionCodeAndName that it will depend on release like:
task increaseVersionCodeAndName() << {
//your code
dependsOn 'assembleRelease'
}
Instead of calling gradle assemble call your own gradle task increaseVersionCodeAndName

Related

Android Studio - Failed to notify project evaluation listener error

Following is the build.gradle code in Android Studio
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.sg.blahblah"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
lintOptions {
checkReleaseBuilds true
abortOnError false
xmlReport true
htmlReport true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
lintOptions {
disable 'MissingTranslation'
}
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.google.android.apps.dashclock:dashclock-api:+'
compile 'com.roughike:bottom-bar:1.4.0.1'
compile 'com.diogobernardino:williamchart:2.2'
}
I am getting the below error:
Error:A problem occurred configuring project ':app'.
Failed to notify project evaluation listener.
com.android.build.gradle.tasks.factory.AndroidJavaCompile.setDependencyCacheDir(Ljava/io/File;)V
Can anyone please help?
Following is the Instant Run screenshot
I got this problem too. I fix it by Change build.gradle in project
Change
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
}
And also I change the distributionUrl in gradle-wrapper.properties(Global Version)
distributionUrl=https\://services.gradle.org/distributions/gradle-4.0-milestone-1-all.zip
And got succeed.FYI.
I am facing same error before a week I solve by disabling the Instant Run
File → Settings → Build, Execution, Deployment → Instant Run and
uncheck Enable Instant Run.
Hope it works.
Note This answer works on below Android Studio 3
you need check your gradle version. gradle -v
then you should know your gradle version and your gradle plugin version compatible.
Example:
gradle 4.6 is not compatible with gradle plugin 2.2.
so need update com.android.tools.build:gradle version to 2.3.3.
then you need check gradle/wrapper/gradle-wrapper.properties distributionUrl gradle version
google Android Plugin for Gradle Release Notes
on the other hand
using newer plugin version might require to update Android Studio
thanks #antek
I also encountered this error when updating to 'com.android.tools.build:gradle:3.0.0'
To fix it, I had to add the google() repo to both the buildscript and module repositories. The documentation here only mentions adding to to the buildscript.
Project-level build.gradle
buildscript {
repositories {
...
// You need to add the following repository to download the
// new plugin.
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
}
App-level build.gradle
repositories {
...
// Documentation doesn't specify this, but it must be added here
google()
}
gradle-wrapper.properties
...
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
had similar problem, issue was different versions of included library. to find out what causes problem run build command with stacktrace
./gradlew build --stacktrace
In my case, i got wifi problem. make sure you have valid internet connection
In my case I solved this error only by Invalidating caches.
File > Invalidate caches / Restart
This is neither an exact answer to the question nor a silver bullet.
However, if nothing works for you e.g. Invalidate cache & restart, Checking build dependency, Disabling Instant Run (I never advise that) etc.
Add command-line option --stacktrace in Setting > Build, Execution, Deployment > Compiler
Now build/assemble gradle once again. You will have detailed information about the cause. e.g. in my case:
Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException:
Could not find com.squareup.okhttp3:logging-interceptor:3.9.1Net.
I have misspelled the dependency name in module level gradle file. Hope that help
The problem is probably you're using a Gradle version rather than 3.
go to gradle/wrapper/gradle-wrapper.properties and change the last line to this:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
For those of you working on a team:
I pulled down some changes that included updating the build tools version, but I had not downloaded that new version of the build tools on my machine. Downloading the new version fixed this issue for me
For me, this issue arose due to an incompatible combination of plugin and gradle.
I added these to the code to have it working:
Main build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
}
Main gradle-wrapper.properties:
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
Usually it depends on Instant run or Gradle, but I tried both variants and nothing helped me. Then I looked through idea.log and saw this error
Caused by: java.lang.RuntimeException: A conflict was found between the
following modules:
- com.android.support:support-core-utils:25.3.1
- com.android.support:support-core-utils:27.0.1
I really don't know why this error is not shown in Gradle Console or Event Log tab. Then I fixed it by adding some code to the end of android{} block.
configurations.all {
resolutionStrategy {
failOnVersionConflict()
eachDependency { DependencyResolveDetails details ->
if (details.requested.name == 'support-core-utils') {
details.useVersion '25.3.1'//Or you can use 27.0.1 if it does not conflict with your other dependencies
}
}
}
I had this issue because I was using Charles proxy on my computer and the SSL was enabled for all hosts. And since AS didn't trust my proxy, the network request failed.
So I had to disable SSL for all hosts and restart my Android Studio.
In my case I have changed version of Kotlin plugin in gradle file related to module but hadn't change it in root gradle file.
It is interesting but as for me help this:
File -> Setting -> Gradle -> disable offline work
I have met the similar problem.
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':app'.
> Failed to notify project evaluation listener.
> org.gradle.api.tasks.compile.CompileOptions.setBootClasspath(Ljava/lang/String;)V
* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.0-milestone-1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 7s
Build step 'Invoke Gradle script' changed build result to FAILURE
Build step 'Invoke Gradle script' marked build as failure
Finished: FAILURE
The key is you need to get a way to solve this kind of problems,not to
solve this problem.
According to the log above,the most important information is:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.
Most of the building problems of Gradle will be solved because when you use the specific Gradle build command,you can get more detailed and useful information that are clear.
*clean project
./gradlew clean
*build project
./gradlew build
*build for debug package
./gradlew assembleDebug or ./gradlew aD
*build for release package
./gradlew assembleRelease or ./gradlew aR
*build for release package and install
./gradlew installRelease or ./gradlew iR Release
*build for debug package and install
./gradlew installDebug or ./gradlew iD Debug
*uninstall release package
./gradlew uninstallRelease or ./gradlew uR
*uninstall debug package
./gradlew uninstallDebug or ./gradlew uD
*all the above command + "--info" or "--debug" or "--scan" or "--stacktrace" can get more detail information.
And then I found the problem is related with the version of Gradle,when I have changed Gradle from 5.0 to 4.1,and then it's OK.
For me I had to specifically stop the gradlew and clear caches and this fixed my issues:
./gradlew --stop
// Delete all cache files in your project. With git: `git -xfd clean`
// Delete global cache dir. On Mac it is located in `~/.gradle/caches
Found here:
https://github.com/realm/realm-java/issues/5650#issuecomment-355011135
I've resolved this issue by cleaning all the Gradle cache, stoping the Gradle Daemon process, and created a new build successfully using the following command. Make sure your current directory is android.
rm -rf ~/.gradle/caches && ./gradlew --stop && ./gradlew cleanBuildCache && ./gradlew bundleRelease
I'm using React Native. So I've added following in my scripts in package.json,
"build-android": "rm -rf ~/.gradle/caches && cd android && ./gradlew --stop && ./gradlew cleanBuildCache && ./gradlew bundleRelease && cd ..",
Changing the below line in your gradle.build helps.
classpath 'com.android.tools.build:gradle:4.2.2'
With the new google support gradle plugin (com.google.gms.google-services) this can be caused by some dependency version problems with your com.google.android.gms.* modules.
You can probably see the root cause by running the build command with the --stacktrace parameter. i.e.:
./gradlew :app:dependencies --stacktrace
which might output the cause of the problem:
Caused by: org.gradle.api.GradleException:
The library com.google.android.gms:play-services-measurement-base is being requested by various other libraries at [[15.0.2,15.0.2],
[16.0.0,16.0.0]], but resolves to 16.0.0. Disable the plugin and check
your dependencies tree using ./gradlew :app:dependencies.
at com.google.gms.googleservices.GoogleServicesPlugin$1$_afterResolve_closure1.doCall(GoogleServicesPlugin.groovy:328)
at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedAction.java:71)
Just Change the Distribution url at gradle-wrapper.properties
Place it : https://services.gradle.org/distributions/gradle-4.10.1-all.zip
I ignored using JDK13 with Android Studio, So I selected below settings and it was solved:
Step 1. (File > Other Settings > Default Project Structure > SDK Location > JDK Location)
Embedded JDK
Step 2. (File > Project Structure > Project)
gradle plugin 3.6.3
gradle 5.6.4
I had buildToolsVersion "27.0.1", upgrading it to 27.0.2 fixed the issue.
Also, my android support deps were at version 27.0.2 so they were not aligned to the buildToolsVersion
The only thing that helped me was to use the system gradle instead of Android Studio's built-in:
SETTINGS -> Build, Execution, Deployment -> Gradle
Select Use local gradle distribution. To find the path, you can do which gradle where the which program is supported. It might be /usr/bin/gradle.
See also Error:Could not initialize class com.android.sdklib.repositoryv2.AndroidSdkHandler for another possible cause.
SETTINGS -> Build, Execution, Deployment -> Gradle -> unselect Offline work
Then sync project, you are good to go.
If not working , then File > Invalidate caches / Restart - > Invalidate and Restart.
In my case, I was missing the target SDK platform installed. I remember this error was straightforward and prompted you to install it automatically. Worth checking that as well.
First Step:File → Settings → Build, Execution, Deployment → Instant Run and uncheck Enable Instant Run.
Second step: Press Invalidate/Restart.
done.... Enjoy.
In my case, I had to do -
File -> Sync Project with Gradle Files
In my case I had to update all the Firebase libraries to the latest versions.
I think u have to change compile by implementation first, then maybe the problem is your android version, it is not compatible with your code, so update it.
And Good luck

Could not get unknown property 'assembleRelease' for project

After updating Android Studio to version 2.2 and the gradle plugin to 2.2.0, I get following error:
Error:(32, 1) A problem occurred evaluating project ':jobdispatcher'.
Could not get unknown property 'assembleRelease' for project ':jobdispatcher' of type org.gradle.api.Project.
The problem is in the build.gradle file of an imported jobdispatcher module:
task aar(dependsOn: assembleRelease)
What changes can I make to fix this?
Note, this issue is very similar to, but still a bit different to, that reported here.
Move your dependency dependsOn inside your gradle task like shown below:
task aar() << {
dependsOn 'assembleRelease'
}
Just add "" like this to fix your problem:
from:
task aar(dependsOn: assembleRelease)
to:
task aar(dependsOn: "assembleRelease")
I tried all the previous answers, all are not working. Here is the one working after gradle 2.2.
Starting from 2.2, those tasks also include "assembleDebug" and "assembleRelease". To access such tasks, the user will need to use an afterEvaluate closure:
afterEvaluate {
task aar(dependsOn: assembleRelease) {
//task
}
}
task aar {
....
}
aar.dependsOn('assembleRelease')
and task aar will run after task "assembleRelease" finished~
wish this will help you~ :-D
I had the same problem.
Disabling instant run under Android Studio/Preferences/Build, Execution, Deployment/Instant Run worked for me.

Where to define gradle task so that it doesn't run with every build

I have defined a gradle task that increments version code.
The thing is that it is in the app.gradle and it runs with every build.
My goal is to make it run on demand from our CI server.
Just make your task depends on a special task. In your case:
task incVersionCode(dependsOn: ["assembleRelease"]) << {
// your task code
}
you can also use this android gradle plugin for auto increasing version code:
https://github.com/moallemi/gradle-advanced-build-version/

Android Studio - gradle task to execute after SYNC

Is there a way to execute gradle task once after project Sync with Gradle files is complete?
I've tried to set task dependency to preBuild, as I've seen gradle:build is triggered when Sync is executing. But the problem is that dependency doesn't seem to work, task is not executed and I have to manually start the task after each Sync.
This is basically what I've tried so far
apply plugin: 'com.android.library'
...
task myTask {
...
}
gradle.projectsEvaluated {
preBuild.dependsOn(myTask)
}
I've also tried to set task dependency to other tasks that I see are triggered (:generate{Something}), but that wasn't successful either.
Is there anything I can to do force the gradle task to be executed after each Sync?
I'm using Gradle 2.2.1 + Android Studio 1.0.2
Finally, I've managed to trigger the task on every Sync event.
Apparently gradle.projectsEvaluated is either not executed at all when syncing, or it is executed after build task, so the solution is to get rid of it completely
apply plugin: 'com.android.library'
...
task myTask {
...
}
preBuild.dependsOn(myTask)
Inside the Gradle menu (usually located on the upper right corner of Android Studio), there is a list of tasks. By right clicking on the task, it is possible to set Execute After Sync.
Some while ago JetBrains extended their idea gradle plugin and now you can write something like
idea.project.settings {
taskTriggers {
afterSync tasks.getByName("myTask")
}
}
You must apply the plugin, such as
plugins {
id "org.jetbrains.gradle.plugin.idea-ext" version "0.7"
}
according to docs:
A Gradle build has three distinct phases
Initialization...
Configuration During this phase the project objects are configured.
The build scripts of all projects which are part of the build are
executed.
Execution...
Our build.gradle files are executed during Configuration phase. Task is a class (we extend org.gradle.api.DefaultTask when developing them). So let's just call our task's execute method:
task myStandaloneTask(type: MyStandaloneTaskImpl){
println("myStandaloneTask works!")
}
// let's call our task
myStandaloneTask.execute()
task myInsideGradleTask {
println("myInsideGradleTask works!")
}
// let's call our task
myInsideGradleTask
where MyStandaloneTaskImpl is a Task developed in buildSrc or as Standalone project, details
P.S. No need to use parenthesis () after myInsideGradleTask because of Groovy

Cant build project using Gradle in Android Studio

When i open my gradle project in Android Studio, it will show build successful in the terminal while after that it shows the following error:
Could not execute build using Gradle distribution
'http://services.gradle.org/distributions/gradle-1.6-bin.zip'. Task 'wrapper' not found in root project 'gradle'.
Althoug I am running gradle 1.9, I dont know why this error is shown
If you are using gradle wrapper make sure these lines are added in to your top level build.gradle file
task wrapper(type: Wrapper) {
gradleVersion = '1.9'
}
Also your $YOUR_PROJECT_DIR/gradle/gradle-wrapper.properties should point to write distribution url, I have observed that distrinutionUrl defined in gradle-wrapper.properties file changes aumatically according to the gradle version defined in wrapper task while syncing. If the task is not defined by default it changes to 1.6 .
So check it and make it correct
distributionUrl=http\://services.gradle.org/distributions/gradle-1.9-bin.zip
And finally wherever you have defined your gradle dependencies class-path in build.gradle files they all should be
dependencies {
classpath 'com.android.tools.build:gradle:0.7.+'
}
0.7.* is used for gradle version 1.9 , you can make all the changes as per your gradle version.

Categories

Resources