How to Compile Sample Code - android

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

Related

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.

Android build application: gradlew does not exist

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.

How to create .apk from HelloWorld sample of Cocos2dx?

I am using Windows 7 x64, cygwin, Eclipse Juno cpp, jre6, android ndk r8b, latest cocos2dx for windows. I have tried this tutorial link.
http://www.cnblogs.com/ybgame/archive/2012/06/07/2540693.html
I have overcome the error. But unfortunately, the Eclipse builder don't generate the .apk file. The console's output is here:
Notice that, there is no "make" command called. This is different from the tutorial link above, where the last part of tutorial, the console's output is showing the make command called.
right click on your Eclipse Project -> Android Tools-> Export signed (or unsigned) Application Package
compile the project in msys or cygwin and then import/ create project from source and give a name. click on the run button.you will notice the project run on emulator all is set . good luck.

NDK Automatic build in eclipse OSX Invoking autoreconf in build directory:

this time with a droid related question.
Im running Eclipse Helios and Mac OS X 10.6.8
I have been following a book and a few tutorials on building the NDK from both command line and Eclipse.
I am copying the source over there is no static library business. I can compile from the command line fine with the "ndk-build" executable and it works fine.
Though i need to compile inside Eclipse for the reasons i don't need to go into here.
Ive tried 2 techniques and the one i have seen working is to convert my Project to a c++ project and then in Project / Properties / c/c++ Build tab / Build Command i set to ndk-build , this is set to be visible in my path (hence why it compiles when i go to directory and use ndk-build from Terminal)
I then in the C/C++ General tab add the following locations as include directories :
/Users/Me/Code/Android/android-ndk-r7b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/include
/Users/me/Code/Android/android-ndk-r7b/platforms/android-9/arch-arm/usr/include
/Users/me/Code/Android/android-ndk-r7b/sources/android/native_app_glue
Then when i go to compile i don't get any out put i just get the following error:
Invoking autoreconf in build directory: /Users/me/Code/Android/DroidBlaster
sh -c autoreconf -i
autoreconf: `configure.ac' or `configure.in' is required
Configuration failed with error
Ive tried a few other tutorials but to no avail, if i could award a bounty on this is would as its urgent i get this fixed.
Cheers community :)
NOTE:
Ive worked out that it is using auto tools to build the project where this is incorrect as i should be building with the NDK , getting closer to an answer hopefully. Seems that i cant convert my Android project with CDT to a custom build configuration, might be a bug to do with Eclipse, trying a fresh install
Ok so i worked it out, it was because i was trying to compile using Auto tools when i should have set up the project when i should have been using "Convert to C/C++ project" didn't help though that eclipse installed CDT incorrectly and i had to reinstall to get the right plugins.

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"

Categories

Resources