Trouble with gradle in android studio - android

I know about this questions:
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
Could not resolve com.android.support:appcompat-v7:26.1.0 [duplicate]
Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project
And I've read this documentations:
Migrate to Android Plugin for Gradle 3.0.0
Migrating to Android 8.0
So I'm posting this question believing its not a duplicate.
I've installed Android Studio 3.4.1. I didn't have any previous version before and I started a new project.
Every setting in Gradle file have been set by Android Studio itself and I've checked them all.
I have already tried
invalidate and restart android studio
Could not resolve com.android.support:appcompat-v7:26.1.0 in Android Studio new project
Failed to resolve: com.android.support:cardview-v7:26.0.0 android
These are the file contents:
build.gradle (Module:app)
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
defaultConfig {
applicationId "com.example.myapplication"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
}
Top level build.gradle
// 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:3.4.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {url 'https://maven.google.com/'}
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/guardian/android' }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
gradle-wrapper.properties
#Mon Jun 10 17:40:01 IST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
I use google() in repositories as here clearly says:
// If you're using a version of Gradle lower than 4.1, you must instead use:
// maven {
// url 'https://maven.google.com'
// }
My gradle version is 4.1 so I don't need above code.
But I still get this error as the others have been asking about:
Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
androidx.constraintlayout:constraintlayout:1.1.3.
ERROR: Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
androidx.versionedparcelable:versionedparcelable:1.0.0.
ERROR: Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
androidx.lifecycle:lifecycle-runtime:2.0.0.
ERROR: Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
androidx.legacy:legacy-support-core-ui:1.0.0.
ERROR: Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
androidx.vectordrawable:vectordrawable-animated:1.0.0.
ERROR: Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
androidx.fragment:fragment:1.0.0.
I have also unchecked the offline check box from gradle and using default
Why should I get this error when I'm creating a new project in AS 3.4.1 and it has been set all the necessary settings?

You are trying to mix AppCompat and Jetpack dependencies, and you cannot do that.
I think you might not have the right repository setup for the Jetpack libraries (why it can't find any Jetpack libraries).
Don't use: implementation 'androidx.appcompat:appcompat:1.0.2' . (this is Jetpack) -- use AppCompat versions of this (besides - Jetpack is NOT consistent with Appcompat versions earlier then 28.x). Bottom line, get rid of anything that says (androidx).

Define repositories for both Appcompat and jetpack
allprojects {
repositories {
google()
jcenter()
maven {url 'https://maven.google.com/'}
maven { url "https://jitpack.io" }
maven { url 'https://dl.bintray.com/guardian/android' }
}
}
After that sync project with gradle.. let me know its working or not.

Replace
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:design:26.1.0'
with
implementation 'com.android.support:appcompat-v7:26.0.0'
implementation 'com.android.support:design:26.0.0'
EDIT:-
You should invalidate your cache and restart. Follow this steps file -> invalidate caches/Restart Then select invalidate and restart

Related

Android studio unable to build my app after gradle plugin updated

I updated the Gradle plugin yesterday and now the android studio is not able to build my app. The app shows the following error.
ERROR: Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
ERROR: Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.16.1].
Show Details
Affected Modules: app
WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been replaced with 'variant.getExternalNativeBuildProviders()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-avoidance.
To determine what is calling variant.getExternalNativeBuildTasks(), use -Pandroid.debug.obsoleteApi=true on the command line to display a stack trace.
Affected Modules: app
My app level build.gradle file looks like this:
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.mvp1stockmeter"
minSdkVersion 16
targetSdkVersion 28
versionCode 1
versionName "1.0"
multiDexEnabled true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
dataBinding
{
enabled true
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
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 'com.android.support:multidex:1.0.3'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.google.firebase:firebase-firestore:18.0.0'
implementation 'com.google.firebase:firebase-core:16.0.7'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation 'com.firebaseui:firebase-ui-auth:4.3.1'
implementation 'com.google.firebase:firebase-auth:16.1.0'
//implementation 'com.facebook.android:facebook-android-sdk:4.x'
implementation 'com.jjoe64:graphview:4.2.2'
}
apply plugin: 'com.google.gms.google-services'
My project level build.gradle file looks like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'io.fabric.tools:gradle:1.26.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
maven {
url 'https://maven.google.com/'
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I searched this on StackOverflow and google as well. But did not find any information. Please help. I am stuck here.
I don't have a clue why this is happening, but it is happening since yesterday, March 21 2019. I think it is a problem in the maven repository? Because the url where android studio is trying to get that library is down.
Anyway, the fix is to "manually" point AS to that missing dependency, adding this line into your build.gradle, inside dependencies{...}
implementation group: 'io.grpc', name: 'grpc-core', version: '1.16.1'
Then sync, then you can delete that line.
Well, I hope someone can explain what happened.
Adding mavenCentral() to allprojects{} section of project level build.gradle file has resolved this issue for me.
Adding mavenCentral() to buildScript{} section of project level build.gradle file has resolved this issue for me. Thanks for your support.
I had three build errors of the following type:
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve io.grpc:grpc-core:[1.28.0].
As with many of these android studio related issues,
File -> Invalidate Caches / Restart...
did the trick for me.
Delete this line :- testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"...It worked for me
Add mavenCentral() to your buildscripts->repositories and allprojects->repositories both places and sync the project.

Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.volley:volley:1.1.1

I tried to import android volley into my project, but it failed. I dont know what happened. This is the build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.root.wifi1"
minSdkVersion 22
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.volley:volley:1.1.1'
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'
}
And this is the build.gradle for project:
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
//maven { url "https://jitpack.io" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
I have tried using volley library version 1.1.1, 1.1.0, the one from mcxiaoke, and a few other versions, but none of them worked. I also tried to switch my gradle version, and also tried to create local library using android volley that I cloned. Someone suggested to add maven { url "https://jitpack.io" } to allproject repositories, I also tried it, but it also didnt work. Of course I have also tried to disable offline gradle from Settings menu, but it didnt change anything.
this is the error :
Unable to resolve dependency for ':app#debug/compileClasspath': Could not resolve com.android.volley:volley:1.1.1.
Unable to resolve dependency for ':app#debugAndroidTest/compileClasspath': Could not resolve com.android.volley:volley:1.1.1.
Unable to resolve dependency for ':app#debugUnitTest/compileClasspath': Could not resolve com.android.volley:volley:1.1.1.
Unable to resolve dependency for ':app#release/compileClasspath': Could not resolve com.android.volley:volley:1.1.1.
Unable to resolve dependency for ':app#releaseUnitTest/compileClasspath': Could not resolve com.android.volley:volley:1.1.1.
Everytime I changed the volley version the error was just like that too.
I dont know what to do now, please help
PS: if i comment/remove the volley dependency my project works 100% fine, and I dont use a proxy-protected internet
Try to add this
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}}
To your build.gradle and then make a Clean project also Invalidate Cache & Restart from file options should work.

