I installed Android Studio on my Mac. I have an android project. I'd like to build it in command-line. If I try to build, or even just get the available tasks:
./gradlew tasks
I got this error:
No Java runtime present, requesting install.
I don't want to install a new JDK. I can build the app in Android Studio. How can I use the JDK installed by Android Studio?
In this article you can find a solutiuon:
https://medium.com/#peter.configcat/build-your-android-app-from-command-line-with-android-studio-on-mac-ee1f7434709b
Add Android Studio JDK to your PATH. Add this to your .zshenv:
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home
export PATH=”$JAVA_HOME/bin:$PATH”
./gradlew tasks and ./gradlew assmebleDebug should work.
Related
I've been at this for a whole day.
I created a new project using npx react-native init Project. But If I try to run it on android I get this:
FAILURE: Build failed with an exception.
* What went wrong:
Incompatible magic value 0 in class file java/util/logging/ErrorManager
I've went through the docs many times. When I run npx react-native doctor, I get this:
Android
✓ JDK
✖ Android Studio - Required for building and installing your app on Android
✖ Android SDK - Required for building and installing your app on Android
- Versions found: N/A
- Version supported: 29.0.3
✓ ANDROID_HOME
So there were a few things that were causing this issue.
✖ Android Studio - Required for building and installing your app on Android
It seems that npx react-native doctor looks for /opt/android-studio, after placing my android studio in /opt/, it was able to detect it.
✖ Android SDK - Required for building and installing your app on
Android
Versions found: N/A
Version supported: 29.0.3
From what I understood, react native uses sdkmanager script to look for sdk which comes with command line tools when you install android studio. In my case, when I ran the script it was giving me errors. The reason for that was that I hadn't created JAVA_HOME environment variable. So, after creating the environment variable and adding it to PATH, the sdkmanager script ran successfully and so did the react native project.
TL;DR
You need to have your android studio folder in opt and it must be named android-studio.
Install android sdk command line tools(latest) and add it to your PATH like this export PATH=$PATH:$ANDROID_HOME/cmdline-tools/latest/bin
Also create JAVA_HOME and add it to PATH.
It's look you don't have installed Android Studio in your system.
Try to install from official site https://developer.android.com/studio#downloads
Or use snap https://snapcraft.io/install/android-studio/manjaro
sudo snap install android-studio --classic
Unable to create build for android from Ionic 4 solution.
Command: ionic cordova build android
Error:
Checking Java JDK and Android SDK versions
ANDROID_SDK_ROOT=/Users/$USER/Library/Android/sdk (recommended setting)
ANDROID_HOME=/Users/$USER/Library/Android/sdk (DEPRECATED)
Could not find an installed version of Gradle either in Android Studio,
or on your system to install the gradle wrapper. Please include gradle
in your path, or install Android Studio
I have android studio installed. I manually downloaded the gradle and kept in the path as well.
I have all the environment variables present. Still i have the same error message as shown above.
ENVIRONMENT VARIABLES
COMMAND: open ~/.bash_profile
export GRADLE_HOME=/Users/$USER/Library/Android/sdk/gradle/bin
export JAVA_HOME=/Users/$USER/Library/Java/Home
export ANDROID_SDK_ROOT=/Users/$USER/Library/Android/sdk
export ANDROID_HOME=/Users/$USER/Library/Android/sdk
I tried the below link in ionic forum and many other but of no help:
https://forum.ionicframework.com/t/cannot-build-android-apk-ionic-4/184154
Any suggestions would be appreciated.
Thank you.
JAVA_HOME environment variable was incorrect due to multiple versions installed on my machine. I pointed it to the latest version and the issue is resolved.
I'm trying to execute Android Lint tests on windows without using Android Studio or Android SDK.
I tried following approach as it is stated in the documentation that it's not required to have gradle or android studio. This requires to download command line tools for Android SDK. Then executing below,
cd C:\Users\User\Desktop\sdk-tools-windows-3859397\tools\bin
lint \path\to\project\location
Executing above results in,
myapp: Error: "myapp" is a Gradle project. To correctly analyze Gradle projects, you should run "gradlew :lint" instead. [LintError]
Then I tried using gradle,
cd \path\to\project\location
gradlew lint
Then it throws following error,
A problem occurred configuring project ':app'.
> The SDK directory 'C:\Users\Test\AppData\Local\Android\sdk' does not exist.
Is it not possible to execute Android Lint only using Android SDK command line tools?
I pointed ANDROID_HOME to the Android SDK tools directory in system variables.
Then executed below,
cd \path\to\project\location
gradlew lint
I'm following this approach for now. But this is confusing since the the official android developer documentation of lint, it mentions we can use "lint" as standalone with android projects. Here as the workaround i'm using "gradlew lint"
I'm trying to build Terminal Emulator for Android. I'm running Android Studio 1.4 in Kubuntu 15.04. I also tried building it in Ubuntu 14.04 LTS with the same results. The project requires the latest Android NDK, SDK 22, and SDK 11 which I've downloaded and configured in Android Studio. My system gradle version is 2.8, and Android Studio has downloaded some other versions internally. I'm using jdk1.8.0_65, which is set to JAVA_HOME and configured in Android Studio. I've built several other projects with my configured Android Studio and only seem to have a problem with this project. I need to use this project as a base for an app I'm developing.
I end up with same error, posted below, no matter what route I take to fix it in Android Studio. This is generally what I've done to try and get the project to work. I open up the project unmodified in Android Studio. I click Build >> Rebuild Project. I get an error telling me ndk implementation is deprecated. I add a file gradle.properties to the root directory of the project with the line android.useDeprecatedNdk=true and rebuild. It gives me an error: Task 'generateDebugTestSources' not found in project. I execute Sync Project With Gradle Files to resolve it. Then I end up with the following error and can't get past it.
Gradle 'Android-Terminal-Emulator-master' project refresh failed
Error:exception during working with external system:
or
Gradle sync failed: exception during working with external system:
Consult IDE log for more details (Help | Show Log)
idea.log
Things I've done to try and get the project to build:
Modify all of the project's build.gradle files to use the experimental plugin
Use different versions of Android Studio
Switch from openjdk to Oracle's jdk
Upgrade gradle to the latest version
Set gradle to default wrapper (default) and also set gradle to different versions
invalidate cache, remove ~/.gradle, and rebuild project
Make sure PATH includes the gradle and jdk bin directories and is in ~/.bashrc, ~/.profile, and ~/.zshrc
remove proguard from libtermexec library
reboot computer
I should note that the project builds without issue on the command line. I'd really like to get the project to build in Android Studio for development.
Install Arch and run Android Studio there.
I decided to try building Terminal Emulator on my Arch server, so I installed a xfce (Desktop Environment) and Android-Studio through pacman. I followed the same general path to get things setup, and the app built without issue.
The idea log Android Studio generated for the failed build on Windows and Ubuntu didn't point to any clear problem, even with --stacktrace enabled with gradle. I'm not going to waste my time figuring out why gradle doesn't want to build apps in Ubuntu or Windows.
I installed PhoneGap 3.0 with Node.js and configured all the environment variables so that javac, java, and ant all work but when I do a basic app create and try to build it for Android, I get the following error:
An error occurred during creation of android sub-project. Creating Cordova project for the Android platform: Command failed to execute : ant jar
Any ideas?
Make sure you have the Android Build Tools installed for your Android SDK version. In the Android SDK manager under Tools>Android SDK Build-tools you should see that the Build tools for your SDK version are not installed.
Detail on how I uncovered this:
To identify this as the root cause I ran the Cordova command with -d for verbosity:
cordova -d platform add android
The output of this command shows the error:
Running bin/create for platform "android" with command: ""C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"" (output to follow)
Running the offending command directly:
"C:\Users\---\.cordova\lib\android\cordova\3.1.0\bin\create" "C:\Users\---\workspace_android\FleetView\platforms\android" "com.---.fleetview" "Fleet View"
produces this output:
BUILD FAILED
C:\tools\adt-bundle-windows-x86_64-20130219\sdk\tools\ant\build.xml:479: SDK does not have any Build Tools installed.
Total time: 1 second
Command failed to execute : ant jar
I am on Windows 7.
This is due to ANT tools could not find tools.jar in JRE lib directory. When I copied tools.jar from JDK lib directory to JRE lib directory, the problem was absolutely solved and the build was successful when I ran the command "cordova -d platform add android". Hope this helps you.
Posted the answer to similar question: Android Platform Guide trouble with adding a platform through the command line
A combination of 2 things worked for me:
include the JDK in your path (path\to\jdk\bin of course)
exclude the JRE from your path (or at least have it come after the JDK)
I faced the same issue,
I was having jdk-6 and I updated to jdk-7,
that fixed the issue,
Also I didn't installed ant in the first place,
in your case ant PATH might be missing.
See if that helps.