Unable to build from Android Studio - android

I get this error message when trying to build my project from Android Studio
org.gradle.tooling.UnsupportedVersionException: The specified Gradle installation 'C:\Program Files\Android\android-studio\plugins\gradle' is not supported by this tooling API version (1.7, protocol version 4): The specified Gradle installation 'C:\Program Files\Android\android-studio\plugins\gradle' is not supported by this tooling API version (1.7, protocol version 4)
I can build my project from executing
gradlew assemble

I found out if I import module by "Create module from existing sources", this problem went away.
I had selected "Import module from external model" with Gradle. This option generated the above message.

I believe this is a temporary issue with the current build of AndroidStudio. I downloaded and installed gradle locally and referenced that installation for my project via File -> Settings >> Gradle >> Use Local Gradle Distribution and was able to build and install.
Alternatively, using gradlew from the Terminal window worked as well. ./gradlew tasks show you available taslks including "installDebug".

Related

Could not import project 'FirebaseUI-Android'

I tried importing via import project wizard, didn't work. This project is using Gradle Kotlin DSL. I am using Android Studio 3.1.4.
I tried running gradle idea and got this message
FAILURE: Build failed with an exception.
* Where:
Build file '/Users/user/Projects/firebaseauthui/FirebaseUI-Android/build.gradle.kts' line: 400
* What went wrong:
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
* 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.
What is the recommended way to import this project as they have migrated to Kotlin DSL?
This has been reported on GitHub Repository. Still I have issue importing.
A note on importing the project using Android Studio: Using 'Project
from Version Control' will not automatically link the project with
Gradle (issue #1349). When doing so and opening any build.gradle.kts
file, an error shows up: Project 'FirebaseUI-Android' isn't linked
with Gradle. To resolve this issue, please git checkout the project
manually and import with Import from external model.
According to your issue
* What went wrong:
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
Looks like Android SDK is not configured in your project which is why it is failing to compile project in Gradle.
Try this solution:
Go to your project ('/Users/user/Projects/firebaseauthui/FirebaseUI-Android/')
Find local.properties file.
Open that file and add this variable if it's not there
sdk.dir=`path of your Android SDK`(it is where you've put android sdk in local storage)
"For more generic way, check this solution" SO answer by #Ziggy192
I did update the Android Studio, current version
Android Studio 3.1.4 Build #AI-173.4907809, built on July 24, 2018
JRE: 1.8.0_152-release-1024-b01 x86_64 JVM: OpenJDK 64-Bit Server VM
by JetBrains s.r.o Mac OS X 10.13.6
I did update Kotlin plugin, current version
Version: 1.2.70-release-Studio3.1-1
Still I could not import from Version Control- GitHub.
Manual git checkout then open build.gradle.kts with Android Studio did solve the issue.
Getting started:
1. Get an Android Studio version 3.0 and above (You got it)
2. Make sure you have install Kotlin plugin.
Go to File | Settings | Plugins | Install JetBrains plugin… and then search for and install Kotlin. If you are looking at the "Welcome to Android Studio" screen, choose Configure | Plugins | Install JetBrains plugin… You'll need to restart the IDE after this completes.
3. Make sure you have Firebase Authentication
Go to Tools | Firebase | Authentication | Connect to Firebase | Add Firebase Authentication to your app.
With this step, you don't have to manually download the Firebase AUth.
4. Done
Source : Kotlin for Android Firebase Auth
I cloned the FirebaseUI-Android project and tried to reproduce your issue. I found two solutions for it.
If you just want to build the project locally as you mentioned in one of your comment. You can use command line to do it.
First you need to create an environment variable named ANDROID_HOME in your operating system and set it to SDK location. It's required so that gradle can find all the tools required to build the project.
Open a command prompt(Windows OS) on the project root directory.
Type gradlew assembleDebug to build the project. You can also try to run other task available in gradle as per your requirement.
I tried to import project via wizard but it did not work for me as well. I then first opened a random android project in Android studio and then tried
File > Open... > Selected the FirebaseUI-Android Project > New Window
These two procedure worked for me but I'm not sure if it's the recommended way.
Note: Please make sure you set the ANDROID_HOME if you get SDK location missing issue in any of the two solutions. You will also get error in project as google-services.json is missing and I hope you know how to fix it.
My Android Studio is v3.1.4 and Kotlin Plugin is v1.2.50
The error is suggesting that the android studio cannot find your android SDK you should go to:
File -> Project Structure -> in right panel choose SDK location -> set your Android SDK location.
Try to sync project with Gradle files from Android Studio:
Step 1 - File -> Sync Project with Gradle file
Step 2 - Once sync is done :- File - Invalidate caches/Restart.
I hope this will help you.

What is gradle wrapper and the gradlew.bat file?

Lately I came to know the power of Gradle as a build system and as an Android developer I wanna understand it deeply.
One article said the following:
You can execute all the build tasks available to your Android project using the Gradle wrapper command line tool. It's available as a batch file for Windows (gradlew.bat) and a shell script for Linux and Mac (gradlew.sh), and it's accessible from the root of each project you create with Android Studio.
To run a task with the wrapper, use one of the following commands:
On Windows:
gradlew task-name
Now I have some doubts which goes as follow:
What is Gradle Wrapper and gradlew.bat?
If I've got Android studio installed and it is using gradle to build my apps (so gradle is already installed on my system), do I still need to install gradle for build purpose from command line? As when i write any commend like gradle, gradlew on my command line I get error saying gradlew is not recognized as internal or external command (the same error for other commands). I may be using it on wrong path, help me on what path do I need to use Gradle related command?
If I need to download and install it, how and where can I find the file? And the other processes?
I am using a Windows machine for this.
The Gradle Wrapper is an optional part of the Gradle build system. It consists of four files that you check into version control system. The Unix start script <your root project>/gradlew, the <your root project>/gradlew.bat Windows start script, <your root project>/gradle/wrapper/gradle-wrapper.jar which contains the class files for the wrapper and is started by the start scripts and <your root project>/gradle/wrapper/gradle-wrapper.properties which contains some configuration for the wrapper, for example which Gradle version to use to build the project.
In my opinion, each and every Gradle project, even the tiniest, should make use of the Gradle wrapper.
The Gradle wrapper makes sure your build is always run with the same Gradle version, no matter who executes the build and where or that Gradle is installed or not, as long as the one uses the Gradle wrapper to build the project. This means you can design your build for that Gradle version and be sure that the build will not fail, just because someone is using a different version of Gradle and thus is also an important step in build reproducibility.
Also, someone wishing to build your project only needs to have Java installed and that's it. He does not need to have any Gradle version installed. Actually any already installed Gradle version is ignored. The Gradle wrapper checks whether in ~/.gradle/ the version that is necessary for the build is already present, because some Gradle wrapper of any project put it there already. If it is present already, it is used, otherwise it is automatically downloaded.
If you type gradlew on the commandline and the command is not found, that means you didn't put your root projects path to the PATH environment variable (I wouldn't recommend doing that either), nor are you currently in your root project's directory. To run a Gradle build, you have to be anywhere inside your project and call Gradle or the Gradle wrapper. But like with any executable file that is not on the path, you have to provide its path of course. So if you are in your root project directory, you can simply do gradlew. if you are in <root project dir>/foo/bar/, you would need to call ../../gradlew.
The Gradle Wrapper files are generated by the implicitly available Gradle task wrapper and then get checked into the VCS of the project in question. If those four files are not present for a project, it does not use the Gradle wrapper and you should post an improvement request to the project to add it.
If some project does not use the Gradle wrapper, but builds with Gradle, you can either install Gradle and use gradle instead of gradlew, or you can even call the Gradle wrapper of any other project that you have available on disk. The build will then be run with the Gradle version that wrapper or Gradle installation is using and thus might not behave as expected, which is why really each and every project should use the wrapper if it uses Gradle.
Edited after comments
Gradle is a build system.
This gradle-wrapper is kind of the primary interface to to build Android projects. It the part of Gradle-build-system and does some primary check if gradle in installed or not.
gradlew.bat - its a batch file used on Windows. You can even open it with a notepad to view the instructions in it. Batch files are like 'commands' written in a file to be executed. You use it (in case of Windows) to execute build commands. It also checks if gradle is installed or not. And in case it is not, it downloads and installs it.
Example : to build android app on Windows:
Open command prompt
Navigate to your project's root directory
execute gradlew.bat assembleDebug
It starts the wrapper, checks if Gradle is installed there and
executes all the 'gradle specific' commands to build your project.
Do you need to install Gradle ?
Actually, no. Its the job of this gradlew script to check for that. If gradle its not already there, it would automatically download it and use it for all later builds.
gradlew.bat IS the Gradle Wrapper (for Windows in this case). Gradle Wrapper is just a small utility that will ensure that Gradle is installed (or install it if necessary) so you can always build the project. Gradle itself allows you to manage dependencies and build configurations for your project.
If you have installed Android Studio, you have Gradle installed and are good to go. (Technically, each project will have it's own wrapper to handle installing/using Gradle)
As I mentioned above, you are good to go.
In the end Gradle is a command line tool that you use to build your project and you could very well use that directly (though you don't have to) since it is exactly what Android Studio uses to build your project.

Can't get Terminal Emulator for Android to build in Android Studio

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.

Jenkins job using Gradle can't find executable

I am trying to set up a Jenkins job to build the next big Android app! I've got the Android SDK installed and that part seems to be working fine. I've got Gradle Plugin v1.24 installed on Jenkins and now I think I'm trying to figure out how to get Gradle actually working.
First attempt was to have Jenkins download a specific version automatically from gradle.org. I'm trying to pull v2.2.1 because that seems to be the version my Android app builds with locally. When I do that I get this error in my Jenkins job:
[Gradle] - Launching build.
Invalid tool ID 2.2.1
[Gradle] - [ERROR] Can't retrieve the Gradle executable.
Build step 'Invoke Gradle script' marked build as failure
I tried many different versions but could not get that working. So, next was to tell Jenkins where to download Gradle from. I gave it this location:
https://services.gradle.org/distributions/gradle-2.2.1-bin.zip
I get a different error when building but still not too sure what to do.
[Gradle] - Launching build.
[Journeyman-Android] $ gradle clean build
FATAL: command execution failed
java.io.IOException: Cannot run program "gradle" (in directory "/var/lib/jenkins/workspace/Journeyman-Android"): error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1047)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
at hudson.Launcher$ProcStarter.start(Launcher.java:382)
at hudson.Launcher$ProcStarter.join(Launcher.java:389)
at hudson.plugins.gradle.Gradle.performTask(Gradle.java:262)
at hudson.plugins.gradle.Gradle.perform(Gradle.java:116)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Caused by: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.forkAndExec(Native Method)
at java.lang.UNIXProcess.<init>(UNIXProcess.java:186)
at java.lang.ProcessImpl.start(ProcessImpl.java:130)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:1028)
... 16 more
Build step 'Invoke Gradle script' changed build result to FAILURE
I tried to see what I can do with the Jenkins CLI but that fails for me too. We use Jenkins to build/deploy several other projects successfully so this is a working Jenkins installation.
Does anyone have any pointers or suggestions for what I may need to do?
Update (still failing)
I am able to build my app manually but navigating to the root of my project in the jenkins workspace and executing
./gradlew assemble
Finally figured it out. I needed to update my jenkins job to use the Gradle wrapper instead of a specific Gradle version. Once I did that I had a few more errors to sift through but they were all very informative and gave me the information I needed to resolve them.
I downloaded the Gradle.
Extracted to some place.
In Jenins > Manage Jenkins > Gradle
Unchecked the install automatic.
Set the path to gradle home, (Ex: C:\Graddle\gradle-2.1).
Probelm resolved.
For Jenkins running on linux:
download gradle zip file
cd /opt/
wget https://services.gradle.org/distributions/gradle-2.10-all.zip
unzip
unzip gradle-2.10-all.zip
visit jenkins website
Jenkins > Manage Jenkins > Configure System > Gradle > Gradle installations
uncheck Install automatically, set 2.10 to name, set /opt/gradle-2.10 to GRADLE_HOME.
click your job
Configure > Build > Invoke Gradle script
select Invoke Gradle, select 2.10 in Gradle Version dropdown list.
If one previously configured the build with Invoke Gradle script option and selected a specific Gradle Version (say 2.4 for example), he initiated the build but later switched to Use Gradle Wrapper option without resetting the Gradle Version value back to Default. Jenkins would issue the
[Gradle] - [ERROR] Can't retrieve the Gradle executable.
It is a jenkins' bug as documented by this post.
The workaround is to reset Gradle Version to Default before swithcing to Use Gradle Wrapper.
This will help you remove invalid tool issue:
Manage Jenkins -> Manage Plugins -> Advanced: Click "Check Now" button at the bottom/right of the page.
On an old version of Jenkins (v1.609), I had to delete the "Gradle build script" step, and recreate it :-O

Importing project into Android studio

I am trying to import an Android library I've created into Android Studio. I've exported the app from Eclipse by going to File > Export > Gradle Build Files which completed successfully.
However, when I try and import the project into Android Studio I get the following error:
You are using an old, unsupported version of Gradle. Please use
version 1.8 or greater. Please point to a supported Gradle version in
the projects Gradle settings or in the project's Gradle wrapper (if
applicable)
I've followed the instructions from Unable to import Eclipse project to Android Studio but this hasn't worked.
Thanks for any help you can provide
Download Gradle 1.8: http://www.gradle.org/downloads
Install/Copy it in a folder on your computer.
Check what gradle installation you use in Settings (Strg+Alt+S) -> Gradle
Check "use local gradle distribution" and point in "gradle home:" to the gradle installation

Categories

Resources