Could not resolve com.android.tools.build:gradle:2.2.3 - android

I'm working on a mobile app project for work, but often when I attempt to run the application it gives me the following error:
Error:A problem occurred configuring root project 'projectName'.
Could not resolve all dependencies for configuration ':classpath'.
Could not resolve com.android.tools.build:gradle:2.2.3.
Required by:
:projectName:unspecified
No cached version of com.android.tools.build:gradle:2.2.3 available for offline mode.
I have tried a number of different things including deselecting the Offline work checkbox in the settings and then closing and re-opening Android Studio, but nothing seems to fix the issue. It may build fine for a few times in a row, but that same error keeps popping up. Then I have to try variations of building and making the app, or exiting and re-opening Android Studios. Nothing consistently works though. Any insight into what may be causing this issue and how it can be fixed would be appreciated.
***Update: Upon request I have added below my app gradle content
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
useLibrary 'org.apache.http.legacy'
dexOptions {
javaMaxHeapSize "8g"
}
defaultConfig {
applicationId "com.example"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug{
debuggable true
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile files('libs/gson-2.2.2.jar')
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.loopj.android:android-async-http:1.4.9'
}

It turns out the solution to my particular issue was relatively simple. The error message was a bit deceiving as this was not a problem with the offline mode switch, but rather confusion with the gradle file. Here are a few steps I took to fix the issue:
For Android Studio 2.3 go to File>Settings>Gradle and select the "Use default gradle wrapper" option. Also make sure the checkbox next to "Offline work" is unchecked just in case.
Click the "Apply" button
Within the build.gradle file (the one named after your project) under the "Gradle Scripts" section of Android Studio make certain that your current build gradle class path matches the current version of Android Studio. An example for Android Studio 2.3:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
}
}
Also within the Gradle Scripts section make sure that your gradle-wrapper.properties file is referencing the correct gradle file in the distribution URL. For example for gradle 3.3:
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
Navigate to C:\Program Files\Android\Android Studio\gradle and ensure there is a gradle folder with the same name as the gradle you are using. In my case I ensured there is a folder named gradle-3.3 with a zip file named gradle-3.3-all.zip. It is relatively easy to find this zip file online.
Delete the .gradle folder in C:\Users\yourUser with yourUser being whichever user your Android Studio project is under.
Close Android Studio and restart. It should begin the gradle sync process and rebuild the .gradle file.
For me when I did this it also complained about not finding the gradle-3.3-all.zip file in the .gradle folder. I was able to fix this by adding the gradle-3.3-all.zip file to C:\Users\yourUser.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9. I'm not sure if the folder has the same name for everyone, but whatever the name, that is the location I went to. If all this doesn't work I would try a variation of these steps, and hopefully it works for you.

The reason why it is failing is because it could not compile one of the libraries you included. Perhaps, try removing the one you suspect and try again. But most of the times, a rebuild of the project should resolve dependencies.

I've had the same pb, managed to resolve it adding in gradle.properties
systemProp.https.proxyHost=<my proxy hostname>
systemProp.https.proxyPort=<my proxy port>
I was missing HTTPS property, there was only HTTP setted so it was working sometimes, and not for the https links gradle used.

Related

Error: Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0 [duplicate]

