Android Studio - Unable to find optional library: org.apache.http.legacy - android

I am making an android app which features navigation drawer. I remember that I used some features that requires sdk version to be 24 so compileSdkVersion needs to be 24 as well as the targetSdkVersion, but my android phone is only 19 so I don't see the app downloaded on my phone, it is opened once I finished running the project but when I close the tab on my phone, I cannot open it again. So I tried to change the compileSdkVersion and targetSdkVersion to 19 but I'm having this error: Unable to find optional library: org.apache.http.legacy
build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 19
buildToolsVersion "25.0.0"
defaultConfig {
applicationId "com.marivel.cruz.threatmapping"
minSdkVersion 17
targetSdkVersion 19
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
signingConfigs {}
buildTypes {}
useLibrary 'org.apache.http.legacy'
}
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:19.+'
compile 'com.android.support:support-v4:19.1.0'
compile 'com.google.android.gms:play-services-maps:9.8.0'
compile 'com.android.support:multidex:1.0.0'
compile 'com.google.android.gms:play-services:9.8.0'
testCompile 'junit:junit:4.12'
}

This might seem like a workaround, but try commenting out the use library line and add the following under dependencies in your gradle build file :
dependencies {
compile files('libs/httpclient-4.4.jar')
compile files('libs/httpcore-4.4.jar')
compile files('libs/httpmime-4.3.6.jar')
}
You will have to download those files from apache and add them to your libs directory. This has worked for me before, but as I said, it feels a bit like a workaround.
You can find those jar files here:
Httpclient
Httpcore
Httpmime

Related

android unable to build the project showing install missing files

Codes of build.gradle(Module.app)
After,creating my project it was showing incompatible version.So,Found in internet to modify my gradle file but after modifying gradle file and changing compile sdk from 26 to 27 it's showing install the missing file .
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
defaultConfig {
applicationId "com.example.thelost.fisp_beta10"
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 {
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:27.+'
compile 'com.android.support:recyclerview-v7:27.+'
compile 'com.android.support:design:27.+'
compile 'com.android.support:cardview-v7:27.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
}
Error: Showing in my project
Click on the error if any, it will automatically download.
From the docs
You should always keep your Build Tools component updated by
downloading the latest version using the Android SDK Manager. If
you're using Android plugin for Gradle 3.0.0 or higher, your project
automatically uses a default version of the build tools that the
plugin specifies. To use a different version of the build tools,
specify it using buildToolsVersion in your module's build.gradle,
The latest buildToolsVersion is 27.0.1
So change
buildToolsVersion "27.0.2"
to
buildToolsVersion "27.0.1"
and sync your project.
try this in app level gradle
repositories {
maven {
url "https://maven.google.com"
}
}

Running project on Android Studio fails because of missing app module

When I press on run in Android studio an Edit configuration windows pops up and says "Error: Module not specified".
I have added sources to the application libs folder by manually making a folder structure android/hardware/automotive/vehicle/V2_0 and copied the files in there.
Build completes without errors.
I haven't edited the MainActivity -class so it is all pre-generated code.
I believe this error has something to do with incorrect syntax when including but it seems to be hard to get it working :)
this is my settings.gradle file:
include ':app'
project(':app').projectDir = new File('libs/android/hardware/automotive/vehicle/V2_0')
and this is my build.gradle file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.example.s26150.testingopencar"
minSdkVersion 21
targetSdkVersion 26
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:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile project(":android.hardware.automotive.vehicle.V2_0")
testCompile 'junit:junit:4.12'
}
What could be the issue here?
thanks in advance.

This leads to App crash. All com.android.support libraries must use the exact same version specification (mixing versions can lead to runtime crashes)

Here is my entire build.gradle(Module:app) How to fix this? This is causing app crash. I have tried to add some more code by reading earlier/previous posts about it. But it didn't helped.
However it lead to successful gradle sync and successful installation of app.
Vut app crashes.
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "26.0.0"
defaultConfig {
applicationId "com.example.akash.nbrider"
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.android.support:mediarouter-v7:25.3.1'
compile 'com.android.support:design:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.android.gms:play-services:8.4.0'
/*compile 'com.google.android.gms:play-services-location:10.2.0'
compile 'com.google.android.gms:play-services-maps:10.2.0'*/
}
enter image description here
Problem is with these two lines
buildToolsVersion "26.0.0"
...
compile 'com.android.support:appcompat-v7:25.3.1'
They should use the same main version number. If there is v. 26 library you should use that one. Otherwise, downgrade buildToolsVersion to 25.
The easiest way to install 25 buildTools would be to just manually change to 25 in build.Gradle, Sync Gradle and you should get clickable link.

Gradle Failed: transformClassesWithDexForDebug with jdk 1.8

