Android Studio doesn't install SDKs... what? - android

I'm trying to use Cordova to build a hello world app and after adding ANDROID_HOME variable (You'd be shocked how long that took to figure out) all I keep seeing when building is this:
BUILD FAILED
Total time: 1 mins 6.679 secs Error:
/Users/vladdy/Desktop/laboratory/cordovaBackgroundApp/platforms/android/gradlew:
Command failed with exit code 1 Error output:
FAILURE: Build failed
with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Failed to find target with hash string 'android-25' in: /Users/vladdy/Library/Android/sdk
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Ok fair enough so let's go install it:
Waiting patiently for the install, and same error running cordova build.
I wonder what else we need to install? But look, it seems that Android Studio still has Nougat and 25 available:
Why is Android Studio not installing anything?
I can see why PhoneGap Build is so popular...
Edit:
cordova requirements is now broken reporting the following:
My ~/.bash_profile:
export ANDROID_HOME=/Users/vladdy/Library/Android/sdk/

Requirements?
If you don't need Android Studio, I recommend not downloading it, instead, as #Tom-Esendam also suggest, go for the command-line tool.
Android Studio and Command Line Tool
Direct download link of Command Line Tool for OSX (2017-03-21)
Proxy?
And if your behind a proxy server, don't forget to add it to the settings in the SDK Manager Settings.
What does the different programs and commands?
cordova build doesn't download any SDK's.
cordova prepare appends the necessary SDK files to the cordova build folders.
After download of Command Line Tool:
After unzipping it, set ANDROID_HOME to it's root, so you have:
build-tools
extras
platforms
platform-tools
system-images
tools
catalogs under the root.
Adding SDK's:
Then install SDK's with ./tools/android.
Android SDK Manager downloads the SDK's, so you check what you need and hit OK to download it.
Preparing the build
Make sure all proxy settings are set if your behind a proxy.
Before running cordova build run cordova prepare. This shouldn't be necessary, but least I need to run that even thou cordova build should include that.

I don't know about the mac version. But on windows you have a standalone sdk manager. If there is one on mac try that?

Related

Cordova Cli - No usable Android build tools found

I'm trying to build an hybrid app using the cordova cli using command
cordova build android
But it fails with error (complete log) :
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=undefined (DEPRECATED)
Using Android SDK: /usr/lib/android-sdk
Subproject Path: CordovaLib
Subproject Path: app
FAILURE: Build failed with an exception.
* Where:
Script '/home/iam/Projects/lave/platforms/android/CordovaLib/cordova.gradle' line: 75
* What went wrong:
A problem occurred evaluating script.
> No usable Android build tools found. Highest 30.x installed version is 27.0.1; Recommended version is 30.0.3.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.1.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 1s
I have followed this step thinking it would solve the issue but problem remain and I get same error even after installing the packages.
Actual image from my Android SDK Settings :
It's worth mentioning that I have installed Android-SDK using apt and afterwards I have set up environment path with this command :
export ANDROID_HOME="/usr/lib/android-sdk/"
export PATH="${PATH}:${ANDROID_HOME}tools/:${ANDROID_HOME}platform-tools/"
After installing the packages in Android-SDK,I restarted Ubuntu thinking it would fix the problem. But still receives same error message when trying to build. Am I missing something?
From the error logs I think it cannot find your ANDROID_SDK_ROOT, please check if it is set like this in your environment variables:
export ANDROID_SDK_ROOT=/Users/[USERNAME]/Library/Android/sdk
export PATH=$ANDROID_SDK_ROOT/tools:$PATH
I believe you should also set the path to your build- and platform tools like so (for your versions/paths of course):
export PATH=${PATH}:/Users/[USERNAME]/Library/Android/sdk/build-tools/33.0.0uild-tools/30.0.3
export PATH=${PATH}:/Users/[USERNAME]/Library/Android/sdk/platform-tools
Can you check that you have set al of these, or something similar? Also be aware that you may have to fix something in your build tools (this is the case for several versions, I don't know of the top of my head which ones, so it's worth to check): Android Studio error "Installed Build Tools revision 31.0.0 is corrupted"
I want to offer the solution that worked for me for Ubuntu. I suddenly remembered I had written a tutorial for mac here on SO. Remembering this made me realize I forgot to set the JAVA_HOME which Cordova looks for while Checking Java JDK and Android SDK versions. Also, ANDROID_HOME is completely obsolete and deprecated. Set the same path for ANDROID_HOME to ANDROID_SDK_ROOT (same thing).
export PATH=$PATH:$ANDROID_HOME/platform-tools
export ANDROID_SDK_ROOT=/home/iam/Android/Sdk
export JAVA_HOME=/opt/android-studio-2021.3.1/android-studio/jre
Create a bash profile and paste the above codes then save
sudo gedit ~/.bash_profile
Run this
source ~/.bash_profile
Now when running
cordova build android --prod
Gradle should be able to configure for the first time and do the necessary tasks and then boom
BUILD SUCCESSFUL in 7m 4s
48 actionable tasks: 48 executed

