I have new clear android app. I want to add volley to my app to make HTTP request. I am developing app with Android studio using Gradle. Here is screenshot for my app:
Ass you see i am going to add volley to my app adding this line of code com.mcxiaoke.volley:library-aar:1.0.0 to build.gradle file
I tried to add Retrofit too. But it gives same type of error: Failed to resolve: bla bla bla.
So i think in my situation gradle can not sync any other library different than com.android......
And i have tried add this lines of code to my build.gradle too. but nothing is changing
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
repositories {
mavenCentral()
}
}
Please advise
Edit: After comments added build.gradle files for project and for module.
Project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.3.0'
}
}
allprojects {
repositories {
jcenter()
}
}
Module:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
defaultConfig {
applicationId "domain.testgradle"
minSdkVersion 11
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'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.mcxiaoke.volley:library:1.0.19'
}
Volley is now published by the Android Open Source Project on jCenter:
dependencies {
compile 'com.android.volley:volley:1.0.0'
}
You can use
com.mcxiaoke.volley:library-aar:1.0.1
Or its latest version (Not aar)
compile 'com.mcxiaoke.volley:library:1.0.19'
And set
buildToolsVersion "23.0.1"
and use
'com.google.code.gson:gson:2.3'
Add this
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:+'
compile 'com.mcxiaoke.volley:library:1.0.19'
}
Related
I am creating a blank project in which I add mapbox navigation package compile 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.6.3' in the gradle file. It shows error in appcompat file like this:-
Error:Failed to resolve: com.android.support:appcompat-v7:26.1.0
eventhough I use different version of Appcompat file. Before adding navigation package, everything was fine. Can someone please help me to find out this weird error.
Here is my app's gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.aadhilahmed.test7"
minSdkVersion 15
targetSdkVersion 25
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:25.3.1'
compile 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.6.3'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Specify:
compile ('com.mapbox.mapboxsdk:mapbox-android-navigation:0.6.3') {
transitive = false;
}
Try this.Starting from version 26 of support libraries make sure that the repositories section includes a maven section
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com"
}
}
}
For Gradle build tools plugin version 3.0.0
allprojects {
repositories {
jcenter()
google()
}
}
I created an Android library named "core" that use the Logger library (https://github.com/orhanobut/logger).
Here its build.gradle:
apply plugin: 'com.android.library'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
minSdkVersion 16
targetSdkVersion 25
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'])
compile 'com.orhanobut:logger:1.15'
compile 'com.android.support:appcompat-v7:25.0.1'
testCompile 'junit:junit:4.12'
}
Then I build a .aar of core library.
I add this library as a dependency into my application, by putting the .aarcore files in the libs folder.
That's the build.gradle of my application :
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.1"
defaultConfig {
applicationId "com.package.test"
minSdkVersion 16
targetSdkVersion 25
multiDexEnabled true
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
jcenter()
flatDir {
dirs 'libs'
}
}
dependencies {
compile 'com.mypackage:core:1.0#aar'
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'
})
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:25.0.1'
compile 'com.android.support:multidex:1.0.1'
}
As you can see I have multidex activated.
It compile just fine but at runtime, at the first call to Logger I get an exception:
stack=java.lang.NoClassDefFoundError: Failed resolution of: Lcom/orhanobut/logger/Logger;
Even if I set transitive = true
compile (com.mypackage:core:1.0#aar) {
transitive=true
}
it doesn't work.
Thank you !
I had to do a couple of things in concert to get it to work.
1) In your library project
Add the following to your project-level gradle file:
buildscript {
dependencies {
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
}
}
Be sure to use the right version of the plugin for your gradle version, check here.
Add the following to your module-level gradle file:
apply plugin: 'com.github.dcendents.android-maven'
group='com.github.YourPackage'// Doesn't have to be github, just an example
Also in this file, make sure your dependencies (the ones you want to be transitive) use api instead of implementation if you are using Gradle 3.4+. If you are using a version of Gradle <3.4, compile is the way to go. Example:
dependencies {
api 'com.google.android.gms:play-services-location:15.0.1'
}
2) In your app project (which uses the library)
Add the following to your module-level gradle file:
dependencies {
implementation('com.github.YourPackage:yourRepo:version#aar') {
transitive=true
}
}
Add the following to you project-level gradle file (but this will depend on where your library is served from, for me it's jitpack):
allprojects {
repositories {
...
maven {
url 'https://jitpack.io'
credentials { username 'yourAuthKey' }// Only for private repositories
}
}
}
Note: You shouldn't add the auth key as a string in build.gradle, put it in a property in your gradle.properties file.
Note 2: JitPack allows you to use for example development-SNAPSHOT as a version number for a gradle dependency. Android Studio caches these dependencies and will not re-download it when you push to your development branch. To overcome this, use commit hashes as version numbers during development or clear (delete) the cache files, located on Windows at ~/.gradle/caches/modules-2/metadata-x.xx/descriptors/com.github.YourPackage/yourRepo. (Needles to say, I learned this the hard way).
I'm trying to reference SpotifyWebApi in AndroidStudio. I'm using the instructions here
https://github.com/kaaes/spotify-web-api-android/blob/master/README.md
However I get the error
Error:Failed to resolve: :spotify-web-api-android-0.1.0:
when I try to build.
How can I fix this? I have AndroidStudio 1.2.2
Here's my Module:app build.gradle file
apply plugin: 'com.android.application'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "app.com.example.android.spotifystreamerstage1"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'spotify-web-api-android-0.1.0', ext:'aar')
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
// Other dependencies your app might use
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.2.0'
}
spotify-web-api-android is not included maven central repository. the doc of the link has wrong info. I don't know why..
Alternatively I have found this link and next codes.
repositories {
maven {
url "https://github.com/z0lope0z/raws/raw/master"
}
mavenCentral()
}
dependencies {
compile 'kaaes.spotify.webapi.android:spotify-web-api-android:0.1.0'
}
My (Android Studio) project has two modules: an Android-Library (app) Module and a Google Backend Module. The app module accesses the backend. in my gradle dependencies (app) I have:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':Backend', configuration: 'android-endpoints')
compile ('com.google.android.gms:play-services-wearable:6.1.71') {
exclude module: 'support-v4'
}
I want to use the app library in other projects, so I tried a) exporting it to a aar-library and b) exporting it into a jar-library. It works during compile time. I can use all classes of the app-module. But when running this app, it gives me an error, that it does not find the class that is the Interface between app and backend modules (as part of the backend).
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/cluedup/voicecontrols/backend/apiVoiceForm/model/VoiceFormBean;
Does anybody have an idea of how I can get this to work?
EDIT: Here are the complete gradle-files:
Library-App:
apply plugin: 'android-library'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.cluedup.voicecontrols"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs', '../backend/libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(path: ':Backend', configuration: 'android-endpoints')
compile ('com.google.android.gms:play-services-wearable:6.1.71') {
exclude module: 'support-v4'
}
}
Importing app
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.1"
defaultConfig {
applicationId "com.cluedup.voicecontrols.sample"
minSdkVersion 19
targetSdkVersion 21
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
flatDir {
dirs 'libs'
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile ('com.google.android.gms:play-services-wearable:6.1.71') {exclude module: 'support-v4'}
compile(name:'app-debug', ext:'aar'){transitive=true}
}
Here is what works for me - it seems like a hack for me, though! So if someone has a better solution, I'll still would be glad to hear about
Step 1: Create a jar of the backend-module. Actually, the jar of the backend is produced as byproduct when trying to publish the whole app in the sonatype central repository. I followed this example (http://gmariotti.blogspot.de/2013/09/publish-aar-file-to-maven-central-with.html) to prepare for the upload.
As a result, I found a jar-file of the backend in the ../backend/build/libs Directory.
Step 2: Remove the dependency of the app to the backend-module and replace it with a dependency to the created jar-file
// DO NOT USE compile project(path: ':Backend', configuration: 'android-endpoints')
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}
Step 3: create the aar-file of the app with gradlew assemble
Step 4: add the jar of the backend and the aar of the app as dependencies in the importing Project
compile(name:'app', ext:'aar'){transitive=true}
compile(name:'Backend-0.0.2', ext:'jar'){transitive=true}
I am using android-studio 0.6.1 and have all necessary google repositories installed in SDK manager: however when I try to build a project, gradle says about unresolved dependency:
Unresolved dependencies:
Error:com.google.maps.android:android-maps-utils:+
My build.gradle looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 12
targetSdkVersion 19
versionCode 1
versionName '0.1'
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile project(':library')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.google.android.gms:play-services:+'
compile 'com.google.maps.android:android-maps-utils:+'
}
I know I can just import all necessary instruments in library folder, however I would like to resolve this problem. Do you have any suggestions?
EDIT:
Found a way to solve it:
Looks like the problem was in absense of
compile 'com.android.support:support-v4:19.0.1'
in build.gradle, also I had to empty 'library' folder and delete the line in order to avoid 'duplicate packages' problem with support libraries:
compile project(':library')
So my final build.gradle file looks like this:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.11.+'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 12
targetSdkVersion 19
versionCode 1
versionName '1.0'
}
repositories {
mavenCentral()
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.google.android.gms:play-services:4.4+'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
The error is
Unresolved dependencies:
Error:com.google.maps.android:android-maps-utils:+
I'd say double check that you've got the dependency correctly defined. Looking at the Map Utils website leads me to believe you might want to declare the dependency with a version.
Replace
compile 'com.google.maps.android:android-maps-utils:+'
to
compile 'com.google.maps.android:android-maps-utils:0.3+'
Do a Gradle Sync and everything should build correctly.
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
// Support Libraries
compile 'com.google.android.gms:play-services:4.1.32'
compile 'com.android.support:support-v4:19.0.1'
compile 'com.google.maps.android:android-maps-utils:0.3+'
}
com.google.android.gms:play-services:3.1.36 can be downloaded by going to your SDK Manager and installing the Extras->Google Repository package (you may want to install the Extras->Android Support Repository as well while you are there). These allow Gradle to automatically use these resources without the need for library projects or jars manually added to your project.
Try to replace this:
compile 'com.google.maps.android:android-maps-utils:0.3+'
with this
compile 'com.google.android.gms:play-services-maps:9.4.0'