Retrofit 2.4.0 with Gradle plugin 3.1.2

I have a very simple question. I'm an Android Developer returning back to development after a 6 months break and as usual everything has changed apparently. Here is my question:
Start a new Android project on Android Studio 3.1.2
Default Gradle plugin is 3.1.2
Added retrofit2 dependency to app's build.gradle
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
Started gradle sync
Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.squareup.retrofit2:retrofit:2.4.0. Open File Show
Details
Unable to resolve dependency for
':app#debugAndroidTest/compileClasspath': Could not resolve
com.squareup.retrofit2:retrofit:2.4.0. Open File Show Details
Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.squareup.retrofit2:retrofit:2.4.0. Open File Show Details
Unable to resolve dependency for ':app#release/compileClasspath':
Could not resolve com.squareup.retrofit2:retrofit:2.4.0. Open File
Show Details
Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.squareup.retrofit2:retrofit:2.4.0. Open File Show Details
I read the whole article about Gradle plugin 3 migration. It is no help.
Project build.gradle
// 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:3.1.2'
// 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
}
app level build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.xyz.xyz"
minSdkVersion 15
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
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'
}
if your PC is running on some proxy please add proxy in android studio or check your internet connection.
For Proxy follow below steps:
File -> Settings -> Appearence & Behaviour -> System Setting -> HTTP Proxy
add your Proxy
Otherwise check your internet connection
I run your code run with no errors. Try to Invalidate Caches/Restart from: File -> Invalidate Caches/Restart
what worked me is to trying to add it through the project structure dependency window
follow these steps :
1- File -> Project structure -> depencies
click apply then try to sync again and it worked fine for me.

How to remove all dependencies on android studio?

