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

I created a Cordova app and I need to use expansion files for the google play store.
To use this expansion files, I added the xapkreader plugin.
Now, when I want to build my project (cordova build android), I get the following error:
package org.apache.http does not exist
I tried to add
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
}
to my build.gradle. But then I got
A problem occurred configuring root project 'android'.
> Unable to find optional library: org.apache.http.legacy
Also, I put my org.apache.http.legacy.jar in every lib folder I found.
The optional.json exists in my android-23 sdk folder, too.
Does somebody have an idea how I could fix it?
Values:
minSdkVersion: 16
targetSdkVersion: 25
Cordova: 6.0.0
Gradle version: 2.2.1

Use this alternative:
dependencies {
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
}

Related

Using a newer Android Gradle plugin in React Native

When I try to build our Android React Native app, it generates these warnings related to Gradle:
WARNING:Software Components will not be created automatically for Maven publishing from Android Gradle Plugin 8.0. To opt-in to the future behavior, set the Gradle property android.disableAutomaticComponentCreation=true in the `gradle.properties` file or use the new publishing DSL.
OneSignalPlugin: WARNING: OneSignalPlugin: Downgraded 'com.android.support:33.0.0' -> 28.+ to prevent compile errors! Recommend updating your project's compileSdkVersion!
WARNING:We recommend using a newer Android Gradle plugin to use compileSdk = 33
This Android Gradle plugin (7.2.1) was tested up to compileSdk = 32
I'm not sure why it's complaining about the compileSdkVersion being updated to 33, as that's exactly what I have specified in my build.gradle file:
buildscript {
ext {
buildToolsVersion = "33.0.0"
minSdkVersion = 21
compileSdkVersion = 33
targetSdkVersion = 33
supportLibVersion = "33.0.0"
castFrameworkVersion = "21.0.0"
kotlinVersion = "1.6.0"
...
However, the more pressing issue is that I'm trying to upgrade the Android Gradle plugin to a newer version. In build.gradle I have:
classpath("com.android.tools.build:gradle:7.0.4")
...and in gradle-wrapper.properties I have:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
I've tried changing build.gradle to use version 7.3.3, however then it fails to find the pom file to download.
> Could not determine the dependencies of null.
> Could not resolve all task dependencies for configuration ':classpath'.
> Could not find com.android.tools.build:gradle:7.3.3.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
Required by:
project :
> Could not find com.android.tools.build:gradle:7.3.3.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
- https://repo.maven.apache.org/maven2/com/android/tools/build/gradle/7.3.3/gradle-7.3.3.pom
Required by:
project : > project :react-native-gradle-plugin
Here is the full build log, in case it helps: https://gist.github.com/justintoth/11b462c7dbe0f51a2e78a62950e2b969
The answer is that there is a difference between the Gradle version (7.4.2 in my case) and the Android Tools Gradle version (7.3.1 in my case.) So in build.gradle I specified:
classpath("com.android.tools.build:gradle:7.3.1")
...and then in gradle-wrapper.properties I have:
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
This now "works", although I ran into many other build and runtime errors while upgrading to React Native 0.70.x so I'm still not there yet...

Could not resolve all dependencies for configuration ':app debug Runtime Classpath'

I am upgrade my android project gradle 5.4.1-all to 6.5-bin, and upgrade build tools 4.0.0 to 4.1.0, then i am get an error like this
Could not resolve all dependencies for configuration ':app:debugRuntimeClasspath'.
Could not create task ':app:minifyReleaseWithR8'.
Cannot query the value of this provider because it has no value available.
upgrading build tools from 4.0.0 to 4.1.0 doesn't sound right to me--
To set the buildToolsVersion (e.g. to '30.0.5') in your build.gradle file, I suggest going to Tools > SDK Manager, then going to the "SDK Tools" tab; here I find the default view misleading, because it shows a certain version of the "Android SDK Platform-Tools" (the one you might have upgraded to) - but then when you tick the option "Show Package Details", you see another version actually installed.
And so I recommend setting the buildToolsVersion to this latter installed version.
Double check the type on what you are assigning to your compileSdkVersion in the build.gradle files.
If you are using a value from gradle.properties you need to parse it into an integer first or you will get this R8 task related crash due to that tasks configuration running triggering further resolution of dependency configurations.
so if you have something like this in your build.gradle:
android {
compileSdkVersion project.targetSdk
...
}
and this in your gradle.properties:
targetSdk=30
you need to parse the integer from the string.
android {
compileSdkVersion Integer.parseInt(project.targetSdk)
...
}
In gradle file, you must have buildtools version, something like:
buildToolsVersion 29.0.3
Make sure you have this version downloaded, the problem is mostly caused by you have no this build tools version.
Download it fron Android Studio sdk manager -> SDK tools tab.
a work around for me in build.gradle app level was to downgrade from:
compileSdkVersion 32
buildToolsVersion '32.0.0'
to :
compileSdkVersion 32
buildToolsVersion '30.0.3'
Noting that :
current config in build.grade project level is:
projectMinSdkVersion = 16
projectTargetSdkVersion = 30

compileSdkVersion is not specified error in React Native Android

I get the build error when I try to build an Android app in my React Native project.
When I run react-native run-android, it says:
> Configure project :react-native-os
WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':react-native-os'.
> compileSdkVersion is not specified.
In Android Studio, I can see that it says the same thing:
Cause: compileSdkVersion is not specified.
So I edited build.gradle(Module: app) file in Android Studio, but the problem persists and the error message doesn't change.
android {
// compileSdkVersion rootProject.ext.compileSdkVersion
compileSdkVersion 28
buildToolsVersion "28.0.3"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
I tried solutions in other threads like this one but nothing worked. Does anyone know what the problem is here?
I also faced the same issue solved by :
1- run npm i #react-native-firebase/app in terminal
2- follow these steps to add firebase to the android platform.
Make sure that you have in android/app/build.gradle:
task copyDownloadableDepsToLibs(type: Copy) {
from configurations.compile
into 'libs'
}
(This error happened to me after I accidentally changed configurations.compile to configurations.implementation)
Easiest and effective solution if this is happening with react native
Move to node_module/#react-native-firebase/
for all modules example- app, firestore etc.
Go to their android folder and open build.gradle
you will see,
project.ext {
set('react-native', [
versions: [
android : [
minSdk : 'same your project version root folder/android/app/build.gradle',
targetSdk : 'same your project version root folder/android/app/build.gradle',
compileSdk: 'same your project version root folder/android/app/build.gradle',
buildTools: 'same your project version root folder/android/app/build.gradle'
],
firebase: [
bom: firebaseBomVersion,
],
],
])
}
Hope this made it work. Happy Coding :)
Go to node_module>#react-native-firebase>messaging>android>build.gradle
Find code which defines min and target sdk and define the sdk and build version same as you have in your main project build.gradle file.
Then run command cd android && ./gradlew clean && cd ..
Also make sure you had defined default firebase config in your app level build.gradle
Make sure you have this import on top your build.gradle :
apply plugin: "com.google.gms.google-services"
and an default config as :
defaultConfig { applicationId "..." minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 00 versionName "... multiDexEnabled true }
I think you are using Android Supported Library.
If you are 27+ Supported Library you should use compileSdkVersion 27 and targetSdkVersion 27
My issue was caused by node command not found by gradle.
# fixed by linking the node path to the /usr/bin/node
# node is binary was located in $HOME/.nvm/versions/node/v14.13.0/bin/node
sudo ln -s $(which node) /usr/bin/node
When I run the above command the issue above disappeared.
Maybe I am too later to answer but the possible reason is if your build.gradle version is above 7 than you also may be getting the error of maven, Plugin with id ‘maven’ not found. If you try to follow the steps and solve that error that sdk compile error vanishes.
https://lifesaver.codes/answer/plugin-with-id-maven-not-found-12774
This worked in my case

React Native Android Gradle Fail

I'm trying to get a ReactNative Android app up and running, but after going through the initial setup guide, I get the error:
Error:Failed to find target with hash string 'android-26' in:
/Users/nicholasstephan/Library/Android/sdk
Install missing platform(s) and sync project
I don't want to install and use SDK v26, React Native specifically uses v23.0.1. I'm not sure where that reference to v26 comes from.
Any ideas where that reference to android-26 could be coming from?
Either you are saying that it should compile with Android 26 (targeting and compiling could have two different target versions) or some of your dependencies are asking for that specific version.
Check all your node-modules for build.gradle and settings.gradle files.
This is due to maven repo URL, I faced same issue in android studio As it can't find android-26 but it can 26
I suggest to check
1 . youProject/android/app/build.gradle
2 . youProject/android/app/src/main/AndroidManifest.xml
and search for 'android-26' string and make it just 26
In my case it was compileSdkVersion 'android-26'
so I change it to compileSdkVersion '26'

Gradle 2.2.0 execution failed: SymbolForDebug

After upgrading gradle of my project (and library attached to it) from 2.1.3 -> 2.2.0 it doesn't build anymore and it says:
Error:Execution failed for task ':app:transformNative_libsWithStripDebugSymbolForDebug'.
java.lang.NullPointerException (no error message)
Anyone have a clue on why this is?
I found answer here:
https://stackoverflow.com/a/40117446/1088975
The point is to set both targetSdkVersion and compileSdkVersion to 22"
You need to change the following lines in build.gradle file:
android {
// SDK 24 worked for me - make sure you have the latest and update it accordingly.
compileSdkVersion 24
buildToolsVersion "24.0.2"
...
}
Maybe you can update the ndk version.
I update the ndk version from r10 to r13,and finally it worked.
You might want to check if the location of your NDK folder has any white space in it...if it has you can move your ndk folder to the c:\ drive and rebuild
Also, check the gradle versiom of your app and either upgrade or download later version, because some ndk versions do not support later gradle version

Categories

Resources