Android - Can’t add Okhttp dependency with Estimote SDK - java

Good evening,
I'm triying to add OkHttp library to my Android project, which uses Estimote Android SDK. It seems that the Estimote Android SDK has included that library (an older version), but the problem is that other dependencies I have included to my app (like Picasso) can't access to that dependencies, just my own classes can. Picasso, to initialize the image caching system, needs to instantiate OkHttpClient object by his own and this class can be found in the OkHttp library. But, it seems that a dependency can't access to another dependencies' library. I don't really know how to explain it...
If I add the OkHttp dependency to my Gradle, after 7 minutes of building, the build fails with a "dexDebug" error. That means that the same library is included twice (one in the Estimote SDK and other in my Gradle).
Here you can see my Gradle's dependencies field:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:recyclerview-v7:23.0.0'
compile 'com.android.support:cardview-v7:23.0.0'
compile 'com.android.support:design:23.0.0'
//compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'joda-time:joda-time:2.8.1'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile files('libs/FlurryAnalytics-5.6.0.jar')
compile(name: 'estimote-sdk', ext: 'aar') // This library has okhttp 2.2.0 included in it, but Picasso library can't access here...
}
Here you can see the piece of code that needs the Okhttp library.
Picasso.Builder builder = new Picasso.Builder(this);
OkHttpDownloader downloader = new OkHttpDownloader(this, Integer.MAX_VALUE);
// OkHttpDownloader is a Picasso's class, and then this needs OkHttpClient object from OkHttp library. But it seems that a library can't access to Estimote's library.
builder.downloader(downloader);
Picasso built = builder.build();
built.setIndicatorsEnabled(true);
built.setLoggingEnabled(true);
Picasso.setSingletonInstance(built);
Then, if the problem is solved, I want to change all my HttpRequest AsyncTasks to OkHttp requests.
Any ideas how to solve it? Maybe I can make something in the Gradle file, but I don't know what can I do...
Thank you very much.
Happy coding.

Related

Build app with api 26 but libs with api 24

I migrated to android studio 3.1
I use an external dependency which uses API 24. I can not do code changes here.
I need to build my app with API 26.
is it possible? how can this be done?
During various trials, I got this error
Gradle: Error: more than one library with the package name
'recyclerview'
app build.gradle
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.google.android.gms:play-services-gcm:15.0.1'
implementation 'com.google.android.gms:play-services-location:15.0.1'
implementation 'com.google.android.gms:play-services-places:15.0.1'
implementation project(path: ':libs:externalLib', configuration: 'default')
libs:externalLib build.gradle
dependencies {
compile 'com.android.support:recyclerview-v7:24.0.0-alpha2'
compile 'com.android.support:support-v4:24.0.0-alpha2'
}
Or can I target for API 26 while using 24.x everywhere as a workaround?
You 'must' add you library dependencies in app/build.gradle file.
error says recyclerview library is added twice first you have added it to your gradle and second your library is adding it.
you have to remove implementation 'com.android.support:recyclerview-v7:26.1.0' from your gradle file and contact developer of library to update his library or yourself update it and change its gradle to use version 26 of recyclerview and support library

Failed to resolve: com.android.support:support-v4:26.0.2

