Android build application: gradlew does not exist - android

This is the first Android application I am running. I am reading up the tutorial and following it (as much as I can).
I would like to get myself comfortable with the CLI instead.
I created a project using "android" executable. Although to build the application it says to run the "gradlew" executable which is supposed to be in my project's root. I don't see it there.
What might I be missing ?
Created the project using
android create project --target 1 --name HelloWorld --path HelloWorld --activity HW --package com.developers.helloworld

Indeed, it does not exist, because when you create a project from the command line, the generated project is an Android project without gradle.
You have 3 options however:
Use the official IDE supported by Google - Android Studio - to build and run your apps. (recommended), or
Download and install Ant and
a) Change directory to your project root.
b) Execute from command line ant debug to compile your project.
c) Then adb install YourApp.apk to transfer the apk to your device (once compiled successfully, apk you'll find in the bin directory), or
Manually add Gradle to your project. But keep in mind that Gradle is a build tool that expects a project to have a specific directory structure, if you don't want to configure anything.
In general, is good to know what happens behind a shiny IDE, and know let say, how to generate an android project on your own, from the command line. This also is useful when you want to use an IDE of your preference, or have more control over the Android build.
But, honestly, if you are just getting started with Android, I would highly suggest you use Android Studio. With this option you get an intelligent code editor, implicit support for Gradle, access to a multitude of open source projects from Github that already use the gradle project structure, and other advantages.
UPDATE: how to view logs:
from command line: adb logcat
from GUI: navigate to <android-sdk>/tools, find and open monitor.
Once the window opens, you'll find a tab called LogCat, usually located in the left - bottom of the window, but if it is not there, then go to: Window -> Show View -> Android -> LogCat -> OK, to add it.
note: make sure only one device is connected to adb bridge
for filtering:
check this & this.

The tools/andoird create project has the --gradle flag to specify to use the gradle template instead of ant template.
Use tools/android create project help for more details.

Related

Android Studio vs command line compile /w gradlew

As described here in the Android Studio docs, one can build an Android app from the command line with the gradle wrapper generated by Android Studio. The command line window in Android Studio shows exactly this, i.e. a call to gradlew assembleDebug (or a similar task). However starting a terminal on macOS and calling the gradle wrapper with that exact call sometimes yields other results, i.e. either one is able to build from Android Studio, or the command line, or both (which is ideal, but unfortunately not always true).
Who can explain what other settings the Android Studio IDE sets for their environment and where to find them, how to reproduce these settings easily in a CI environment (e.g. Jenkins, Bamboo, ...) and how one would consistently store these settings in a VCS along an Android project.
In the root of the project you have gradlew.bat, which is how you can run it in the first place. If you open this file, you see the code for building and everything else Gradle does.
Whether you build from the command line or ANdroid Studio, the gradlew.bat file is used. So building and other stuff you do with the gradlew command all use the same file whether it is from the command line or Android Studio's integrated tools.
You can open the file(s, there's gradlew and gradlew.bat in the project root) and see how it works if you wanted too, though these files are usually automatically generated by Android Studio (it is possible to make your own config as well, though there's rarely a need for that). And for including in vcs, make sure the files aren't listed in .gitnore (or whatever vcs ignore extension you have)

Cannot update project from terminal in Android

I am developing an Android project. In my project, I need to do OCR. So found this tutorial http://www.codeproject.com/Tips/840623/Android-Character-Recognition. I am trying to follow that tutorial. But I am having problems with set up, especially with updating project from terminal (tess-two folder). See what I have done below.
I downloaded tess-two from this link
https://github.com/rmtheis/tess-two/
Then I installed android NDK to build that project
I set environment variable under PATH
Then I run below command in tess two folder from terminal
ndk-build //this took around 30 minutes. I closed command windows after successful built
Then I run this command
android update project --path C:\tess-two-master\tess-two
The problem starts when I run that command because I cannot run android command from terminal. So I found solution from Stack Overflow. I needed to set ANDROID_HOME and environments variable under PATH. Then I tested "android" command and it is working.
Then I run this command again
android update project --path C:\tess-two-master\tess-two
This time, it is giving me this error
How can I solve this error? Why my update command is not working? What is wrong with my code? I am using Windows 64 OS.
This is another way. Installing using Grandle
I tried another way to install tess-two. I installed using Gradle like this according to documentation. But I cannot access to TessDataManager because it cannot be found in project.
Gradle
dependencies {
compile 'com.rmtheis:tess-two:6.0.2'
}
This is error
As you can see, I cannot access to TessDataManager class. How can I import that class?
The tess-two project has been updated to include a pre-compliled AAR that can be incorporated into your app by editing your app's build.gradle file.
This means that you can skip the steps of importing/compiling the library yourself, and follow the usage instructions on the tess-two project. After following the usage instructions, you'll be able to refer to the tess-two classes -- including the TessBaseAPI class -- directly from your project.

How do I build an Android project using Ant? (IntelliJ IDE)

I've a project in the IntelliJ IDEA IDE and I want to set up a parallel, production Ant build process that I can extend over time.
I have used IntelliJ's feature to create an Ant build file, and it is on the Build menu, so the Ant build process is running, and working within the IDE. All good.
But the Ant script IntelliJ has created is only compiling to class files, and is not doing a full Android build process through to an APK (as far as I can tell).
Can you point me towards a reference source (or an example) to help me understand how to get an ANT script doing a full build of an Android project?
If you know, would also be v useful to know how to then extend it to include Proguard, production signing, and inserting the production Maps key :)
Use this as a starting point:
http://developer.android.com/guide/developing/other-ide.html
I don't know IntelliJ but I shoudn't be very hard to create an ant file with the most frequent commands you need.
UPDATE:
run the following command:
android create project --target 8 --name "MyFirstProject" --path /path/to/project --activity StartingActivity --package net.sample.package
This will create a project structure. This includes a build.xml file that contains targets to build the project.
To build the application, in the root folder (/path/to/project/) run:
ant debug
It should compile your application.
You may have to install or configure ant before this works correctly but you should be able to figure it out by yourself! :)
(All the info is in the link I posted earlier)
It's pretty well described in SDK documentation. Just 3 steps to make it work:
Assuming you have been developing your activity for a while with such powerful thing as IntelliJ Idea. So as Ollie mentioned in comment you don't have to create android project from scratch. Run in command line:
android update project --path "Path to your project" --target "android-X"
where X is API level
After step one build.xml was created automatically. Now you open IntelliJ, go to ant build panel and add that build.xml.
The important step is to open properties of created task and add debug OR release to command line at execution tab.
Now you can run target and enjoy the result. It will take some more efforts to compile into signed release.
Note: your existing project structure should match to android project. Please review documentation. E.g. I had external library put in "lib" subfolder and I managed it to work only after renaming "lib" to "libs"