I have no internet connection on my machine (because of some reasons) and i want to use Android studio(3) on it with no dependency to the internet.
I Created a very simple (default) App but get lots of errors, I changed the gradle to the local and remove/set offline work option but nothing worked.
Errors:
Error:Unable to resolve dependency for ':app#debug/compileClasspath': Could
not resolve com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#debug/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#debugUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for ':app#release/compileClasspath':
Could not resolve com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#release/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
Error:Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.
Open File<br><a
href="Unable to resolve dependency for
':app#releaseUnitTest/compileClasspath': Could not resolve
com.android.support:appcompat-v7:26.+.">Show Details</a>
build.gradle(app):
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.example.administrator.myapplication"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.+'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
}
build.gradle(project):
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
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
For the first time you need to be connected to the internet so that all your dependencies could be fetched. Once that's done, you no longer need the internet.
But if you try building again, Android Studio (gradle) will still try to connect to internet to refresh the dependencies. If you can't be online then you need to tell Android Studio (i.e, gradle) to work offline.
Go to Android Studio's Preferences -> Build, Execution, Deployment -> Offline Work
Turn this option on and gradle will start to work offline.
Note: com.android.support:appcompat-v7:26.+. won't really work here. You need to mention the specific artifact id and not +.

Error:Could not find com.android.tools.build:gradle:3.3. Issue raise after upgrading gradle version for splunk:mint-android-sdk

My App was working fine, then i add com.splunk:mint-android-sdk, which required upper version of gradle, so i upgrade the gradle to from 2.1 to 3.3. after that i am facing issues. Please review my gradle file and help me out and please guide me how it work.( This is my first app but i want sure make its should be working fine in all scenario )
Error:Could not find com.android.tools.build:gradle:3.3.
Searched in the following locations:
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/3.3/gradle-3.3.pom
file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/3.3/gradle-3.3.jar
https://plugins.gradle.org/m2/com/android/tools/build/gradle/3.3/gradle-3.3.pom
https://plugins.gradle.org/m2/com/android/tools/build/gradle/3.3/gradle-3.3.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/3.3/gradle-3.3.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.3/gradle-3.3.jar
Required by:
:MyApp:unspecified
My gradleare
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.abc.myApp"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled= true
manifestPlaceholders = [onesignal_app_id: "hjaadsffsddd8-2e6hgf-4fdsasdfgb63-8dad5-1111111",
onesignal_google_project_number: "REMOTE"]
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support:cardview-v7:+'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
compile 'com.onesignal:OneSignal:[3.6.1,3.99.99]'
compile 'com.google.firebase:firebase-core:9.2.0'
compile 'com.google.firebase:firebase-messaging:9.2.0'
compile 'com.splunk:mint-android-sdk:5.2.1'
}
and
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
maven { url "https://plugins.gradle.org/m2/" }
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3'
classpath 'com.google.gms:google-services:3.0.0'
classpath 'com.splunk:mint-gradle-android-plugin:5.2.1'
}
}
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com" // Google's Maven repository
}
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Inside buildscript add google() then open terminal write command-- gradlew build and press enter.
repositories {
google()
jcenter()
}
NB: Make sure you are in active network connection
You changed Gradle plugin version, not Gradle version
Set your Gradle Plugin version to 2.3
Then open gradle/wrapper/gradle-wrapper.properties and change Gradle version at line distributionUrl
Please follow these steps :
Open Your project.
Go to the Left side of the Gradle button.
Click button above image show .
if this type of view you are not in offline mode.
Go to Build and rebucild the project.
The above worked for me.
This version of the gradle plugin doesn't exist.
classpath 'com.android.tools.build:gradle:3.3'
use the latest beta release:
classpath 'com.android.tools.build:gradle:3.0.0-beta6'
Instead if you would like to update gradle, update the distributionUrl in gradle-wrapper.properties.
I resolve my problem removing proxy configuration in file gradle.properties
I've got this error, and the problem was the antivirus Avast blocking android studio from download the files.
so I've disabled it temporary and also runned Android studio as an admin. this solved the problem.
In my case, I add maven { url 'https://maven.google.com' } at top of build script.
Go to the gradle wrapper properties and see if the gradle version in the distribution url matches the one in the build.gradle classpath's
I updated following line of
code: classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.google.gms:google-services:3.0.0'
and distributionUrl in gradle-wrapper.properties 'distributionUrl=https\://services.gradle.org/distributions/‌​gradle-3.3-all.zip'
and MOST IMPORTANT is FILE>SETTING>Build,Execution,Deployment>Build Tools>Gradles: Project-level settings: checked :Use default gradle wrapper(recommended)

Categories

Resources