when i use this library :
compile 'co.ronash.android:pushe-base:1.4.0'
I get this error in gradle:
Failed to resolve: com.android.support:support-v4:26.0.2
I can't fix it.
There is a solution to be there library Ignored
'com.android.support:support-v4:26.0.2' from 'co.ronash.android:pushe-base:1.4.0' ?
Because I have already compiled a newer version of support-v4 library.
All my dependencies code in gradle :
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
compile 'com.android.support:appcompat-v7:26.0.0-alpha1'
compile 'com.android.support:support-v4:26.+' //--> its ok and no problem
compile 'uk.co.chrisjenx:calligraphy:2.2.0'
compile 'co.ronash.android:pushe-base:1.4.0' //--->this code is error Failed to resolve: com.android.support:support-v4:26.0.2
compile 'com.google.android.gms:play-services-gcm:11.0.4'
compile 'com.google.android.gms:play-services-location:11.0.4'
testCompile 'junit:junit:4.12'
}
There are a few reasons which can cause this kind of problem.
Checkout these solution, I guess it might help you:
1. Remove Pushe and try adding support-v4 library with version of 26.0.2 to make sure it gets downloaded and cached to your system.
compile 'com.android.support:support-v4:26.0.2' // or implementation
If it still can't be resolved then you have a problem getting it from it's repository server. checkout build.gradle(project:your_prj) and make sure this block is valid.
allprojects {
repositories {
google() // or maven { url 'https://maven.google.com/' } for lower gradles
jcenter()
}
}
If your country is included in sanction you might need to use a VPN to be able to get them. You can also use a proxy like Fod(also donate if you can since it's opensource) or shecan.
Remember all support libraries better be 26.0.2 to avoid conflict and crashing. Your support libraries are 26.0.0-alpha1 which is lower.
After you successfully added and cached support-v4 then try to add Pushe to your dependencies again.
! And also remember that pushe has a support-v4 bundled in it and it's not really needed for you to add it yourself
And Make sure you have
<uses-sdk tools:overrideLibrary="co.ronash.pushe" />
in you manifest. Therefore you can override it's libraries and dependencies.
At the end keep your SDK update.
Edit:
Current version of Pushe is using android support libraries. If you attend to use AndroidX be sure to enable jettifier in order to do runtime conversion.

how can i download AppCompatActivity librery for ADT

I have a problem with importing the package :
"import android.support.v7.app.AppCompatActivity".. i think because i should
download AppCompatActivity librery before importing it
Please, how can i download AppCompatActivity librery??
[1]: https://i.stack.imgur.com/mMPQs.png
No need to download it separately.You can fix it updating your "build.gradle(Module:app)" file. in order to do it you need to add your compiler dependencies for project.
Add this line to "build.gradle(Module:app)" file
compile 'com.android.support:appcompat-v7:25.3.0'
then Sync your project and make sure network connection is working.That's it :)
bellow is an example that shows where you add a compiler dependency to your project.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espressocore:2.2.2',{
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:design:25.3.0'
testCompile 'junit:junit:4.12'
}
To Setup Android Support Library :
The Android Support Repository package is provided as a supplemental download to the Android SDK and is available through the Android SDK Manager.
Follow the instructions below to obtain the Support Library files.
To download the Support Library through the SDK Manager:
1.Start the Android SDK Manager.
2.In the SDK Manager window, scroll to the end of the Packages list, find the Extras folder and, if necessary, expand to show its contents.
3.Select the Android Support Repository item.
4.Click the Install packages... button.
Then After Downloading,
Adding Support Libraries
In order to use a Support Library, you must modify your application's project's classpath dependencies within your development environment. You must perform this procedure for each Support Library you want to use.
To add a Support Library to your application project:
Make sure you have downloaded the Android Support Repository using the SDK Manager.
Open the build.gradle file for your application.
Add the support library to the dependencies section. For example, to add the v4 core-utils library, add the following lines:
dependencies {
...
compile "com.android.support:support-core-utils:25.3.1"
}
Then you can use your Support Library elements.

java.lang.NoSuchMethodError on compile

I'm trying to compile an Android project unsuccessfully. The error message is:
Execution failed for task ':mobile:_compileAppDebug'.
java.lang.NoSuchMethodError: com.google.auto.common.MoreTypes.asTypeElements(Ljavax/lang/model/util/Types;Ljava/lang/Iterable;)Lcom/google/common/collect/ImmutableSet;
Here are my module's gradle dependencies in which I specify a number of libraries including google Auto:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.google.dagger:dagger:2.0-SNAPSHOT'
provided 'com.google.auto.value:auto-value:1.0-rc1'
apt 'com.google.dagger:dagger-compiler:2.0-SNAPSHOT'
provided 'org.glassfish:javax.annotation:10.0-b28'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.f2prateek.dart:dart:1.1.0'
}
When I looked at the dependencies I thought I just needed google auto value since that is where the missing method resides but adding the provided does not resolve the issue.
The project gradle file includes the retrolambda plugin
dependencies {
classpath 'me.tatarka:gradle-retrolambda:2.5.0'
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
}
Can anyone help me identify which dependencies cause the compile error? Interestingly enough, when I copy the gradle files into an empty project everything runs fine.
Dagger 2.0-SNAPSHOT depends on an Auto SNAPSHOT which had an API change: https://github.com/google/dagger/issues/113
This is perfectly normal and acceptable thing for libraries which are under development. If you cannot tolerate an occasional broken build, do not depend on non-release versions in a manner that can change at any time without warning.
I ran in a similar issue. Some libary I'm using bundles Guava within the jar file.
Thus exluding this specific dependency from the apt configuration fixed the problem:
configurations {
apt.exclude module: 'artifactId-Of-Library'
}

Google Calendar API in Android Studio

I'm just a hobbyist programmer trying to access Google Calendar. I'm using Android Studio. I've downloaded all the Google Services from the Android SDK manager and set the dependencies. I've also tried following all of Google's documentation of how to do this here: Google Developers: Calendar API Client Library for Java, by adding the client libraries manually in the libs folder of the project.
Any time I do any of this the sample scripts say to type:
import com.google.api.etc...
No matter which way I do it "api" always gets highlighted in red and says it cannot be resolved. I have access to drive, maps, and a bunch of other google stuff, just not calendar.
Has anyone else experienced this problem? If so, how did you fix it? If you need more information from me I'd be happy to supply it.
Thanks!
This is what my build.Gradle dependencies currently looks like:
dependencies {
compile 'com.android.support:appcompat-v7:+'
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:+'
}
Print here code of your files Gradle.
You need it likes here, and put it into file build.gradle:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
}
UPDATE:
Easify method for adding library, then you can put it into file build.gradle:
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.apis:google-api-services-calendar:v3-rev84-1.18.0-rc'
}

Categories

Resources