How can I use Cordova without installing Android Studio?

I use an old computer for development, and my current specs doesn't meet Android Studio's System requirements.
I am a newbie, and only know some JS/HTML5. And I'm trying to enable oAuth for Firebase Auth services for Android.
I downloaded the Commandline Tools from https://developer.android.com/studio/ (far at the bottom of the page) and tried to use sdkmanager.bat, but I can't make it accept commands. I added its Path to the Environment variable "path", and then tried using Windows PowerShell. But writing any command will just make it start over again. (maybe it was something foolish of me)
Then I downloaded and installed Gradle.
After that when I write cordova requirements I get the following result:
Requirements check results for android:
Java JDK: installed 1.8.0
Android SDK: installed true
Android target: not installed
No android targets (SDKs) installed!
Gradle: installed C:\Users\Sparsha\Desktop\gradle-6.5-all\gradle-6.5\bin\gradle
Some of requirements check failed
I am not sure how Android SDK installed became true, but Android target is not installed (Don't know how to install).
Also, using cordova build gives me the following results:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=undefined (recommended setting)
ANDROID_HOME=C:\Users\Sparsha\Desktop\commandlinetools-win-6514223_latest (DEPRECATED)
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
FAILURE: Build failed with an exception.
* What went wrong:
Unable to start the daemon process.
This problem might be caused by incorrect configuration of the daemon.
For example, an unrecognized jvm option is used.
Please refer to the User Manual chapter on the daemon at https://docs.gradle.org/6.5/userguide/gradle_daemon.html
Process command line: C:\Program Files\Java\jdk1.8.0_251\bin\java.exe -Xmx2048m -Dfile.encoding=windows-1252 -Duser.country=IN -Duser.
language=en -Duser.variant -cp C:\Users\Sparsha\Desktop\gradle-6.5-all\gradle-6.5\lib\gradle-launcher-6.5.jar org.gradle.launcher.daem
on.bootstrap.GradleDaemon 6.5
Please read the following process output to find out more:
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get
full insights.
* Get more help at https://help.gradle.org
C:\Users\Sparsha\Desktop\gradle-6.5-all\gradle-6.5\bin\gradle: Command failed with exit code 1
Thanks...
Whatever you downloaded from that URL is not needed. That is probably the SDK for Android Studio.
To setup your Cordova tools to develop Cordova apps with either Visual Studio or your favorite text editor like Notepad++, follow this detailed guide which I created earlier.
Let me know if you have any questions.

How to solve (Could not initialize class org.codehaus.groovy.reflection.ReflectionCache) issue in react native

$ npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 864 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Launching emulator...
error Failed to launch the emulator. Reason: Could not start an emulator within 30 seconds.
warn Please launch an emulator manually or connect a device. Otherwise, the app may fail to launch.
info Installing the app...
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1m 23s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
FAILURE: Build failed with an exception.
What went wrong:
Could not initialize class org.codehaus.groovy.runtime.InvokerHelper
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 1m 23s
at checkExecSyncError (child_process.js:629:11)
at execFileSync (child_process.js:647:13)
at runOnAllDevices (E:\work\react-native\AwesomeProject1\node_modules\#react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:94:39)
I think I had the same issue. After installing RN (May 20th, 2020), I bumped into this error. I found this solution on https://github.com/gradle/gradle/issues/10248.
In short:
Go to /android/gradle/wrapper/gradle-wrapper.properties file in your RN project
Find this line that starts with distributionUrl. Change the gradle version into gradle-6.3-all.zip.
In my project, it was:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
and I changed it into:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
That's it.
I had the same error on Mac OS and React Native v0.62.
Apply these instructions correctly: React native environment setup
Adding this variable solved my problem:
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
In the React Native version 0.62.x even the initialized application is not ready for a development build.
I change the Gradle version to the latest and I could to have a clean build, so change this file:
// this file => /android/gradle/wrapper/gradle-wrapper.properties
from:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-all.zip
to:
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-all.zip
Pay Attention: The latest version of the Gradle for my time is 6.5. when you are reading this answer please check this link to see the latest version number of the Gradle.
Update Jan 24, 2023
7.6
I fixed this by these steps:
install android studio 3.5 (or later)
install java 1.8
if you have java JDE 14.x.x you have to remove its folder from library/java/JavaVirtualMachines/jdk-14.x.x.jdk (on mac os)
install an older version of JDE (I installed 11.0.6)
npm run android!
Just follow these 2 steps only and take your coffee.
Navigate to 'android' > gradle > wrapper > gradle-wrapper.properties
Change 'distributionUrl' from old to >
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-all.zip
This Error occurs when the gradle version you used is not compatible on your environment, so you just need to update your gradle version to latest Gradle Versions, just go to: /android/gradle/wrapper/gradle-wrapper.properties to your project file.
Auguest 2021
I was using JDK 16.0.1 and faced this issue. So, for JDK 16.0.1 you need 7.0 version of gradle.
I fixed it by going to /android/gradle/wrapper/gradle-wrapper.properties and changing
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2-all.zip
to
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0-all.zip
If you are a macOS user then you should install
brew cask install adoptopenjdk/openjdk/adoptopenjdk8
brew cask install android-platform-tools
update your .bash_profile
nano ~/.bash_profile
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
This would resolve your problem. If you are working on a legacy codebase then changing the distribution URL would lead to other problems. It usually happens because of mismatching java versions.
It's probably because you use Gradle as the build system and JDK14
and the Gradle version is old. Reference:
If you use Gradle Wrapper then refer to
$PROJECT_ROOT/gradle/wrapper/gradle-wrapper.properties
Property distributionUrl should be:
distributionUrl=https://services.gradle.org/distributions/gradle-6.3-bin.zip
If it's an older version then change it, run ./gradlew clean build
and try again.
It is because your Gradle version is not supported by the Java JDK. If you use the JDK version 15.0.2 then you need to Gradle version change 6.6.1 or 6.7
To Change the Gradle Version in Android Studio.
android[project_name]/gradle/wrapper/gradle-wrapper.properties
Open this file and set this
distributionUrl=https://services.gradle.org/distributions/gradle-6.6.1-all.zip
then this problem will be solved.
To check the java JDK version.
open cmd.
run echo %JAVA_HOME%
Then you can also search on google to check the supported version of Gradle to the JDK.
updating JAVA_HOME works for me in mac OS
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home"
This issue is caused by incorrect version of graddle. so to fix this follow these steps
Make sure you have Android studio installed and SDK is setuped from Android studio menu Tool-> SDK Manager you can setup SDK, install latest SDK if you are using latest version of React Native .
From Android Studio menu Tools > AVD Manager Setup one device and download the image. and test it to see that emulator is running OK.
Make Sure JDK is installed for latest react native install latest JDK : https://www.oracle.com/java/technologies/javase-downloads.html
Next from Android Studio menu File > New > new project create one dummy project aka Hello world and build make sure all android studio issues resolved and your Android studio hello world app is running on emulator.
Now time to fix your react native app. Stop your Android studio hello world app and keep the emulator running.
Locate your Android studio hello world app on your system and go to gradle\wrapper folder and copy the gradle-wrapper.properties file
example in windows case my hello world app is located in my documents:
C:\Users\Superman\Documents\android\hello world\gradle\wrapper
Next go to your react native app folder like : myReactApp\android\gradle\wrapper and paste the gradle-wrapper.properties file you copied from your Android studio hello world app.
finally in your terminal execute : npx react-native run-android
I have the same issue with new project and windows. I try all these way but it doesn'. Ridiculously, I move java/jdk folder from C:\Program Files to another dir in D:\ and it works like a charm.
May be it's useful.
December 2021
If you're using the latest version of Java Development Kit, you'll need to change the Gradle version of your project so it can recognize the JDK. You can do that by going to {project root folder}\android\gradle\wrapper\gradle-wrapper.properties and changing the distributionUrl value to upgrade the Gradle version. You can check out here the lastest releases of Gradle.
If you're looking for a solution for a Java/Kotlin Core Android project and not a React Project because i was also facing this problem in my core android project so here you go...
None of the above solutions worked for me. So basically the idea is to Change the version of gradle. How to do that you ask? Follow these steps:
File>Project Structure
Select SDK Location
You will find something written as "JDK was moved to Gradle Settings". Click on Gradle Settings.
Use Gradle Version 11.0
Sync the project again.
And there you go! A successfully built project! :)

Phonegap android failing after adding phonegap-plugin-push

There are lots of issues talking about Phonegap push notification plugin. May be it's updating time to time, some working solutions for some people not work for others.
I just created a fresh phonegap project(CLI 5.1.1) and added android platform and above plugin. When trying to compile it's failing with below error
Could not find any version that matches com.android.support:support-v13:23+
Below is the detailed compile error
Running command: cmd "/s /c
"C:\Users\me\Documents\PhoneGap_Apps\hello\plat
forms\android\cordova\build.bat""
ANDROID_HOME=F:\Softwares\Android\adt-bundle-windows-x86_64-20140702\sdk
JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45
Running:
C:\Users\me\Documents\PhoneGap_Apps\hello\platforms\android\gradle w
cdvBuildDebug -b
C:\Users\me\Documents\PhoneGap_Apps\hello\platforms\andr
oid\build.gradle -Dorg.gradle.daemon=true
FAILURE: Build failed with an exception.
What went wrong: A problem occurred configuring root project 'android'.
Could not resolve all dependencies for configuration ':_debugCompile'.
Could not find any version that matches com.android.support:support-v13:23+ .
Searched in the following locations:
https://repo1.maven.org/maven2/com/android/support/support-v13/maven-me
tadata.xml
https://repo1.maven.org/maven2/com/android/support/support-v13/
file:/F:/Softwares/Android/adt-bundle-windows-x86_64-20140702/sdk/extra
s/android/m2repository/com/android/support/support-v13/maven-metadata.xml
file:/F:/Softwares/Android/adt-bundle-windows-x86_64-20140702/sdk/extra
s/google/m2repository/com/android/support/support-v13/maven-metadata.xml
file:/F:/Softwares/Android/adt-bundle-windows-x86_64-20140702/sdk/extra
s/google/m2repository/com/android/support/support-v13/
Required by:
:android:unspecified
Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
How to overcome this issue?
Update you Android SDK.
The Cordova Plugin named "phonegap-plugin-push" needs "Android Support Library version 23"
Process is explain in here
Compiling
As of version 1.3.0 the plugin has been switched to using Gradle/Maven
for building. You will need to ensure that you have installed the
Android Support Library version 23 or greater.
According to the error message, it's looking for a support-v13 version in the location of <my_sdk>/extras/android/m2repository/com/android/support/support-v13
And this happens because of my plugin.xml (at my_phonegap_app/plugins/phonegap-plugin-push) having below line
<framework src="com.android.support:support-v13:23+" />
But I noticed that I don't have any 23+ versions in my above sdk path and I do have a folder 22.2.0 as the latest. Inside that folder there are support-v13-22.2.0 files.
So update the plugin.xml file so that it refers to one of existing.
<framework src="com.android.support:support-v13:22.2.0" />
To be safe enough, remove android platform and re add it before compiling
phonegap platform remove android
phonegap platform add android
Then try compile. Now it refers for the correct, existing file and compile will get success.
After spending 2h on trying build apk with phonegap-plugin-push plugin I found solution.
In config.xml of your cordova project (in your main directory), just edit or
add this line:
<preference name="android-targetSdkVersion" value="23"/>
Then remove android platform:
cordova platform add android
And add it again:
phonegap platform add android
I had a similar/the same problem when running cordova 6.0.0 project in Visual Studio 2015
Debugging in VS Emulator and Ripple works but not on the device (Sony Xperia Z5 Compact)
Build error output contained the error "Could not find any version that matches com.android.support:support-v13:23+."
Severity Code Description Project File Line Suppression State
Error > Could not find any version that matches com.android.support:support-v13:23+.
I checked that I had the correct SDK tools etc installed on my machine (Windows 10) but still couldnĀ“t build debug to my device.
My solution was to install the adb and fastboot drivers for my phone following this guide (page 2 and 3).
http://www.teamandroid.com/2012/07/30/how-to-set-up-adb-fastboot-with-android-sdk/
install driver for adb interface
http://www.teamandroid.com/2012/07/30/how-to-set-up-adb-fastboot-with-android-sdk/2/
install driver for fastboot bootloader interface
http://www.teamandroid.com/2012/07/30/how-to-set-up-adb-fastboot-with-android-sdk/3/
!note: I have a Xperia z5 and to get it in the fastboot mode the easy way is to (instead of steps 26-28) just run the adb command "adb reboot bootloader"

ionic run android failed, error gradle line 64

previously I can compile but after I updated my cordova something happended. I got this error.
FAILURE: Build failed with an exception.
* Where:
Script 'C:\Users\Jay\testproject\platforms\android\CordovaLib\cordova.grad
le' line: 64
* What went wrong:
A problem occurred evaluating root project 'android'.
> No installed build tools found. Please install the Android build tools version
19.1.0 or higher.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug
option to get more log output.
I downloaded all the required SDK, what is the problem here?
I had the same problem and this is how I fixed it. I had the build-tools version 20 installed but still was getting this error:
No installed build tools found. Please install the Android build tools
version 19.1.0 or higher.
So I created a directory named 20 within build-tools directory, and copied all the files from sdk\build-tools\android-4.4W\* to sdk\build-tools\20. The problem was fixed!
You will need to do two main things:
Install android build tools
Make them available in your shell, when run the ionic run command.
Installing the build tools (ver 19.1.0)
Open android development studio
Goto: Configure --> SDK Manager --> select "Android SDK Build-Tools
select the checkbox "Show Package details" (bottom right)
review the versions of this package, make sure the 19.1 is selected - u may use newer, but 19.1.0 works.
Click Apply to make the changes / install it
Make the build tools available in your shell environment
Edit ~/.bash_profile by using vi or other shell editor
vi ~/.bash_profile
Add the following lines:
export ANDROID_HOME=~/Library/Android/sdk
export PATH=${PATH}:~/Software/android-sdk-macosx/tools:~/Software/android-sdk-macosx/platform-tools"
(save the file, and exit)
Editing the file, makes sure that for each login those variables will be available, but as we are already in active session, you need to make it available for the current shell env, run the following:
. ~/.bash_profile
I was stuck with this error for several days, I didn't find any clear explanation
Till I find this link, https://tomspencer.dev/blog/2017/05/30/a-guide-to-installing-cordova-on-windows-10
uninstall gradle, cordova, ionic, and anything related then use the steps in the link above to install them all correctly. that worked with me

Categories

Resources