Android Studio Gradle project sync complete with errors - android

I recently decided to learn Android programming, so I installed Android Studio and Android SDK on my Ubuntu machine. The issue is when I build a new project, it says :
Gradle Sync completed with some erros
and the log is :
/home/moein/apps/android-studio-projects/Testapp/app/build.gradle
Error:Error:line (24)Failed to resolve: com.android.support:appcompat-v7:23.+
Error:Error:line (23)Failed to resolve: junit:junit:4.12
my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.example.moein.testapp"
minSdkVersion 23
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'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.0.0'
}

Do you have this in your build.gradle file:
compile 'com.android.support:appcompat-v7:23.3.0'

The most probable reason for such errors is you do not have all support libraries installed. Go to SDK manager and install all the supporting repositories. For more details you can visit this answer.

These are the correct version that you can add in your build.gradle according to the API needs.Use it by your requirement.
API 21:
compile 'com.android.support:appcompat-v7:21.0.1'
OR
compile 'com.android.support:appcompat-v7:21.0.2'
OR
compile 'com.android.support:appcompat-v7:21.0.3'
API 22:
compile 'com.android.support:appcompat-v7:22.0.0'
API 23:
compile 'com.android.support:appcompat-v7:23.2.0'

Try Installing the following Highlighted item:

I found the answer to this problem.
I used to get it whenever I open a new project.
Just paste these lines in build.gradle (module:app)
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
Sync it again it will probably solve your problem.

Related

Failed to resolve: com.google.android.gms:play-services:9.6.0 when syncing project

I'm trying to use Google Play Services on my Android app to get the device's last known location, but when I try to add the gradle dependency:
compile 'com.google.android.gms:play-services:9.6.0'
I get the following error:
A problem occurred configuring project ':app'.
Could not resolve all dependencies for configuration ':app:_debugCompile'.
Could not find com.google.android.gms:play-services:9.6.0.
Searched in the following locations:
https://jcenter.bintray.com/com/google/android/gms/play-services/9.6.0/play-services-9.6.0.pom
https://jcenter.bintray.com/com/google/android/gms/play-services/9.6.0/play-services-9.6.0.jar
file:/home/user/Android/Sdk/extras/android/m2repository/com/google/android/gms/play-services/9.6.0/play-services-9.6.0.pom
file:/home/user/Android/Sdk/extras/android/m2repository/com/google/android/gms/play-services/9.6.0/play-services-9.6.0.jar
file:/home/user/Android/Sdk/extras/google/m2repository/com/google/android/gms/play-services/9.6.0/play-services-9.6.0.pom
file:/home/user/Android/Sdk/extras/google/m2repository/com/google/android/gms/play-services/9.6.0/play-services-9.6.0.jar
Does anyone know how to fix this? Thanks!
EDIT
Here's my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "app"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.0'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile group: 'org.powermock', name: 'powermock-mockito-release-full', version: '1.6.4'
compile 'org.mockito:mockito-core:1.10.19'
compile 'com.google.android.gms:play-services:9.6.0'
}
Update your SDK's Android Support Repository and Google Play services first. See if it syncs after.
This could be happening due to google play services SDK not being installed in your android studio package. Follow the Android Developers guide on how to set up google play services in your application. There is a link in it to facilitate on how to set up SDK before you add the dependencies in your package.
Google Developers Guide : Google Play services setup
In your project level build.gradle file, under buildscript > dependencies,
classpath 'com.google.gms:google-services:3.0.0'

Error:(28, 13) Failed to resolve: com.squareup.okhttp3:okhttp:3.2.0

I have a problem with android studio.
I have added the .jar file of okhttp from this link : https://github.com/square/okhttp to my libs directory on my android studio. and when I try to add this line : compile 'com.squareup.okhttp3:okhttp:3.2.0' in the dependencies in build.gradle(Module:app), after trying to syncing it I get error 28, 13. Actually after researching I found out that I can't compile anything in dependencies and sync it remember that I have checked my "android SDK build tool" is installed.
hear is the whole of my code in build.gradle(app) directory:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.kasra.stormy"
minSdkVersion 14
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'], )
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile files('libs/okhttp-3.2.0.jar')
compile 'com.squareup.okhttp3:okhttp:3.2.0'
}
I'll be very glad and thankful if someone help me fix this problem.
Thank you very much:)
Either your internet is bad and you can't download that file from JCenter, or you are just missing a repositories section in your gradle file.
apply plugin: 'com.android.application'
repositories {
jcenter()
}
Also, if you are going to be compiling using gradle instead of a JAR file, then delete the file libs/okhttp-3.2.0.jar and remove the line that says compile files('libs/okhttp-3.2.0.jar').
It is also worth mentioning that you don't need any lines that start with compile files('libs/ because compile fileTree(dir: 'libs', include: ['*.jar'], ) already includes all JAR files within the libs/ folder.
It may help someone. In my case after update com.squareup.okhttp3 to the latest version, I got this error in Android Java libaray. Then I update the Java version to 1.8 which solved my problem.
targetCompatibility = '1.8'
sourceCompatibility = '1.8'
you should change the build.gradle(app):
use
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
instead of
compile 'com.squareup.okhttp3:okhttp:3.2.0'
or just follow the guide as mentioned here.
Just Replace the dependencies with folowng dependencies and they will work for sure.(100%).
if in future this issue comes again then go to https://square.github.io/okhttp/ and update your dependencies with latest one
//define any required ok http without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
//define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:4.9.0"))
Just remove compile files('libs/okhttp-3.2.0.jar')
I solved my problem by editing my build.gradle as below:
apply plugin: 'com.android.library'
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
minSdkVersion 21
targetSdkVersion 23
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.txt'
}
}
lintOptions {
abortOnError false
}
}
dependencies {
compile project(':library')
//compile('com.squareup.okhttp3:okhttp:+') {
// exclude group: 'org.json'
//}
//replaced as below:
compile 'com.squareup.okhttp3:okhttp:3.9.1'
}
Check your code in app.gradle
apply plugin: 'com.android.application'
repositories {
jcenter()}
OR
make your compile okhttp to offline mode, next you uncheck offline mode in setting -> gradle. and try it again
You will not need this
compile 'com.squareup.okhttp3:okhttp:3.2.0'
rather you will need
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
As of today the 30th of September 2020
Check https://square.github.io/okhttp/ for documentation