My android app Gradle build is not syncing, since I updated my android studio to 3.2. I have updated everything in the dependencies and still getting the same error. Here are the dependency files that I use ( Including third-party libraries)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 28
defaultConfig {
applicationId "myappid"
minSdkVersion 19
targetSdkVersion 28
versionCode 32
versionName "3.2"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib:1.3.11"
implementation 'com.android.support:appcompat-v7:28.0.0-alpha1'
implementation 'com.android.support:design:28.0.0-alpha1'
implementation 'com.android.support:recyclerview-v7:28.0.0-alpha1'
implementation 'com.android.support:cardview-v7:28.0.0-alpha1'
implementation 'com.android.support:support-v4:28.0.0-alpha1'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-crash:28.0.0-alpha1'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation "org.jetbrains.anko:anko:$anko_version"
implementation 'com.github.GrenderG:Toasty:1.2.5'
implementation 'com.github.scottyab:showhidepasswordedittext:0.8'
implementation 'com.daimajia.easing:library:2.1#aar'
implementation 'com.daimajia.androidanimations:library:2.3#aar'
implementation 'com.google.android.gms:play-services-ads:17.1.2'
implementation 'com.google.gms:google-services:4.2.0'
implementation 'com.github.sd6352051:NiftyDialogEffects:v1.0.3'
implementation 'net.steamcrafted:load-toast:1.0.12'
implementation 'com.android.support:animated-vector-drawable:28.0.0-alpha1';
}
//apply plugin: 'com.google.gms.google-services'
//classpath 'com.google.gms:google-services:4.2.0'
However, I am getting the following error
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.
I have tried most things available through Google/Youtube searches. Implemented few answers given in StackOverflow too. But at the end of the day, it's the same error. What I am missing.
Please advice, how to resolve the issue. Thank you
So the problem doesn't necessarily needs to be in your application level build.gradle script (the one you posted). It can also be in the project level one or even in the maven-publish-aar.gradle one (if you have it). This means, you could be using deprecated Gradle features on any Gradle script.
I have updated everything in the dependencies and still getting the same error.
Most likely, the warning will be gone once you identify and replace any deprecated Gradle feature that's causing you this trouble. To do this, it will help you to actually add the mentioned --warning-mode=all flag to your Gradle command line options (on your Android studio compiler settings):
This will print the proper warnings for you to be aware of what are the specific deprecated features your app is using.
In my case (for example), I just added the enableFeaturePreview('STABLE_PUBLISHING') setting on the settings.gradle file and that did the magic (I'm using publishing{}).
Also, I know you asked this near a month ago, but, it might be useful for other people facing the same issue.
Had same issue yesterday extended to the #Hugo Allexis Cardona answer even after replacing deprecated Gradle feature having same issue because Old build folder is remains there so what I did is Remove app/build folder and sync gradle again and it work for me Thanks #Hugo Allexis Cardona
Delete App/Build Folder
The Problem is because of the inconsistency of external dependencies.
The Issue can be Easily Solved by migrating to Yarn Package Manager
Delete Node Modules
Delete Package.json.lock
yarn install
OR
Try Deleting android/app/build folder
The run the project by react-native run-android
I found easiest way to solve this issue. Go to projectName/android directory and in terminal enter the following command
./gradlew clean
And then, go to main project directory by entering following command
cd ..
And then start the project
react-native run-android
In my case
I Followed Hugo's answer
Changed the location of project.
Tried another android device [Build and success install]
Tried on my android device [Build and success install]

Android studio default project fails: Error:Failed to resolve: com.android.support:support-v4:25.2.0

I am literally just starting app development for the first time and the default project when I create a new one will not build. I have tried looking on Google and SO for these errors and have found some but their solutions do not work. Given that I have not edited the files at all, I presume it is an issue with Android Studio not being setup properly but can't figure it out. The errors are as follows:
Error:Failed to resolve: com.android.support:support-v4:25.2.0
Install Repository and sync project
Open File
Show in Project Structure dialog
Error:(23, 24) Failed to resolve: com.android.support.test.espresso:espresso-core:2.2.2
Install Repository and sync project
Show in File
Show in Project Structure dialog
Error:(26, 13) Failed to resolve: com.android.support:appcompat-v7:26.+
Install Repository and sync project
Show in File
Show in Project Structure dialog
The build.gradle file it points to is as follows:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.extremecomputing.spotzz"
minSdkVersion 17
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.google.android.gms:play-services-maps:11.0.1'
testCompile 'junit:junit:4.12'
}
I have tried with a previous project that I had created a few things I found online. Such as they had recommended the + in the version could cause unpredictable builds, but that wasn't it. One had recommended a few compile lines in the dependencies section, it changed the errors for a moment saying I needed to download something, I did then it went back to the original errors. I also have tried to make sure that the SDK tools are updated, and they appear to be. Any suggestions would be greatly appreciated.
Please be noted that support library from revision 25.4.0 to the latest, we need to add google maven. As in the release note says:
Important: The support libraries are now available through Google's
Maven repository. You do not need to download the support repository
from the SDK Manager. For more information, see Support Library Setup.
So you need to add the google maven to your root build.gradle like this:
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
Read more at Support Library Setup.
Try this:
in Android Studio, open Tools -> Android -> SDK Manager
under tab "SDK Tools" un-check the libraries causing problems
click "apply" to uninstall them
re-check the same libraries click "apply" to reinstall them
close SDK Manager and run Gradle sync / build
I had the same problem and it was due of an interference with another library.
In my case I had to comment:
compile 'com.onesignal:OneSignal:[3.5.3,4.0.0)
Now it builds

