I'm trying to add a .jar library to my project into the /libs folder. Here is my grade.build:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar', 'libs/java-api-wrapper-1.2.0-all.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 15
targetSdkVersion 16
}
}
After I add that, I build my project and there are no errors. But when I try to use the class in my code private ApiWrapper wrapper, I get an error:
Gradle: error: cannot find symbol class ApiWrapper
I can't quite find where the error is. Is my grade.build not ok, or am I supposed to build it some other way?
Using the command line, in the root of your project, run :
./gradlew clean && ./gradlew build
Then recompile your project in studio and you should see your new lib.
Set minifyEnabled to false for all your library projects in build.gradle.
See accepted answer by Scott Barta in this thread.
See accepted answer by Scott Barta in this thread
Goto File ⇒ Invalidate Caches & Restart
Solved my problem
As first option, i think will be enough Syncronizing the Project with Gradle Files.
Another option, from the command line, run the batch file gradlew.bat located inside your project folder:
./gradlew clean && ./gradlew build
I had a similar situation where Android Studio couldn't find a library that definitely existed. Even though I was able to compile my project in Android Studio, run it from Android Studio in the emulator or on a physical device, and build it from the command line using gradlew, the Android Studio IDE complained Cannot resolve symbol 'ConstraintLayout'. I believe I had imported the library correctly because I followed Google's instructions: https://developer.android.com/training/constraint-layout/#add-constraintlayout-to-your-project.
Anyway, I ended up solving the problem as follows:
Close Android Studio
Delete the .idea folder in the project's directory
Open Android Studio
Re-import the project so Android Studio can regenerate the .idea folder
This in-fact solved the problem. I believe Android Studio somehow corrupted the .idea folder when I had done "Android Studio" > "Check for Updates" earlier in the day.
Go to the Android studio File and press Invalidate Caches/Restart. This worked for me to find the library
Related
I downloaded an open source game "ChaseWhisplyProject" source code from Github.
I imported the project in my Android Studio (Version 1.5.1).
It shows following error message:
Error:Failed to open zip file.
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)
Re-download dependencies and sync project (requires network)
I changed all the dependency versions to latest one bu still it is showing the same message.
It has two modules under the main project 1) BaseGameUtils & 2)ChaseWhisply.
The above modules are not shown in bold letters (I think it should be shown in bold letters like module "app").
Following are the gradle files.
1) Root Gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
allprojects {
repositories {
jcenter()
}
}
2) BaseGameUtils Module Gradle
apply plugin: 'com.android.library'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
dependencies {
compile 'com.android.support:support-v4:23.1.1'
compile 'com.google.android.gms:play-services:8.4.0'
}
3) ChaseWhisply Module Gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.application'
dependencies {
compile 'com.android.support:gridlayout-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile project(':BaseGameUtils')
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
lintOptions {
// TODO fix and remove !
disable 'MissingTranslation', 'DuplicateIds', 'ExtraTranslation'
}
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
versionCode 22
versionName "0.3.6"
}
}
4) Settings.gradle
include ':ChaseWhisply', ':BaseGameUtils'
What is wrong over here? Please help.
While importing a libGDX project I got the same message from Android Studio 2.2.
Went to File->Project Structure then selected Project and set
Gradle version
and
Android Plugin Version
to values identical to another project I had recently created with Android Studio 2.2 and updated SDK. Could then sync gradle. Did Build->Build Clean with no issues. Then did Run->Clean and Rerun and project ran fine.
Hope this helps.
It basically means that the gradle zip file in the cache folder is corrupted, if you don't want to change the version like the up-voted answer then you must delete the folder for your gradle version you're using for this project from the below path.
Then just retry the sync and android studio will download it again
C:\Users\ [user here] \.gradle\wrapper\dists
ex: if you're using 3.3 for this project you'd be deleting the folder
C:\Users\[user here]\.gradle\wrapper\dists\gradle-3.3-all
I was also facing the same issue. The solution worked for me was go to "gradle\wrapper\dists" and deleted the folder "grade-4.10.1-all" folder and downloaded the same version after that i pasted the extracted folder in same address.After that I again synchronized the android studio. I worked for me.
I face the same problem and I search for it and found a best solution and i works for me:
Manually download Gradle 3.3 binary (direct link: https://services.gradle.org/distributions/gradle-3.3-bin.zip)
Open your android studio root directory, and extract the zip to the gradle folder (for example: program files/android-studio/gradle/gradle-3.3)
Open Android Studio, go to File->Settings-> (Build, Exectution, Deployment) >Gradle and set "Gradle home" to point your new gradle-3.3 folder.
Apply and sync.
May be incompatible with Gradle and maven version
delete project dir/gradle/wrapper
put a right version gradle into it
run again
change the gradle-wraper-properties distributionUrl to your local downloaded gradle such as
distributionUrl=https://services.gradle.org/distributions/gradle-3.3-all.zip
I solved this issue by this following steps
1.C:\Users\System name.gradle\wrapper\
2.Inside wrapper folder u will find grale file with some version, You just have to delete it
3.Come/Go to android studio and Go to File->Sync project with Gradle Files.
4.Android studio automatically download the require gradle file.
5.And now go for coding
The close android studio then goes to the directory and you will find this type of folder. I saw in my pc. after deleted then clean project and sync. its works fine.
you just delete from this directory
C:\Users\ [user here] .gradle\wrapper\dists
if you use 3.3 version in android studio. you can see like this
C:\Users[user here].gradle\wrapper\dists\gradle-3.3-all
Well, It's a bit late, but usually happens when something went wrong in Android Studio's initial launch (eg. system crash, connection loss or whatever). We can call it bad programming or lazy QA.
To fix this close Android Studio and delete everything from the following directory. Don't worry files will be downloaded on next launch.
For Windows: C:\Users\your-username.gradle\wrapper\dists
For Linux: ~/.gradle/wrapper/dists
For mac: ~/.gradle/wrapper/dists
You can also Gradle manually to fix this issue, But it's better to let Android studio does this work. .
Clean Project is a way to go. After you clean project, make sure you rebuild it. Usually it solves the gradle issues for me.
In my case I was running IntelliJ IDEA as non root user.
If you want to use the new features, you should not revert it to the old version, just delete the directory ~/.gradle recursively, then restart Android Studio.
Update your gradle version and update with required version of gradle and syn your project.
https://services.gradle.org/
First of all, open your gradle-wrapper.properties file from the project then note down the version of the Gradle.
It could be like this:
distributional=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
So, here my Gradle version is 6.5. It could be different in your case.
After this, open file explorer and open your project folder. There you will be having the Gradle folder open it, inside it the version will be mentioned of your previous Gradle.
Now you will have to download the Gradle file according to the wrapper.properties(for example nothing but 6.5 version).
You can download it from here
Extract it
paste it to the Gradle folder
open your project > file > settings > Build, Execution, Deployment > Gradle, then select the newly downloaded Gradle file in the Gradle user home.
Then run your project.
This worked for me - go to https://gradle.org/releases/ and download latest stable version (binary-only works fine). extract and insert into C:\Users\OWNER\.gradle\wrapper\dists folder.
Open Android Studio settings > Build, Execution, Deployment > Gradle, use gradle from: specific location.
The following steps solved my problem :
1.C:\Users\System name.gradle\wrapper\
2.Inside wrapper folder u will find grale file with some version, You just have to delete it
3.Come/Go to android studio and Go to File->Sync project with Gradle Files.
4.Android studio automatically download the require gradle file.
5.And now go for coding
I have recently updated android studio to the latest version,but then comes the problem.
Gradle 'MyApplication' project refresh failed.
Error:Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.2.1-all.zip'.
Found this in StackOverflow
However trying everything nothing works - cannot create new project of import anything at the moment.Please kindly advice.
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.sclick.myapplication"
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
task assemble{}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
}
**Top Level Gradle.build**
// 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
}
}
allprojects {
repositories {
jcenter()
}
}
gradle-wrapper.properties
#Wed Apr 10 15:27:10 PDT 2013
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip
I had same issue. I have tried many things but nothing worked Until I try following:
Close Android Studio
Delete any directory matching gradle-[version]-all within C:\Users\<username>\.gradle\wrapper\dists\. If you encounter a "File in use" error (or similar), terminate any running Java executables.
Open Android Studio as Administrator.
Try to sync project files.
If the above does not work, try restarting your computer and/or delete the project's .gradle directory.
Open the problem project and trigger a Gradle sync.
I had a similar issue, when I upgraded to the latest version of Android Studio 1.3.2. What seemed to work for me was removing the .gradle folder from my project directory:
rm -rf ~/project/.gradle
I had same issue when first start Android Studio in Window 10, with java jdk 1.8.0_66. The solution that worked is:
Step 1: Close Android Studio
Step 2: Delete Folder C:\Users\Anna\.gradle
(Anna is my username)
Step 3: Open Android Studio as Administrator
Step 4: If you are currently in an opened project, close current project by select File > Close Project.
Step 5: Now you seeing this Quick Start GUI:
Select Open an existing Android Studio project, navigate to your project folder and select it.
Wait for gradle to build again (it would download all the dependency in your build.gradle for every module in your project)
If it has not worked till now, you could restart your computer. Do step 1 again.
This happens sometime when I changed Android Studio version or recently upgrade Window. Hope that helps !
I forced to use a proxy and also forced to add proxy setting on gradle.properties as these:
systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=1080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=1080
And also forced to close and open studio64.exe as administrator .
Now its all seems greate
Event log says
8:21:39 AM Platform and Plugin Updates: The following components are ready to update: Android Support Repository, Google Repository, Intel x86 Emulator Accelerator (HAXM installer), Android SDK Platform-Tools 24, Google APIs Intel x86 Atom System Image, Android SDK Tools 25.1.7
8:21:40 AM Gradle sync started
8:22:03 AM Gradle sync completed
8:22:04 AM Executing tasks: [:app:generateDebugSources, :app:generateDebugAndroidTestSources, :app:prepareDebugUnitTestDependencies, :app:mockableAndroidJar]
8:22:25 AM Gradle build finished in 21s 607ms
I'm using android studio 2.1.2 downloaded as exe setup file. it has its Gradle ( I also forced to use custom install to address the Gradle )
Go on Project->Settings->Compiler(Gradle-based android project), find the text field "VM option" and put there:
-Xmx512m -XX:MaxPermSize=512m
This shouls solve the issue in any case the error shown in the gradle message window is "Could not reserve enough space for object heap"
Hope this helps
You can download the gradle you want from Gradle Service by reading the gradle-wrapper.properties.Download it ,unpack it where you like and then change your grandle configuration use local not the recommended.
I had the same problem and I Just Invalidate caches/restart
Try updating gradle dependency to 2.4. For that you need to go to
File -> Project Structure -> Project -> Gradle version.
There you need to change from 2.2.1 to 2.4. Wait for new gradle version to be downloaded.
And you are ready to go.
I have run into a similar problem on Mac.
Looking at the log under Help -> Show logs in Finder I found the following entry.
You have JVM property "https.proxyHost" set to "127.0.0.1".This may lead to incorrect behaviour. Proxy should be set in Settings | HTTP ProxyThis JVM property is old and its usage is not recommended by Oracle.(Note: It could have been assigned by some code dynamically.)
and it turned out I had Charles as a network proxy running. Shutting down Charles solved the problem.
I'm getting error below this,
Error:A problem was found with the configuration of task ':project1:zipalignDebug'.
> File 'D:\Program Files\Android Studio\sdk\tools\zipalign.exe' specified for property
'zipAlignExe' does not exist.
I downloaded all packages in sdk, I downloaded twice a packages about zipAlign but it didn't solve my problem.
Please help. Thank you.
If you're using Gradle, updating the Gradle plugin from 0.10 to 0.11 worked for me:
buildscript {
...
dependencies {
...
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
In case you run into the following Gradle build error after updating your Android SDK:
A problem was found with the configuration of task ':MyApp:zipalignRelease'.
File '/home/user/SDKs/android-sdk-linux_x86/tools/zipalign' specified for property 'zipAlignExe' does not exist.
Therefore, I updated the android-sdk-setup script to also symlink zipalign. Gradle now finds what it is looking for. Happy building!
I got the answer here:
http://tech.sarathdr.com/questions/question/gradle-is-failing-with-new-android-sdk-versio-zipalign-is-missing
It says:
New android sdk version (23) does not contain the file zipalign file. You can download the old version of android sdk and copy zipalign file to the tools folder
I got this error before, here's what I have done
Go to
C:\...\Users\your-name\AppData\Local\Android\sdk\build-tools
you have to reach up to build tools.
than there you will get list of build tools.
Here you have to just copy Zipalign.exe from older to newer version .
It worked for me. I used it in BluetoothLegatt sample code.
In Windows, make sure your ANDROID_HOME is pointing to the right folder. For me it was:
C:\Program Files\adt-bundle-windows-x86_64-20140321
I updated it but I forgot to point to the newer SDK folder:
C:\Program Files\adt-bundle-windows-x86_64-20140702\sdk
Now I'm sure I'm using the last SDK tools for Android.
Ok, now update the gradle script:
dependencies {
classpath 'com.android.tools.build:gradle:0.12.+'
}
and
android {
buildToolsVersion "19.1"
After I updated Android Studio to version 0.2.7, I got the following error:
org.gradle.tooling.GradleConnectionException: Could not execute build
using Gradle distribution
'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.: Could
not execute build using Gradle distribution
'http://services.gradle.org/distributions/gradle-1.6-bin.zip'.
This is my build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.5.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 10
targetSdkVersion 17
}
}
Does anyone know this error?
I had the same issue, can't say I know what caused it, but I just closed Android Studio, renamed the c:\users\MY USERNAME\.gradle directory to old-.gradle and then re-launched Android Studio.
Android studio then re-created the directory and automatically downloaded the gradle zip file and set it all up.
Seems to all be fine but to be honest I don't know what this directory is nor what the root cause of the problem was either, so proceed with caution and keep the old .gradle folder around for a bit until you're happy all is working fine.
For me the following two steps fixed the issue:
Make sure the Gradle build was successful
Android Studio - File - Invalidate Caches / Restart...
I suddenly had this issue in the morning after it working the night before. I tried all solutions here and failed.
I also tried installing another version of Gradle 1.8 and setting the gradle_home.
Tried restarting studio.
Eventually the tried and trusted method of restarting Windows worked for me.
All in all a frustrating waste of time.
I updated to 0.3.0 and had the same issue. I had to end up changing my Gradle version to classpath 'com.android.tools.build:gradle:0.6.1+' and in build.gradle and also changing the distributionUrl to distributionUrl=http\://services.gradle.org/distributions/gradle-1.8-bin.zip in the gradle-wrapper.properties file. Then I did a local import of the Gradle file. That worked for me.
I had this issue as well and jaywhy13 answer was good but not enough.
I had to change a setting: Settings -> Gradle -> MyProject
There you need to check the "auto import" and select "use customizable gradle wrapper". After that it should refresh gradle and you can build again. If not try a reboot of Android Studio.
First of all, JDK environment variable settings :
e.g) JAVA_HOME -> C:\develop\java\jdk\jdk1.8.0_25
path -> %JAVA_HOME%\bin;
eclipse
Window -> preferences -> Gradle -> Arguments -> Worksapce JRE check -> jdk(jdk1.8.0_25) choice
again Run -> gradle build :)
1- delete .gradle folder in the root directory of the app
2- invalidate cache and restart
As per answer by WarrenFaith, go to:
Settings -> Gradle -> Project-level settings
Change to Use customizable gradle wrapper.
Click OK and watch it build. If you still get an error at that stage, go back to:
Settings -> Gradle -> Project-level settings
Change it back to Use default gradle wrapper (recommended)
Click OK. That fixed it for me.
I had the same issue and i solved it by deleteing gradle-wrapper.jar and gradle-wrapper.properties file of Gradle wrapper then clean rebuild work for me.
I entered:
[C:\Users\user\].gradle\caches\1.8\scripts directory and deleted its content.
I didn't had to restart anything, just removed scripts content any rerun it.
For me, when using IntelliJ IDEA, this error arose because I had the Java SDK, rather than an Android SDK, set at the Project level.
My fix:
IntelliJ > File > Project Structure ...
Project > Project SDK > [Select] 'Android API 19 Platform (java version "1.7.0_40")'
I'm on:
IntelliJ IDEA: 13.1.3
Gradle: 1.10
Android Plugin for Gradle: 0.9.+
I had the same problem on Ubuntu with Eclipse 4.3 (Kepler) and the problem was that I created the project with a minus-sign in it.
I recreated the project with no specialchars and it all worked fine
I had the same Gradle build problems in Eclipse and by doing the following steps, the problems were solved:
set up project to use correct java version of java
project properties-> java build path -> jre system (edit the current one, and add the correct java jdk or jre there)
window->Preferences ->Gradle->Arguments-> Workspace JRE (set to the correct one)
Hope this will help those who have the same problems.
This happened to me after a java update, few things to check if you are sure your path has been set before:
if the path doesn't match the latest java install folder, change it (if your in eclipse check the eclipse.ini too to make sure your using your systems default vm (ie no VM tag) )
go to the java directory, there should be a 'jdk' and a 'jre' in the path, for example:
C:\Program Files (x86)\Java\jdk1.8.0_72\jre
if not you probably installed the JRE only not the JDK that
finally if the lib folder of the jdk (not jre) doesnt contain tools.jar then you have a problem with the install
I had a similar problem after doing brew install gradle. Perhaps it was because it was an older version. So I uninstalled and instead followed the gradle website's install instructions and then when I did gradle eclipse I no longer had the could not execute build using gradle distribution error.
This problem occurred to me when I edited the configurations in Android Studio to use the Desktop. However, using the default(android) seems to work well without any issues.
To correct this mistake very easily,
If you read logs. The problem occurs because of the sudden shutdown of the IDEA. And the log files do not correctly write data. Just delete the file on the path
C:/Users/{UserName}/.Gradle/demon/{gradleVersion}/registry.bin.lock.
I tried to add a Maven dependency to my project, which uses Gradle, by adding these lines to the build.gradle file in Android Studio:
repositories {
mavenCentral()
}
dependencies {
compile files('libs/android-support-v4.jar')
compile 'org.roboguice:roboguice:2.0'
}
The project seems to compile well, but there's no way to reference Roboguice classes inside my project's code. I feel like I'm missing something, namely, how does Gradle download the dependency and where will it store it? How should I fix my project?
Using the command line, in the root of your project, run :
./gradlew clean && ./gradlew build
Then recompile your project in studio and you should see your new dependencies.
EDIT: At the time of the answer, Android studio didn't propose the "Gradle sync" button. It now does, so rather than using the command line, you can hit the button, and it will basically run ./gradlew clean && ./gradlew build for you.
Anyway, it's always good to know how to do it in command line :)
The name of the button is: Sync Project with Gradle Files
See the screenshot below.
On Android Studio I just press the Sync Project with Gradle File button, left of the AVD Manager did the job. No restart, no ./gradlew clean or ./gradlew build.
You can also navigate through Tools-->Android-->Sync Project with Gradle File.
I was having the same problem. I tried all solutions suggested without success. Then I simply closed and opened again Android Studio and it worked!
Nothing here worked for me. What did work was File -> Invalidate Caches / Restart...
This is an extremely annoying bug, that happens way more often that it should. The build tools should not be a hindrance to development.
go to intellij preferences and enable gradle auto import dependencies