Warning:Module version com.android.support:appcompat-v7:23.1.0 depends on libraries but is a jar

When I created a new project in Android Studio bundle it is displaying the following error:
Warning:Module version com.android.support:appcompat-v7:23.1.0 depends on libraries but is a jar
Error:A problem occurred configuring project ':app'.
Could not find appcompat-v7.jar (com.android.support:appcompat-v7:23.1.0).
Searched in the following locations:
file:/C:/Users/PRASOON SHARMA/AppData/Local/Android/sdk/extras/android/m2repository/com/android/support/appcompat-v7/23.1.0/appcompat-v7-23.1.0.jar
I am not sure where I have made the mistake.
Here is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "com.example.prasoonsharma.club"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "0.1"
}
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:+'
}
It happen because of you use plus + on:
compile 'com.android.support:appcompat-v7:+'
Gradle is confused to decide the location that will be used to compiling the library, i.e. in file:/C:/Users/PRASOON SHARMA/AppData/Local/Android/sdk/extras/android/m2repository/ or in file:/C:/Users/PRASOON SHARMA/AppData/Local/Android/sdk/extras/android/support/v7/appcompat. So, the gradle script should look like this:
compile 'com.android.support:appcompat-v7:23.1.0'
Update Support Library to the latest version, and rebuild your project.

material-dialogs library:Failed to find: com.android.support:appcompat-v7:21.0.3

I am going to add material-dialogs library to my project but I get this error Error:Failed to find: com.android.support:appcompat-v7:21.0.3 This is build.gradle..Where is my mistake?Is sth wrong with my project?
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.peomtime.tosca.peomtime"
minSdkVersion 15
targetSdkVersion 21
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:support-v4:21.0.2'
compile 'com.android.support:appcompat-v7:21.0.+'
compile 'de.hdodenhof:circleimageview:1.2.0'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
//Core
compile 'com.github.gabrielemariotti.cards:cardslib-core:2.0.1'
compile 'com.github.machinarius:preferencefragment:0.1.1'
//compile 'com.github.nirhart:parallaxscroll:1.0'
compile project(':Parallax')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
compile 'com.afollestad:material-dialogs:0.6.3.1'
}
thank you so much for your help
Check that you have latest libraries installed in Android SDK Manager. For appcompat-v7:21.0.3, the packages need to be checked/updated are:
Android Support Repository
Android Support Library
Also, it's recommended to fix your dependencies version rather than using + to get latest version:
compile 'com.android.support:appcompat-v7:21.0.3'
Not sure why, but I added this repo from Afollestad to my build.gradle (project, not model) and everything was resolved.
repositories {
maven { url "https://jitpack.io" }
}
link

Android studio : Error : Module version com.android.support:support-v13:13.0.0 depends on libraries but is not a library itself

I try to add this lib (https://github.com/daimajia/AndroidImageSlider) to my project. I added the compile library in my gradle file, but i get an error :
apply plugin: 'com.android.application'
android {
compileSdkVersion 20
buildToolsVersion '20.0.0'
defaultConfig {
applicationId "com.pp.myapp"
minSdkVersion 16
targetSdkVersion 20
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.nostra13.universalimageloader:universal-image-loader:1.9.2'
compile 'com.iangclifton.android:floatlabel:1.0'
compile 'com.google.android.gms:play-services:5.0.89'
compile "com.android.support:support-v4:+"
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.0.9#aar'
}
And i get this error :
Error:Module version com.android.support:support-v13:13.0.0 depends on libraries but is not a library itself
Try adding this dependency:
compile 'com.android.support:support-v13:19.0.+'
You have to install the Android Support Library from the SDK, too.
I got the same error with an oauth library. It was fixed after a while when, tired of implementing new changes to the build.gradle like changing the support libraries, I discarded the changes on the file (via Sourcetree). It synchronized and automatically got fixed.
(Android Studio) It's a kind of magic.

Categories

Resources