Cannot resolve symbol 'AppCompatActivity' , Cannot resolve symbol 'R', Could not download support-compat.aar

I installed Android Studio 2.1.3, and successfully created a new project (just call it ProA), it runs well in AVD. That time I had just only downloaded the SDK platform android-24. I created that project with the Minimum SDK API 14. Actually , I didn't download android-14 at that time.
Then later I downloaded android-14, android-15,android-21,android-23, tried to create a new project (call it ProB), but many errors occurred there.
The MainActivity's superclass is AppCompatActivity , but the error is Cannot solve symbol 'AppCompatActivity'.
There is a red line under the #Override tag over the onCreate() method, saying that Method does not override a method from its superclass
In onCreate() method ,the setContentView(R.layout.activity_main) code snippet shows Cannot resolve symbol 'R'.
The Messages window has a error message saying
A problem occurred configuring project ':app'.
Could not download support-compat.aar(com.android.support:-compat:24.2.0): No cached version available for offline mode
the overall picture is like this: the overall error image(click to see)
the content of app\src\build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
defaultConfig {
applicationId "com.example.zhangsir.aftervpn"
minSdkVersion 14
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
}
the content of gradle\build.gradle:
// 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.3'
// 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
}
the screenshot of the standalone sdk manager (click to see)
modified at 2016 Aug,27
I have downloaded all the Android SDK Build-tools:
What can I do to solve this problem?
go to File >Invalidate Caches & Restart -> Invalidate & Restart
Update
download Android SDK Build-tools 24.0.1
Sometimes, It gets these errors, most of the time we use sync Project if it didn't hover mouse to
Build >Clean Project >Rebuild Project
If this also, didn't fixed the problem then you might have done something wrong in gradle. You can update gradle if none of these works..
And One more thing I just saw in your question API 14 is not supported by AppCompactActivity so, you must extend Activity for that. AppCompactActivity supports from API 15. For more information see this
Try re-downloading the Android Support Repository from the Sdk manager.
Also update the Android Sdk, Platform-tools, Build Tools, Google Support Library to the Latest version.
Problem solved!
this Messages window in this picture click to see
says Could not download support-compat.aar (com.android.support-compat:24.2.0): No cached version available for offline mode
So I checked the first project which is OK, compare the app\src\build.gradle files in the two projects. the OK one's dependencies is like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
}
while the error one's dependencies is like this:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
}
So I modified the error one's dependencies, then Build->Clean Project, Build->Rebuild Project , it's OK now!
The basic reason is that my network is not available to google's server, many things cannot be downloaded.
If your Android Studio showing that cannot resolve symbol AppCompatActivity or cannot resolve symbol R then you can do one simple thing which is SYNC GRADLE. Click Here for the purpose of demonstration, you can watch it.
Simple Solution Here:
If your Android Studio showing that cannot resolve symbol AppCompatActivity or cannot resolve symbol R then you can do one simple thing which is SYNC GRADLE.
"Tools" -> "Android" -> "Sync Project with Gradle Files"
Click Here for the purpose of demonstration, you can watch it.

Android Studio 1.3 will not work with jcenter() Android Repository

