Error:Cause: buildToolsVersion is not specified - android

I create a simple project and then I right-click on the project and then I use the make mudole app option. Now I have two build.gradle folders: 1- build.gradle:project My Application. 2- build.gradle: Mudole app. the first build.gradle is as follows:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.library'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
And the second Build.gradle folder is as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "com.exam.exam.myapplication"
minSdkVersion 7
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
And now I click on the run option to create aar file from this project But I get the following error:
Error:Cause: buildToolsVersion is not specified.

I had the same issue. What I was doing wrong was the placing of apply plugin statement in the root gradle of the project. When I placed it in the app gradle then the issue got resolved.
What I would suggest is to check if you are placing some statement in the root gradle that you should be placing in the app gradle.

Add buildToolsVersion to your build.gradle file this will solve your problem.
buildToolsVersion "27.0.1"
Gradle file code
android{
compileSdkVersion 27
buildToolsVersion "27.0.1"
useLibrary 'org.apache.http.legacy'
}

Add buildToolsVersion property to your local build.gradle file.
android {
compileSdkVersion 27
buildToolsVersion "26.0.1"
defaultConfig {
targetSdkVersion 27
}
}
As per your requirements!! Then Try to build -> you will get build failure and this message :
Failed to find Build Tools revision 26.0.1
Install Build Tools 26.0.1 and sync project
Then Click to Install build tools and your project is configured and you are good to go!!!

in file... build.gradle(Project: XXX):
repositories{
//put pluging repository here
//e.g.:
mavenCentral()
}
dependencies{
//classpath to plugin here
classpath 'com.XXXX.xXXxxXX.XXXX'
}
in file.... build.gradle(Module: app)
//add on top:
apply plugin: 'com.YOUR.PLUGIN.XXX'

The issue for me was that andorid-versionCode can only be integer value.
in build.xml:
eg:android-versionCode="1"
It cannot be "1.1" etc...
The error code is not helpful at all.

Not really sure what the underlying problem was, but I found the solution in a concurrent problem that was occurring:
https://stackoverflow.com/a/32490472/1544046
Essentially, I had to change my gradle target to use the wrapper and not a defined path. I've had it set to the Gradle Wrapper in the past, but it seems to revert from time to time without notice. Once I switched back and recompiled it worked fine.
In the project's settings: Build, Execution, Deployment->Build Tools->Gradle and select "Use default gradle wrapper".

Might be helpful for someone:
in my case long time ago I had added keystore properties in build.gradle file for Android:
def keystorePropertiesFile = rootProject.file("keystore.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
and after some period of time I pulled repo and forgot to add this file ("keystore.properties").
Gradle for some reason (!) gave me the same error (buildToolsVersion was defined a bit below in build.gradle file).
The workaround was just to add missing "keystore.properties" file.

Android Project > setting.gradle
include ':app' , ':xxx'
I imported one of module and this coused this error. I remove it is fixed.
include ':app'

Check if android studio version in build.gradle is same as the one you are running.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
In my case, I opened/imported the project created on android studio 2.3.3 in android studio 3 and i was able to get rid of this issue after updating the build.gradle with 3.0.0

for me it was an additional classpath line for example :
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.4.1'
so i was deleting the first
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.0'
and the issue solved

I had same error, I using cordova and resolve by removing the space character
id="com.xx.yy " => to id="com.xx.yy"

Try to invalidate caches / restart , it fixed this like this after updated
File-> Invalidate caches/restart

Related

run common gradle code in android base project gradle file

i have a library which uses all of our apps.
except for shared code and resources i wanted to share gradle code.
each app is constructed:
some_app/
|
- settings.gradle
- build.gradle
|
- mylib/
|
-build.gradle
- other_lib/
- app/
|
- build.gradle
right now i'm talking about the build.gradle in the root dir. The one that defines buildScript closure with dependecies and allprojects{} closure as well.
i tried to use apply from: './mylib/gradle_files/baseProject.gradle'
it works, but then my app can't find the android plugin. for some reason the classpath dependencies were not injected into the build script!
i then tried to create a list and use that:
ext.projectBaseDependencies = ['com.android.tools.build:gradle:2.1.2', 'com.google.gms:google-services:3.0.0']
I then used the list in my closure:
apply from: './mylib/gradle_files/baseProject.gradle'
buildscript {
repositories {
jcenter()
}
dependencies {
classpath projectBaseDependencies
}
}
it doesn't work, gradle does not find my variable defined in baseProject.gradle.
I have a hunch that apply from works AFTER buildScript closure is evaluated :-(
Is there any way to share gradle script code across ALL apps ? if not apply from, what CAN work ? skip configuration and config in afterEvaluate {} clause ?
Why not use a Gradle file in your common library? If your common library includes a build.gradle file, you can apply the android library plugin:
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
versionCode 1
versionName "1.0"
consumerProguardFiles "proguard-rules.pro"
}
}
dependencies {
// Your common dependencies here
}
Then you can include the library in your project's settings.gradle:
include ':mobile'
project(':common').projectDir = new File("/Users/example/path/to/common")
Then add it to your dependencies in the project's build.gradle:
dependencies {
compile project(':common')
// Your other project dependencies
}

