Set gradle temporary directory to SSD - android

I am using android studio with gradle. When I build the app, I notice the spinning harddisk is working a lot, so I looked and saw that gradle is writing temporary files to the directory defined (in Windows (8.1)) the variable TEMP or TMP under my user.
Is there some way I can change the directory gradle uses as temporary directory without changing it for all other applications as well?
I would like to move the gradle temp dir to an SSD. (Bonus question: do you think this would significantly speed up gradle, that is currently very slow)

Try to set environment variable GRADLE_OPTS to -Djava.io.tmpdir=D:\some\dir\on\sdd, and GRADLE_USER_HOME to D:\other\dir\on\ssd. Also make sure that the project directory is on SSD.

In yourbuild.gradle
allprojects {
buildDir = "c:/tmp/${rootProject.name}/${project.name}"
}
Here is the full example code:
// 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:2.2.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
buildDir = "c:/tmp/${rootProject.name}/${project.name}"
repositories {
}
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}

Related

Could not compile Build file

The android project file got deleted mistakenly after I have successfully recovered from Drill Disk and tried to run the project I got an error
Build file 'E:\AndroidStudioProjects\side\app\build.gradle' line: 25
Could not compile build file 'E:\AndroidStudioProjects\side\app\build.gradle'.
> startup failed:
build file 'E:\AndroidStudioProjects\side\app\build.gradle': 25: unexpected char: 0x0 # line 25,
column 2.
}
^
I have tried pasting it from the project the Build.Gradle file from Github still I get the error:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.3'
classpath 'com.google.gms:google-services:4.3.5'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
center()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I don't want to pull or create a new instance because I have made the changes in the old file, so if I do it again it will take a lot of time again.
So any expert please help me with what I should do, I have referred to the older post here at Stackoverflow related to this topic But I was unable to get the solution?

Adding your API_KEY to an Android project downloaded from GitHub in the Gradle properties file

I am trying to add my API_KEY to a project downloaded from GitHub. In the ReadMe of the project, it is asking for me to update the gradle.properties file, but I do not see any such file in the project. I do see local.properties (which is where I presume I need to make the changes) and gradle-wrapper.properties file. I have tried adding the API_KEY designation to each but neither seems to work. I simply can get passed configure build step in Android Studio. Does anyone know what I am doing wrong?
The reason I presume that I update the local.properties is that it is not included in the build and therefore not exposing the API_KEY to anyone else. Is this correct?
The log link takes me to the app/build.gradle file but i presume the buildConfigField should link to the actual API_KEY in some file but I am not sure where that exists? Thanks in advance.
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.2.70'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-
plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle.properties is not the same as local.properties. Create a file named gradle.properties in you Project root folder (outermost folder) and add the api key
API_KEY = "YOUR_API_KEY"

I am not able to sync my android project as it was build on another PC. How to solve it?

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript [poiu{
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()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
buildscript **[poiu**{
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
}
}
Pay attention to the code wrapped in * - the code there should be purely buildscript without the [poui at all.
As to how this happened; It might be copy-paste error(paste in wrong place) or it might be accidental code writing. The point is to fix it. Gradle build errors are not as detailed and the IDE does not show error in the same way the java(or C++ etc) compilers and IDE's show them.

Error:Could not find com.android.tools.build:gradle:2.1.0-alpha1

I update my android studio and restart it, it works properly but when i try to imoprt my previous project it shows error somthing like that:
here is the snapshot of error...
Error during import the project
and here is my gradle file...
// 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:2.1.0-alpha1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Try with other distribution of gradle.
Open gradle-wrapper.propertieswhich It's inside gradle/wrapper folder and in distributionUrl set another one which work, for example:
distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip
EDIT
Try with this classpath in global build.gradle
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
I had the same problem upgrading my Android Studio to 2.2.0. I changed the classpath property of my build.gradle file but the difference with the answers above is that I didn't put the version of the Gradle but the Android Studio's one and it worked. Note that you also need to verify the Ggradle home path in file>>settings>>build,execution,deployment>>gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
I had this problem today, and when I updated the Android Plugin Version to the recent one, it worked. So, I think when you meet this problem, you can update the Gradle and Android Plugin Version to the newest. It always works. This is my configuration:

Why can't I really follow this Android Studio tutorial?

I am following this tutorial on how to use Android Studio to create android apps. At the very end, the user opens the file 'build.gradle' which looks completely different from what I have:
// 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.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Maybe this is not very important? Or is the video using an old version of AndroidStudio/SDK/gradle/whatever?
You are opening the top-level gradle file. The gradle file that appears in the video is the app module one.
You can have more than one module in the same project to divide your app code and/or to create different apps that share some code. Each module has its own gradle file to configure its dependencies and know how to compile it. The top-level file contains common configuration options for all modules, as the top comment tells.

Categories

Resources