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
Related
For a new Android Studio Project I have somehow generated the files that are generated whenever we create a new project through Android Studio through a python script. This script also places the java and layout xml files in their respective locations. Now I want to build this project and generate the APK through command line only (without opening Android Studio).
I found the android command but that command is deprecated and no longer supported.
Image of the message when using android command
Now, can anyone please suggest any other way to build and create APK through command line?
I found this ant software but am unable to use it as I don't know how to create the build.xml file.
Please help me out.
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.
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.
I am interested in making Android apps on demand. Depending on the clients request, my web site would send me a JSON file direct to a Windows application that I have created in Delphi. This one would save the file inside the Android app source folder and then, execute a command line telling the Android compiler to generate the APK file and send it to my client, all that without my presence.
The Android project was made with MotoDev. And it uses the Android SDK that is in my root.
How should I configure the command line to achieve this from inside my Delphi program?
I will also need to change the manifest to put a new version number so it does not conflict with other clients version.
Android uses the Ant build system, so you can create a build.xml and build.properties file for your project.
You'll need to create the build.xml file first though:
android update project -p .
This will generate a build.xml file. You should probably customize the build steps and targets for your project. A good idea in your case would be to have the build.properties file generated by your website for the specific build... Then include it via the build.xml file. In particular, you will need to specify in the build.properties file where the signing keys are, and what the password is:
Build.Properties:
key.store=keystore.dat
key.alias=signing_key
key.store.password=password123
key.alias.password=password123
The build process using ant also allows you to do variable replacements in Java files, which might be another idea. It would allow you to customize the build process further on a client by client basis.
By default, the build is triggered by:
ant clean
ant release
Another neat idea: Have Ant copy the resulting APK file to a network share accessible by the website by placing a < copy ... /> line in the < target name="release" > section.
Create build.xml at project creation time
If you start a new project with:
android create project \
--target 1 \
--name MyName \
--path . \
--activity MyActivity \
--package com.yourdomain.yourproject
the build.xml file used by ant will be generated.
The android tool is present in the tools/ directory of the SDK which you downloaded.
Create debug releases
Besides:
ant release
for final releases, you can also create debug releases with:
ant debug
Location of generated apk
Generated apk are placed under bin/.
The most important outputs are:
MyName-debug.apk
MyName-release.apk
but some intermediate apks are also generated, in particular unaligned and unsigned versions.
But most of the time you can forget where they were created and just run:
ant debug install
ant release install
to get them installed. But make sure it is working with adb first: adb devices command not working
Tested on Ubuntu 15.10, Android 23.
Android doesn't directly use ANT build systems now. It uses Gradle, which is based on Groovy. You can learn more about build systems here.
You can see the list of available tasks you can run on using this command
gradlew tasks
To initiate a debug build, invoke the assembleDebug task
gradlew assembleDebug
You can install your app using the adb tool via this command
adb install path/to/your_app.apk
To learn more about building on command line, follow this comprehensive article.
Also you can read this article on "Why Build Your Java Projects with Gradle Rather than Ant or Maven?"
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"