Gradle failed to sync with 'unable to find optional library'

I had to reinstall my system and today I get this error in Android Studio when I try to sync with gradle:
Warning: Unable to find optional library: org.apache.http.legacy
My project gradle is:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
mavenCentral()
}
}
And my module gradle:
apply plugin: 'android'
android {
useLibrary 'org.apache.http.legacy'
compileSdkVersion 23
buildToolsVersion '23.0.2'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
}
buildTypes {
release {
}
}
productFlavors {
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:appcompat-v7:23.1.1'
}
From the google docs:
To continue using the Apache HTTP APIs, you must first declare the
following compile-time dependency in your build.gradle file:
android {
useLibrary 'org.apache.http.legacy'
}
I tried the suggestions mention in this thread but they don't work. Same result with android studio 1.5 and 2 preview.
How can I fix this?
Edit: Things I've tried so far:
Change gradle classpath versions to 1.3.0, 1.3.1, 1.5.0.
Change the compileSdkVersion and targetSdkVersion to 22. Also the buildToolsVersion from 23.0.1, 23.0.0, 22.0.1.
Top level build.gradle - /build.gradle
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
Module specific build.gradle - /app/build.gradle
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
Add org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional folder to app/libs directory and sync your project
After a lot of working this solutions work for me
.
** Studio\Android\sdk\platforms** here delete your android-23 and from sdk manager update api 23 again.**
.
it will solve your issue.
In my case, it didn't work because I was missing optional.json in <sdk-path>\platforms\android-23\optional\, directory with the following content:
[
{
"name": "org.apache.http.legacy",
"jar": "org.apache.http.legacy.jar",
"manifest": false
}
]
Creating a new JSON file with with above content solved the problem for me.
You need to add org.apache.http.legacy.jar jar file in your Android Stuido project's app/libs folder.
Jar Location - `<SDK LOCATION>\android-sdk\platforms\android-23\optional`
To do this, just right click on your project and select Show in Explorer then go to ...\app\libs and paste above jar file and Sync your Project with Gradle File
Module:app
android {
compileSdkVersion 'Google Inc.:Google APIs:23'
buildToolsVersion "24.0.0"
defaultConfig {
applicationId "<ur_app_id>"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
Update your project gradle file to use gradle version 1.3.1.
classpath 'com.android.tools.build:gradle:1.3.1'
Also try adding codehause repo.
repositories {
mavenCentral()
maven{
url 'http://repository.codehaus.org'
}
}
In my case the problem was actually occurring because I didn't have the correct SDK installed on that computer. Navigating to .../Android/Sdk/platforms/android-23 I could see that folder was empty. Adding SDK 23 via the SDK manager fixed the problem and allowed me to compile.
You should manually check that you have the same version of the SDK installed that is specified under compileSdkVersion in your build.gradle file.
To save time 2 solutions are best and works for me.
Solution 1 :
open your android sdk manager and reinstall API 23 (remove and install again).
Solution 2 :
Download this file which contain optional.json file
extract and move optional.json to :
C:\Users\\AppData\Local\Android\sdk\platforms\android-23\optional
if above solution is not work then try this way
I experienced this problem recently, and it is caused by the path length restriction I think it´s 256 characters maximum.
Relocate your Project and the build will succeed.
Copy "sdk\platforms\android-23\optional\org.apache.http.legacy.jar" to your app module libs directory, then add as library;
If you enable the proguard, please edit "proguard-rules.pro" to keep related classes or exception will occurred.

Android Studio Gradle does not download maven depedencies

I am quite new to Android development and trying to write some test code. I have downloaded Android Studio 1.3 version and created testapp. I am trying to add com.facebook.android:facebook-android-sdk:4.1.0 depedency but somehow it's not getting downloaded.
Here is Project level build.gradle file.
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}}
Here is Module level build.gradle file.
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "com.testapp"
minSdkVersion 19
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.android.support:appcompat-v7:22.2.1'
}
After reading other posts on similar topics I also confirmed that Gradle > Global Gradle settings > Offline work is not checked. Still somehow facebook depedency is not getting downloaded.
Any suggestions what could be the issue? Appreciate any pointers.
Thanks.
In your build.gradle you have to add
repositories {
jcenter()
}
It this way gradle knows where are the dependencies to download.
It is somenthing different from the repositories inside the buildscript block.
Otherwise you can add in the top-level build.gradle file:
allprojects {
repositories {
jcenter()
}
}
In this case, the repository block is valid for all modules in the project.
Could you post the error AndroidStudio is showing? (check on the Gradle Console, on the Run section and Android Monitor section)
One possible option that comes to my mind is that you don't have the lastest Android Support repository / Google repository installed: Check for updates on your Android SDK Manager.

