Gradle build errors with Android Studio - android

When I try to build my project in Android Studio I get the following error, using the gradle plugin provided with the download (v 1.6):
The specified Gradle installation is not supported by this tooling API version (1.6, protocol version 4)
When I downgrade to gradle 1.3, 1.4 or 1.5, I get this error:
Gradle: : java.lang.ClassNotFoundException: org.gradle.tooling.provider.model.ToolingModelBuilderRegistry
The project was originally created in Eclipse, the exported using the build gradle file option, then imported into Android Studio.
Does anyone know what I can do to fix these issues? Many thanks.

I had a similar problem and I believe that it was caused by having multiple versions of gradle on my machine. The solution I found was to use the script that Android Studio creates in your project folder (either gradlew (MacOs/Unix) or gradlew.bat (Windows)):
./gradlew assemble
This causes the correct version of gradle to be run - i.e. the version that was shipped with Android Studio.
I haven't tried creating a project within Eclipse, so I'm not sure if these scripts are created when creating your project in that way.

I think the problem is with the way Eclipse 22 exports the project. In the end the way I got my project transferred over was to create a new project in Android Studio and copy over the files from my Eclipse project into the appropriate directories in the new project.
The directory structure of projects in Android Studio is very different to the structure in Eclipse, and there are several files created when you start a new project which you don't get when importing a project from Eclipse (e.g. gradlew.bat, settings.gradle).

I also had this problem which can indeed be worked around with Mark's suggestion of using ./gradlew assemble.
However, this does not help you run Make Project from within Android Studio.
To do that, I had to go to Preferences / Gradle / Use local gradle distribution
and select any random (but NOT gradle) folder inside the project folder.
You might notice that this is marked as an invalid location, but you can ignore that, it seems...
Not a great solution, but it works.

Related

Convert Gradle/Kotlin project to Android Project

I created a kotlin project with the command gradle init, which I can build and run without issues. I know AndroidStudio uses gradle to build/deploy an android project. With this in mind, can i modify the generated kotlin project to also become an android project? I want that when gradle build is issued, an apk file is generated, instead of the jar being generated right now. And, if possible, being able to deploy the apk to the phone connected to the computer (either via usb or wi-fi).
You actually can, just add the AGP (Android Gradle Plugin) to your build.gradle script.
And from there, structure your project to as Android Project.
Of course it's like manual type of doing it, It's easier just to start an Android Project from Android Studio cause it will generate all the files needed for Android Project.

Android studio : when re-import the project it show's error and given a strange floders

while re-importing my project android studio show's plenty of errors
after cleaning and re-importing my project i have got an red circle with ā€œJā€ on my java files and i'am enable to run my project
Make sure that your gradle version is defined properly.
It seems that this project was on another PC and you imported it on your computer. I think that probably a gradle version conflict occurred and you have two options:
one is to let android studio download gradle version specified in TlaProject (gradle 2.4)
another solution is to edit app level 'build.gradle' file and change its version to a version which is available on your machine (to see which version is available on your system, please check 'gradle' folder inside installation folder of android studio)
My problem was solved by updating the version of android studio .

Writing a Gradle for a previous Project

I just started an android project for school, and I have to edit an android application that was built by previous students. I was given source files and apk but no gradle.
I imported into Android Studio and tried to run the build when I saw that I couldn't. I have looked up documentation online for the past 4 days and have so far come up with nothing other than downloading the gradle-2.7 files and running:
build gradle
in my computers shell.
Is there an easy way to build a gradle? Perhaps some tools or such? Or will I have to go through the files and write all the gradles myself?
Android Studio uses a Gradle wrapper to fully integrate the Android plugin for Gradle. You can build your Android apps from within Android Studio and from the command line on your machine or on machines where Android Studio is not installed.
Android studio comes bundled with gradle and in the screenshot I can see gradel folder, gradlew and gradlew.bat and build.gradle files. So (hopefully) all you need to take care is build.gradle files.
I would strongly suggest you to go through link
If you have time go through this course

importing github project into android studio

I set up git in Android Studio
http://maxrohde.com/2014/08/18/import-github-project-to-android-studio/
Then imported this project
https://github.com/GautamGupta/Simple-Android-OCR
The following error was displayed:
Migrate Project to Gradle?
This project does not use the Gradle build system. We recommend that you migrate to using the Gradle build system.
What can I do to fix this?
That project hasn't been modified in two years, really four for most of the project, so it uses the older project layout and was very likely developed using Eclipse rather than Android Studio.
Here is the Google reference for migrating a project from Eclipse to Android Studio:
https://developer.android.com/sdk/installing/migrate.html
An option if simply importing doesn't work is to install Eclipse and do an export from there to Android Studio. While you could just work in Eclipse it is deprecated for Android development and you'll find many more up-to-date resources for Android Studio.
How do you import an Eclipse project into Android Studio now?
Android Studio's default build system is Gradle. That GiftHub project is not using Gradle build system. Probably created from Eclipse (Ant build system)
So when you open a project that does not use Gradle build in Android Studio, it will ask to convert the Project to Gradle based build. You just give yes on the popup, it will take care of everything.
http://gaut.am/making-an-ocr-android-app-using-tesseract/#comment-184181
here it explains solutions for gradle errors
That's not an error!
The recommended build system for android projects is gradle.
But the author of this project in github did it using only eclipse without any special build system.
You just need to answer "yes" to that popup message and Android studio will convert the project to use gradle

Exporting an eclipse project as gradle

I have been trying to export my eclipse project as a gradle build file to use it with Android Studio but I can't seem to make it work correctly.
When I click "Finish" nothing happens. If I repeatedly click it, I can see a progress bar that shows for a millisecond and then vanishes.
My ADT is version 22.3 (which is the latest) and I have tried all of the solutions I found on google as well.
Similar questions can be found here:
Eclipse Gradle export of Android project does nothing
Cannot generate gradle.build files from Eclipse
As you can see, there is not really a solid solution for this problem, but people wrote they created it manually. I don't know how to do so though.
Is there any solution for this problem that I haven't heard of? If not, how can I create the file manually?
Apparently, the current edition of the export-to-Gradle support in Eclipse cannot handle a project that is attached to an Android library project. In that case, you would need to (temporarily) detach the Android library project, export the main project, then modify build.gradle to use the library project (manually or via Android Studio).
Generating build.gradle files FIRST FOR ALL of the projects in my dependencies ONE AFTER ANOTHER worked for me.
I generated build.gradle (with export wizrd for facebook, play and whatever other projects I imported and used in my project).
For not trivial Android project you should do it manually.
For the latest build.gradle template for classic Android project check gh.c/N/n-1/b/m/o.n.e.e.g/docs/android/build.gradle.
You can continue to develop in Eclipse with ADT and run Gradle build using Nodeclipse/Enide Gradle for Eclipse
(marketplace)
Some screenshots for Gradle for Eclipse:

Categories

Resources