Project build.gradle
buildscript {
repositories {
jcenter()
}
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
}
}
allprojects {
repositories {
jcenter()
}
}
Module build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "23.0.0 rc3"
defaultConfig {
applicationId "com.example.mark.god_dam_supportlib"
minSdkVersion 15
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.android.support:appcompat-v21:22.2.1'
compile 'com.android.support:appcompat-v7:22.2.1'
}
tried:
Putting the URL for bintray in the jcenter()
.
Disable offline mode
Made sure jcenter was in Project Structure - > Project - > [Android Plugin Repository && Default Library Repository].
Toggled disable offline mode.
Removed and reinstalled Android Support Repository,
Android Support Library (many times).
No network proxy.
Set the .gradle to 777.
No Matter what get on a gradle sync:
Error:(25, 13) Failed to resolve: com.android.support:appcompat-v21:22.2.1
Install Repository and sync projectShow in FileShow in Project Structure dialog
Click on “ Install Repository and sync project”
Error message in the “Install Missing Components” dialog:
Loading SDK information...
Ignoring unknown package filter 'extra-android-m2repository'Warning: The package filter removed all packages. There is nothing to install.
Please consider trying to update again without a package filter.
As well in red at the bottom of “Install Missing Components” dialog”
Imstailed Failed: Please check your network conection and try again. You may continue creating your project, but it will not compile correctly without the missing components
On a Gradle build get:
Error:A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not find com.android.support:appcompat-v21:22.2.1.
Searched in the following locations:
https://jcenter.bintray.com/com/android/support/appcompat-v21/22.2.1/appcompat-v21-22.2.1.pom
https://jcenter.bintray.com/com/android/support/appcompat-v21/22.2.1/appcompat-v21-22.2.1.jar
file:/home/usr/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v21/22.2.1/appcompat-v21-22.2.1.pom
file:/home/usr/Android/Sdk/extras/android/m2repository/com/android/support/appcompat-v21/22.2.1/appcompat-v21-22.2.1.jar
file:/home/usr/Android/Sdk/extras/google/m2repository/com/android/support/appcompat-v21/22.2.1/appcompat-v21-22.2.1.pom
file:/home/usr/Android/Sdk/extras/google/m2repository/com/android/support/appcompat-v21/22.2.1/appcompat-v21-22.2.1.jar
Required by:
Name_ofApp_folder:app:unspecified
Checked Google, Stack Over Flow.
Box is an Ubuntu 14.04 LTS straight up desktop.
Went as far as trying to down load the Android Support Repository manually could find a download page.
As An Aside used these “ Android Support Repository” first quarter of the year with out any grief (need to update one!).
Completely and totally out of ideas and getting dangerously low on patience as well
Failed to resolve: com.android.support:appcompat-v21:22.2.1 Install Repository and sync project
That is because there is no artifact named com.android.support:appcompat-v21. It is called com.android.support:appcompat-v7, and you already have a compile statement for it. Delete the compile statement for com.android.support:appcompat-v21.
Note that none of this has anything to do with JCenter, despite your question title.

Java finished with non-zero exit value 2 - Android Gradle

