I have one library project in which i have implemented volley library.
api 'com.android.volley:volley:1.1.0'
So i can use same library in main application.
But when i try to use in main application and try to build apk then issue is that Program type already present: com.android.volley.BuildConfig
But if i exclude volley from library project and comment classes that using volley, doing below line then i am able to build apk.
exclude group: "com.android.volley"
So how i can resolve this issue?
Try to remove the library from the module and from the project as well and try to implement volley
implementation 'com.android.volley:volley:1.0.0' on build.gradle of both module and project file.
That error generally means you have two dependencies that are both providing the same class, causing a conflict.There could be two copies of Volley
Like:
implementation 'com.mcxiaoke.volley:library:1.0.19'
implementation 'com.android.volley:volley:1.1.0'
You can only use one of these or the other. Make sure your dependencies only pull in one copy of the library.
(Note this not my own answer but found it on
https://github.com/google/volley/issues/239 which helped me fixing the issue)
I'm pretty new to android studio, but i got this error and i can't run my project. I saw a lot of answers which suggest to add the support-annotations dependency, but I'm using appcompat so i don't need that. Any thoughts?
Do you have the Android Support Library?
To do it add this to your build.gradle file of the "app" module:
dependencies {
...
implementation "com.android.support:support-annotations:27.1.0"
}
Then sync the project.
Sometimes you can do this automatically by pressing Alt+Enter over the error message and selecting the solution.
You need to fetch the libraries that contain the imports, in your build gradle file of your module add the line inside dependencies tag:
api 'com.android.support:support-annotations:X.X.X'
or
implementation 'com.android.support:support-annotations:X.X.X'
Where X.X.X is the version of the rest of your support libraries.
You should read this article that explains how to implement this with more detail.
So I'd like to import the "apache commons ftp" libraries for use in my project. I got as far as the importing the modules, and am including a pic just to show that they're in there.
But when I try to use the import statements
(i.e.) import org.apache.commons.net.ftp.FTP;
they fail.
So am curious if I am missing a step, or am missing something.
Please add below dependency in your gradle:
// https://mvnrepository.com/artifact/commons-net/commons-net
compile group: 'commons-net', name: 'commons-net', version: '3.5'
For any dependency to import in Android Studio through gradle use below reference:
https://mvnrepository.com/
This will save your time from importing module and solving gradle errors :)
Thank You
I would recommand AndiGeeky's answer if you don't modify so you have a custom library.
Meanwhile if you really want to use the library as a module, you can add this line in your build.gradle in your module app
compile project(':NAME_OF_YOUR_MODULE') << should be commons-net-3.5
Hope that will help you :)
I'm trying to use HttpPost as I did in the past in Android. I realize that it has been removed from recent Android versions. Following the solutions on a similar StackOverflow question, I added this to my Gradle dependencies:
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.5'
After a Gradle sync that complained of no errors, I still cannot import the HttpPost program. In fact, the org.apache.http.client.methods package does not resolve at all.
I also tried what the Apache HttpClient website suggested, which was to use this instead in my Gradle dependencies:
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
Once again, the sync went fine, and this time the package resolved, but not the HttpPost program.
I'd be grateful for any suggestions.
Just add this line in your build.gradle inside android plugin :
useLibrary 'org.apache.http.legacy'
The Apache HttpClient 4.3 for Android meant to be an update for the legacy 4.0 alpha version that was included in early Android versions. To avoid naming conflicts some on the updated classes got the postfix HC4, like HttpPostHC4 for example, which one had to use instead.
But now that the old HttpClient was removed form Android, the old classes like HttpPost do not exist anymore.
The official way to get the HttpClient library on newer Android version is to use:
android {
useLibrary 'org.apache.http.legacy'
}
as documented here.
I am trying to convert an IntelliJ project to the Gradle system of Android Studio but I am running into errors with Apache HttpClient? Am I missing something, the errors I am getting are as follows:
Error:(10, 30) error: package org.apache.http.client does not exist
Error:(11, 30) error: package org.apache.http.client does not exist
Error:(12, 37) error: package org.apache.http.client.entity does not exist
Error:(13, 38) error: package org.apache.http.client.methods does not exist
Error:(14, 38) error: package org.apache.http.client.methods does not exist
Error:(15, 38) error: package org.apache.http.client.methods does not exist
Error:(16, 35) error: package org.apache.http.impl.client does not exist
Error:(134, 33) error: cannot find symbol class HttpUriRequest
Error:(164, 39) error: cannot find symbol class HttpUriRequest
Error:(106, 17) error: cannot find symbol class HttpGet
Error:(106, 39) error: cannot find symbol class HttpGet
Error:(117, 17) error: cannot find symbol class HttpPost
Error:(117, 40) error: cannot find symbol class HttpPost
Error:(125, 43) error: cannot find symbol class UrlEncodedFormEntity
Error:(135, 9) error: cannot find symbol class HttpClient
Error:(135, 33) error: cannot find symbol class DefaultHttpClient
Error:(155, 18) error: cannot find symbol class ClientProtocolException
Error:(165, 9) error: cannot find symbol class HttpClient
Error:(165, 33) error: cannot find symbol class DefaultHttpClient
Error:(185, 18) error: cannot find symbol class ClientProtocolException
My build.gradle file has the following dependencies:
dependencies {
compile 'com.google.android.gms:play-services:+'
compile 'org.apache.httpcomponents:httpclient:4.2.6'
compile 'org.apache.httpcomponents:httpmime:4.2.6'
compile files('libs/core.jar')
}
It seems a lot of people are getting a similar problem but neither SO or Google have a solution so I am hoping this question will help future searchers.
if you are using target sdk as 23 add below code in your build.gradle
android{
compileSdkVersion 23
buildToolsVersion '23.0.1'
useLibrary 'org.apache.http.legacy'
}
and change your buildscript to
classpath 'com.android.tools.build:gradle:1.3.0'
for more info follow this link
I had this problem and then found these pages:
Here you can see that apache library is deprecated, but it's not removed, so it should work. It doesn't.
See.
And here you can see how to include apache library to your project
See.
I resolved problem by adding following to my build.gradle file as recommended in second link.
android {
useLibrary 'org.apache.http.legacy'
}
However this only works if you are using gradle 1.3.0-beta2 or greater, so you will have to add this to buildscript dependencies if you are on a lower version:
classpath 'com.android.tools.build:gradle:1.3.0-beta2'
Add this library into build.gradle
android {
useLibrary 'org.apache.http.legacy'
}
I suggest you replace the deprecated apache HttpClient with the new HttpURLConnection.
That's a cleaner solution, it's quite easy to migrate, and generally it's better to stick to the latest SDK changes than trying to hack/patch/workaround: you usually regret it later :)
Step 1
HttpGet httpGet = new HttpGet(url);
becomes:
URL urlObj = new URL(url);
Step 2
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpResponse response = httpClient.execute(httpGet, localContext);
InputStream is = response.getEntity().getContent();
becomes:
HttpURLConnection urlConnection = (HttpURLConnection) urlObj.openConnection();
InputStream is = urlConnection.getInputStream();
Step 2 bis
int status = response.getStatusLine().getStatusCode();
becomes:
int status = urlConnection.getResponseCode();
copy org.apache.http.legacy.jar which is in Android/Sdk/platforms/android-23/optional folder to to app/libs
and also added this line to app.gradle file
compile files('libs/org.apache.http.legacy.jar')
But if you're using more jar libraries, you can use this way
compile fileTree(dir: 'libs', include: ['*.jar'])
Basically all you need to do is add:
useLibrary 'org.apache.http.legacy'
To your build.gradle file.
I ran into similar problems, you might be able to get it to work using a similar method.
First, try this with your current configuration, exclude httpclient from httpmime:
dependencies {
compile 'com.google.android.gms:play-services:+'
compile ('org.apache.httpcomponents:httpmime:4.2.6'){
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient:4.2.6'
}
In my case, I fixed it by using the following jars :
httpclient-android-4.3.5.1.jar
httpmime-4.3.5.jar
Then, in the build.gradle, excluding httpclient from httpmime:
dependencies {
compile 'com.google.android.gms:play-services:+'
compile('org.apache.httpcomponents:httpmime:4.3.5') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
}
I ran into the same issue. Daniel Nugent's answer helped a bit (after following his advice HttpResponse was found - but the HttpClient was still missing).
So here is what fixed it for me:
(if not already done, commend previous import-statements out)
visit http://hc.apache.org/downloads.cgi
get the 4.5.1.zip from the binary section
unzip it and paste httpcore-4.4.3 & httpclient-4.5.1.jar in project/libs folder
right-click the jar and choose Add as library.
Hope it helps.
Perfect Answer by Jinu and Daniel
Adding to this
I solved the Issue by Using This, if your compileSdkVersion is 19(IN MY CASE)
compile ('org.apache.httpcomponents:httpmime:4.3'){
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile ('org.apache.httpcomponents:httpcore:4.4.1'){
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile 'commons-io:commons-io:1.3.2'
else if your compileSdkVersion is 23
then use
android {
useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
This is what I did, and it works for me.
step 1: add this in the build.grade(module: app)
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
step 2: sync the project and done.
After spending days on the subject, I managed to solve it finally. Unfortunately we need it if we want to use expansion files. The solution has been provided by a few people here, but for me the answers were missing a few minor detail that could have saved a lot of time for me. Here is the sequence of events for novices like me to save your precious time.
First I imported the "library" folder from D:\Users\Imre\AppData\Local\Android\sdk1\extras\google\play_licensing to the project by going into File, New, Import Module and navigating to the "library" folder. If you open the SDK Manager and click on "Launch Standalone SDK Manager" in the bottom of the popup screen, you can hover your pointer over the "Extras" folder down in the bottom and the small yellow info will tell you where you will find the package that you need to import.
Once that is done, go down to the "library" section in the left pane with "Project" and within it the "Android" tab open. Open the java section of the library and open the APKExpansionPolicy class.
If you have errors and the import org.apache.http.NameValuePair and the import org.apache.http.client.utils.URLEncodedUtils are pale grey, open the build.gradle(Project:whatever) and make sure that in "buildscript" under "dependancies" you have the "classpath 'com.android.tools.build:gradle:1.5.0" included. The 1.5.0 might be different in your case. I guess it depends on your Studio version. Mine is 1.5.1. If yours is newer, you will be reminded to update the numbers.
After that, go to "build.gradle(Module:library) and include the "useLibrary 'org.apache.http.legacy' into the "android"section. Sync Now (R/H top corner) should be offered. Do it.
If you get further error messages (I wouldn't know it because I did it the other way round), the Apache files might be missing from your project, as apache is not supported anymore. Find them in C/D:Users/Yourname/AppData/Local/Android/Sdk/platforms/android-23/optional and copy/paste them into yourproject/app/libs folder. You should have an optional.json and an org.apache.http.legacy.jar file in there. You might be better off going to apache's website and dowloading the newest version: http://hc.apache.org/downloads.cgi Unzip it anywhere you want, open it, go to "lib", copy the httpclient-4.5.1.jar file and replace the org.apache.http.legacy.jar file with it.
Sync and rebuild/clean your project and it should be good to go.
Just in case, open your terminal (L/H bottom of Android Studio) and type in "gradlew clean". It will install a few things. Once it is done, type in "gradlew assemble". It will take a few minutes to finish, but it will give you the errors if you have any of course.
If you cannot type in anything in the Terminal, launch command prompt (Windows button+R), type in cmd, hit OK, right click on the title of the small black popup screen (C:\WINDOWS\system32\cmd.exe), Properties, Options, in the bottom of the window check that "Use legacy console" is thicked. Restart A.Studio.
Good luck!
The version of the Apache HTTP client provided on stock Android was very very old.
Google Android 1.0 was released with a pre-BETA snapshot of Apache HttpClient. To coincide with the first Android release Apache HttpClient 4.0 APIs had to be frozen prematurely, while many of interfaces and internal structures were still not fully worked out. As Apache HttpClient 4.0 was maturing the project was expecting Google to incorporate the latest code improvements into their code tree. Unfortunately it did not happen.
While you could keep using the old deprecated library via the useLibrary 'org.apache.http.legacy' workaround (suggested by #Jinu and others), you really need to bite the bullet and update to something else, for example the native Android HttpUrlConnection, or if that doesn't meet your needs, you can use the OkHttp library, which is what HttpUrlConnection is internally based upon anyway.
OkHttp actually has a compatibility layer that uses the same API as the Apache client, though they don't implement all of the same features, so your mileage may vary.
While it is possible to import a newer version of the Apache client (as suggested by #MartinPfeffer), it's likely that most of the classes and methods you were using before have been deprecated, and there is a pretty big risk that updating will introduce bugs in your code (for example I found some connections that previously worked from behind a proxy no longer worked), so this isn't a great solution.
I had to post as none of the above answers worked completely for me.
I am using Android Studio
classpath 'com.android.tools.build:gradle:1.5.0'
compileSdkVersion 23
buildToolsVersion "23.0.3"
Step 1: Download lastest jar file (http://www-eu.apache.org/dist//httpcomponents/httpclient/binary/httpcomponents-client-4.5.2-bin.zip)
Step 2: Copy paste the .jar file to the libs folder (create if does not exist already) in your module (can be app or library)
Step 3: Right click on the jar and "Add as Library". It will automatically add the jar file as a dependency in your module's gradle file
Step 4: Now automatically your problem will get resolved but in case you are using proguard in your app, it will give you warning about duplicate class files and won't let you build. It is a known bug and you need to add following to your proguard-rules
-dontwarn org.apache.commons.**
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
Good Luck!
In my case, I updated one of my libraries in my android project.
I'm using Reservoir as my cache storage solution: https://github.com/anupcowkur/Reservoir
I went from:
compile 'com.anupcowkur:reservoir:2.1'
To:
compile 'com.anupcowkur:reservoir:3.1.0'
The library author must have removed the commons-io library from the repo so my app no longer worked.
I had to manually include the commons-io by adding this onto gradle:
compile 'commons-io:commons-io:2.5'
https://mvnrepository.com/artifact/commons-io/commons-io/2.5
I cloned the following: https://github.com/google/play-licensing
Then I imported that into my project.