Upgrading project to Android Studio 1.0 (Gradle problems)

Just to start I'm very new to android development/android studio/gradle so forgive me if I'm asking a stupid question.
My team has been working on a project with the beta version of android studio, I've just installed the new version (1.0) and i've imported our project from the github remote repo.
When trying to sync the project with gradle i get the error: Gradle version 2.1 is required. Current version is 2.2.1. It recommends that I change the distributionUrl in gradle-2.1 but when I do I get the error that the gradle plugin requires 2.2.1.
The question is why is my project requiring 2.1 and where can I change this?
Here is my gradle.build:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.0"
defaultConfig {
applicationId "com.<teamName>.<projectName>"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
buildscript{
dependencies{
classpath 'com.android.tools.build:gradle:1.0.0'
}
}
in the gradle-wrapper.properties use the following
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
in build.gradle use
dependencies {
classpath 'com.android.tools.build:gradle:1.0.+'
also replace
runProguard false
with
minifyEnabled true
I hope this can help
I was having the same issue that you were and had made the exact same updates as described in the Google docs.
The error I was making was editing my app module's build.gradle, and not the project's build.gradle in the root of the project folder for the com.android.tools.build version.
Here's the updated PROJECT's build.gradle file that I'm using that works.
// Top-level build file where you can add configuration options common to all sub- projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
ext {
compileSdkVersion = 21
buildToolsVersion = "20.0.0"
minSdkVersion = 15
targetSdkVersion = 21
}
allprojects {
repositories {
jcenter()
}
}
To change the gradle distribution used go to this file: {Project folder}/gradle/wrapper/graddle-wrapper.properties.
Then change the distributionUrl to use 2.1:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.1-all.zip

Android Studio Error:(3, 0) Plugin with id 'com.android.application' not found

I'm new to android studio and had somebody write an app I made which was originally used in app inventor. I followed his template and added new things. The app has a problem with the Gradle and gives me the following.
"Error:(3, 0) Plugin with id 'com.android.application' not found."
It also says that my extras Android Support Repository isn't installed however it is. and everything is up to date. I saw many things about updating the Gradle, How do I do that if the SDK manager didn't.
code is:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.0.2"
defaultConfig {
applicationId "contactorganizer.introcode.or.myapplication"
minSdkVersion 8
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.0'
}
Sorry about not having much knowledge.
If you would like the project I can email it to you because I have absolutely no clue and would love to just build this.
Thanks for your help!
When I updated my Android Studio to the latest, I got the same problem. Here is how I solved it.
First:
Add the following code to the top of your build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Second: Find the gradle-wrapper.properties.
Change the last sentence to this:
distributionUrl=http\://services.gradle.org/distributions/gradle-2.2.1-all.zip
Hope this works for you.
I have faced the problem too. The android plugin is 1.2.3. It appears when running one module task in the module directory like this way, ../graldew :module:xxx.
I eventually notice plugin 1.2.3 cannot get right context and android plugin 1.5 works well. So It will work to give it right gradle file.
../gradlew -b ../build.gradle -c ../settings.gradle :module:xxx
This is the situation for me. You can just regard it as a reference.

Categories

Resources