I'm getting this error executing my Android app (I cleaned it and then built it, but the error is still present)
Sync: OK
Make Project: OK
Clean: OK
Run: Error
Error:Execution failed for task ':app:dexDebug' .com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_25\bin\java.exe'' finished with non-zero exit value 2
My gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.rzr.rzevallosr.miappdepruebas"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
// This library handles authentication and authorization
compile 'com.spotify.sdk:spotify-auth:1.0.0-beta9#aar'
// This library handles music playback
compile 'com.spotify.sdk:spotify-player:1.0.0-beta9#aar'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:recyclerview-v7:21.0.+'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile files('libs/spotify-web-api-android-master-0.1.0.jar')
compile files('libs/okio-1.3.0.jar')
}
EDIT: I didn't see "compile fileTree(dir: 'libs', include: ['*.jar'])" it was compiling twice my libraries, so i just comment:
//compile 'com.squareup.retrofit:retrofit:1.9.0'
//compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
//compile 'com.squareup.okhttp:okhttp:2.2.0'
//compile files('libs/spotify-web-api-android-master-0.1.0.jar')
//compile files('libs/okio-1.3.0.jar')
and it works fine.
This issue is quite possibly due to exceeding the 65K methods dex limit imposed by Android. This problem can be solved either by cleaning the project, and removing some unused libraries and methods from dependencies in build.gradle, OR by adding multidex support.
So, If you have to keep libraries and methods, then you can enable multi dex support by declaring it in the gradle config.
defaultConfig {
// Enabling multidex support.
multiDexEnabled true
}
You can read more about multidex support and developing apps with more than 65K methods here.
For me the problem was, i had put a unnecessary complie library code in build.gradle
dependencies {
compile 'com.google.android.gms:play-services:7.5.0'
}
which was causing over 65k methods, so removed it,gradle sync, cleaned project, and then ran again and then this error stopped.
I needed just maps and gcm so i put these lines and synced project
compile 'com.google.android.gms:play-services-gcm:7.5.0'
compile 'com.google.android.gms:play-services-location:7.5.0'
Hi people i again encountered this problem and this time it was because of changing build tools version and it really required me to enable multidex..so i added these my app's build.gradle file..
defaultConfig {
applicationId "com.am.android"
minSdkVersion 13
targetSdkVersion 23
// Enabling multidex support.
multiDexEnabled true
}
dexOptions {
incremental true
javaMaxHeapSize "2048M"
jumboMode = true
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:multidex:1.0.1'
}
And create a class that extends Application class and include this method inside the class..
#Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
also include in OnCreate method too
#Override
public void onCreate() {
MultiDex.install(this);
super.onCreate();
}
Just in case if someone still struggling with this and have no clue why is this happening and how to fix. In fact this error
Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdkx.x.x_xx\bin\java.exe'' finished with non-zero exit value 2
can have many reasons to happen but certainly not something related to your JDK version so don't wast your time in wrong direction.
These are two main reasons for this to happen
You have same library or jar file included several places and some of them conflicting with each other.
You are about to or already exceeded 65k method limit
First case can be fixed as follows:
Find out which dependencies you have included multiple times. In order to do this run following command in android studio terminal
gradlew -q dependencies yourProjectName_usually_app:dependencies --configuration compile
this will return all the dependencies but jar files that you include from lib folder
try to get rid of duplication marked with asterisk (*), this is not always possible but in some cases you still can do it, after this try to exclude modules that are included many times, you can do it like this
compile ('com.facebook.android:facebook-android-sdk:4.0.1'){
exclude module: 'support-v4'
}
For the second case when you exceeding method limit suggestion is to try to minimize it by removing included libraries (note sounds like first solution) if no way to do it add multiDexEnabled true to your defaultConfig
defaultConfig {
...
...
multiDexEnabled true
}
this increases method limit but it is not the best thing to do because of possible performance issues
IMPORTANT adding only multiDexEnabled true to defaultConfig is not enough in fact on all devices running android <5 Lollipop it will result in unexpected behavior and NoClassDefFoundError. how to solve it is described here
I didn't know (by then) that "compile fileTree(dir: 'libs', include: ['*.jar'])" compile all that has jar extension on libs folder, so i just comment (or delete) this lines:
//compile 'com.squareup.retrofit:retrofit:1.9.0'
//compile 'com.squareup.okhttp:okhttp-urlconnection:2.2.0'
//compile 'com.squareup.okhttp:okhttp:2.2.0'
//compile files('libs/spotify-web-api-android-master-0.1.0.jar')
//compile files('libs/okio-1.3.0.jar')
and it works fine. Thanks anyway! My bad.
I had the same issue and I fixed removing the library that were unnecessary
compile fileTree(dir: 'libs', include: ['*.jar'])
I removed that library and I could run the project without any problem.
Mine got solved by enabling multiDex for debug builds.
defaultConfig {
multiDexEnabled true
}
I Reject Embedded JDK ( in 32bit ) because embedded JDK is 64bit
Right click your Project -> Open Module Setting -> SDK Location -> Uncheck Use embedded JDk then set your JDK Path, eg in Ubuntu /usr/lib/jvm/java-8-openjdk-i386
Possible problem: You have exceeded dex 65k methods limit, may be you added some library or several methods before problem occurred?
If You have already updated your SDK and You also using google-play-services then you need to take care of the dependency because there are some kind of conflics with :
Follow the below : compile 'com.google.android.gms:play-services:+' Replace by compile 'com.google.android.gms:play-services:6.5.87'
Note: Here '6.5.87' is the google-play-service version. I hope it will help..
I think it's conflicts of .jar file in your project.
I have removed android-support-v4.jar from libs folder and its working !!!
if your project gives error, check in your build.gradle file
dependencies {
}
In my case, the problem was that the new library (gradle dependency) that I had added was relying on some other dependencies and two of those underlying dependencies were conflicting/clashing with some dependencies of other libraries/dependencies in my build script. Specifically, I added Apache Commons Validator (for email validation), and two of its dependencies (Apache Commons Logging and Apache Commons Collections) were conflicting with those used by Robolectric (because different versions of same libraries were present in my build path). So I excluded those conflicting versions of dependencies (modules) when adding the new dependency (the Validator):
compile ('commons-validator:commons-validator:1.4.1') {
exclude module: 'commons-logging'
exclude module: 'commons-collections'
}
You can see the dependencies of your gradle module(s) (you might have only one module in your project) using the following gradle command (I use the gradle wrapper that gets created for you if you have created your project in Android Studio/Intellij Idea). Run this command in your project's root directory:
./gradlew :YOUR-MODULE-NAME:dependencies
After adding those exclude directives and retrying to run, I got a duplicate file error for NOTICE.txtthat is used by some apache commons libraries like Logging and Collections. I had to exclude that text file when packaging. In my build.gradle, I added:
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE.txt'
}
It turned out that the new library (the Validator) can work with slightly older versions of its dependencies/modules (which are already imported into my build path by another library (Robolectric)). This was the case with this specific library, but other libraries might be using the latest API of the underlying dependencies (in which case you have to try to see if the other libraries that rely on the conflicting module/dependency are able to work with the newer version (by excluding the older version of the module/dependecy under those libraries's entries)).
In my case, I got this error when there are 2 or more libraries conflict (same library but different versions). Check your app build.gradle in dependencies block.
There are two alternatives that'll work for sure:
Clean your project and then build.
If the above method didn't worked, try the next.
Add the following to build.gradle file at app level
defaultConfig {
multiDexEnabled true
}
Updating my Java SDK to the latest version 1.7.0_79 and updating the SDK Location under Project Structure solved the problem for me.
My problem was that apart from having
com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException: Process 'command
'/Library/Java/JavaVirtualMachines/jdk1.X.X_XX.jdk/Contents/Home/bin/java''
finished with non-zero exit value 2
I had this trace as well:
Uncaught translation error: java.lang.IllegalArgumentException:
already added: Lcom/mypackage/ClassX;
The problem was that I was adding the same class in two differents libraries. Removing the class/jar file from one of the libraries, the project run properly
For me i was adding the whole playstore dependencies
compile 'com.google.android.gms:play-services:8.4.0'
But i needed google map only , so i made it more specific and the error was resolved.
compile 'com.google.android.gms:play-services-maps:8.4.0'
in my case problem was build tools version which was 23.0.0 rc3 and i changed to 22.0.1 and my problem fixed.
You may be using a low quality cable/defected cable to connect your device to the PC, I replaced the cable and it worked for me.
This error is because of using more number of libraries.in my case 'compile 'com.google.android.gms:play-services-9.4.0' caused this error.To avoid this error use necessary libraries.for example if you want to use Maps in your app.Then use
compile 'com.google.android.gms:play-services-maps:9.4.0'.while adding google play services dependency specify the needed libraries only.by default it includes all the libraries.
In Your gradle.build file, Use this
"compile fileTree(dir: 'libs', include: ['*.jar'])"
And it works fine.
If you want to see what exactly is causing the error, try building your project via gradle terminal, like this ./gradlew assembleDebug --stacktrace --debug . I've seen the following error in my case com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536
This happened when I was trying to entegrate Google Maps to my project. To fix it, I simply checked libraries I was including
compile 'com.google.android.gms:play-services:9.8.0'
I simply changed it to
compile 'com.google.android.gms:play-services-maps:9.8.0'
and problem was gone
I had the same error after converting my project to Kotlin. My problem was that my jre location was changed to an invalid path during the process (I wonder why this could happen... made me waste time). Fixed it by doing this:
File > Project Structure > SDK Location
Unchecked the Use embedded JDK option, which was pointing to an old JDK installation, and selected the correct one:
/home/my_user/jdk1.8.0_101
After changing this, the error disappeared
WORKED FOR ME :)
i upgraded the java to the latest version 8 previously it was 7 and then go to OPEN MODULE SETTING right clicking on project and changed the jdk path to /usr/lib/jvm/java-8-oracle the new java 8 installed. And restart the studio
check in /usr/lib/jvm for java 8 folder name
I am using ubuntu

Categories

Resources