How to Compile Sample Code

I'm breaking into GUI programming with android, trying to compile and analyze Lunar Lander sample program. The instructions for using Eclipse say to select "Create project from existing source" but that option doesn't exist. If I select File->New->Project I can select "Java project from Existing Ant Buildfile". Using that I've tried selecting various xml files as "Ant Buildfile" but all give me the "The file selected is not a valid Ant buildfile" error.
I just want to run GUI sample projects, preferably with Eclipse. Any useful tips will be appreciated.
First of all you need to install Eclipse ADT plugin, here are the instructions http://developer.android.com/guide/developing/eclipse-adt.html.
Then you can import sample code in two ways:
File -> New -> Android Project, and choose "Create project from existing source"
If it is already an Eclipse project, click File -> Import, after that right click on the Project and choose Make it an Android Project
I read you prefer Eclipse, but you can always work from command line.
In a GNU/Linux system it's possible to do
$ cp -r $ANDROID_SDK/samples/android-15/LunarLander .
$ android update project --path LunarLander/ --target 3 --subprojects
$ cd LunarLander/
$ ant debug install
You have to choose the target according to your system.
It's possible to pick one id from the list you get with this command
$ android list targets
It should be File->New-> Android Project you need to select. Apparently, you didn't install Android SDK
In the past you can use "ant" to compile:
https://tthtlc.wordpress.com/2015/08/01/how-to-quickly-compile-all-the-android-samples-via-command-line/
But since June 2014, the SDK has been encouraging user to migrate to using gradle, but it is frauds with lots of problem. By June 2015, compilation has been mostly successful. Here are the steps:
https://tthtlc.wordpress.com/2015/10/30/how-to-build-android-sdk-samples-using-gradle/
And the full compilation of all the samples under the "android-22" branch: I have 84 successful and 19 failures.
The full logs is available here:
http://pastebin.com/33JBDAqj

Working with android and ant scripts for building applications

I want to know if we can create builds using ant's build.xml and when i'm trying to do this an error is displayed SDK location not mentioned and besides that I'm unable to find local.properties file to mention the SDK Location
My aim is that I want to use my exiting code and make a build for new Android SDK's with changes in the resources and and some constant values is this task Possible with making a build using Ant and if by some other way.
I have no idea about Ant and its functioning so it would very appreciable if minute details are also provided.
Well, first thing to do is get some knowledge on Ant, you'll need it to be effective. Just do a google for Ant tutorials.
For Android builds, create a sample project using the android command line (use android --help to see all options):
android create project -n SampleProject -t 7 -p ./sample -k com.sample -a MainActivity
This will generate a sample any build script that you can use as a starting point. To really understand how Android uses Ant, you'll want to take a look at the "android_rules.xml" file located at:
<android-install-dir>/platforms/<any-platform>/templates/android_rules.xml
This file has the definition for all the Ant targets used to build an android project. You can use those targets in your extension of the build.xml file that gets generated when you create the sample project

Categories

Resources