All day I have a challenge with resolve update of some dependencies in my new project.
This is my build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com...."
minSdkVersion 19
targetSdkVersion 24
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:24.2.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.firebaseui:firebase-ui:0.4.3'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.android.gms:play-services:9.6.1'
}
apply plugin: 'com.google.gms.google-services'
and error is:
Error:
"Execution failed for task: ':app:transformClassesWithDexForDebug'
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/home/bin/java" finished with non zero-exit value 2
The problem was showing when I tried to upload an image to Firebase storage. There was error with an internet connection etc. I decided to make update of libraries. After this there is an error with jdk 1.8.
Could somebody help me to resolve this challenge?
Regards
Basically you would also want to check and resolve version conflicts in your app's dependencies.
Also check if you have enabled multidex in your app.
I had a similar issue. In my app I am using guava-retrying library, which was fetching google guava library version 21. Guava version 21 requires JDK 1.8 without providing back porting support and this was causing this error in my case.
I was able to solve it by including the guava-retrying library so that it uses version 19.0 of guava library:
compile ("com.github.rholder:guava-retrying:2.0.0") {
exclude group: 'com.google.guava', module: 'guava'
}
compile 'com.google.guava:guava:19.0'
I believe you need to enable Multidex for your application.
add the Multidex library to your dependencies, then enable Multidex in defaultConfig.
Example:
android {
compileSdkVersion 24
buildToolsVersion "24.0.3"
defaultConfig {
applicationId "com...."
minSdkVersion 19
targetSdkVersion 24
versionCode 1
versionName "1.0"
// Enabling multidex support.
multiDexEnabled true
}
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:24.2.1'
compile 'com.google.firebase:firebase-database:9.6.1'
compile 'com.google.firebase:firebase-storage:9.6.1'
compile 'com.firebaseui:firebase-ui:0.4.3'
compile 'com.firebase:firebase-client-android:2.3.1'
compile 'com.google.android.gms:play-services:9.6.1'
compile 'com.android.support:multidex:1.0.0'
}
Then in `AndroidManifest.xml", enable Multidex installation:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.multidex.myapplication">
<application
...
android:name="android.support.multidex.MultiDexApplication">
...
</application>
</manifest>
Source: https://developer.android.com/studio/build/multidex.html#mdex-gradle

I'm a new android coder. I have the error "Gradle build finished with 242 error(s) and 2 warning(s)"

I'm trying to write a youtube app in android. I tried to use this example https://developers.google.com/youtube/v3/docs/search/list#examples (Java#1). I have only used the import statements from this and when trying to compile I get a lot of errors. I wasn't sure how to import the libraries, first I tried downloading libraries from the internet but that didn't work, although the red error line moved onto further words (for example "import thing.thing2.thing3" before the red error line was under thing then moved to thing2). Then I searched mvnrepository and copy and pasted the code under the 'gradle' tab into my gradle which fixed the red error lines but now I have a lot of errors when trying to run my app (I do not have any red lines in my app as far as I can see). My gradle file looks like:
apply plugin: 'com.android.application'
android {
compileSdkVersion 24
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "richardcastle324.yahoo.com.elephantyoutube"
minSdkVersion 15
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
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:24.0.0'
compile files('libs/YouTubeAndroidPlayerApi.jar')
compile 'com.google.android.gms:play-services-drive:8.4.0'
compile files('libs/google-api-client-1.16.0-rc-sources.jar')
compile files('libs/google-api-services-youtube-v3-rev176-1.22.0-javadoc.jar')
compile 'com.google.android.gms:play-services:9.2.0'
compile 'com.google.apis:google-api-services-youtube:v3-rev176-1.22.0'
// https://mvnrepository.com/artifact/com.google.apis/google-api-services-youtube
compile group: 'com.google.apis', name: 'google-api-services-youtube', version: 'v3-rev176-1.22.0'
// https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client-java6
compile group: 'com.google.oauth-client', name: 'google-oauth-client-java6', version: '1.11.0-beta'
// https://mvnrepository.com/artifact/com.google.oauth-client/google-oauth-client-jetty
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta'
}
I'm not entirely sure what all those dependencies are doing, but I have a basic youtube app that is working with the following build gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.example.jakespeers.youtubeplayer"
minSdkVersion 16
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 files("libs/YouTubeAndroidPlayerApi.jar")
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:design:23.4.0'
compile 'com.google.android.gms:play-services:8.4.0'
}
Just make sure you have the "YouTubeAndroidPlayerApi.jar" file in your libs folder. Find the libs folder by going into the apps names folder, followed by the "app" folder, then finally the "libs" folder. Make sure the file is spelt exactly the same. Also don't forget to change your applicationId. If you need more dependencies you can add them as you need them.
If this still doesn't work, please post the errors you are getting.
Here is the link to download the lib file:
https://developers.google.com/youtube/android/player/downloads/

Categories

Resources