Sunday, April 26, 2015

Android Coding: How to start coding for Android

Hello everyone,

   Today I am going to show on simple steps how to start coding using Android app.

1) First of all you need to download the Android studio that is basically the Eclipse( modified for it) at https://developer.android.com/sdk/installing/index.html?pkg=studio

2) Run the file  android-studio-bundle-141.1980579-windows.exe


3) Install the SDK from Oracle to allow you use java.sh or .exe





4) Choose components that you are going to use.

5) Define where you are going to install them


6) This is a very important step: You are going to define how many GB are you allowing for Android Emulator. Please note that this can affect your machine performance depending on the size of your project.




Installation completes successfully

7) Running Android Studio


8) Next step is create your own Android Java Project







Now that we have our project created, and you can start modifying it ,creating some interactions for your user.

9) On this example we are going to create one regular button that calls a textView to be displayed.

So, here it is our project screen:


10)First of all, we are going to create our button called button, and out text to be displayed called textView1. Once they are created into Android display, you should be able to see them on our main activity.xml(called activity_fullscreen_thiago_leoncio_blog.xml) as below:
  

11) This step now we are going to create the action on the java class called FullscreenThiagoLeoncioBlogActivity.java

//Please note that you should import the TextView from android.widget.TextView.


12) Now we should return to our main xml activity file called activity_fullscreen_thiago_leoncio_blog.xml, and make sure the button we added has the onClick action related properly added.




Now you can save your code and launch your Android emulator clicking on the green arrow (run button).

Choosing the type of device you want to emulate.

then click


...and if you click on this button.....


  On TOP the message that we wrote on onBtnTouch method





I hope it helps you.I am going to provide more articles related of mobile development next month.

Happy coding. Please send me an e-mail if you want this sample code.

Cheers,
Thiago Leoncio.

Saturday, March 21, 2015

Apache Cordova - Run Android app with VisuaStudio on Mac


Hello all,

    Today I am going to show you how to develop for Android using Apache Cordova on my MAC. I will also follow here all pre-requirements as well as providing the most common errors in order to help you to reach your goal - launch your Android app on Mac.

So, the first thing is install the dependencies for it:
1-Node.JS

1.1-Download and Install Node.JS for Mac:  https://nodejs.org/en/download/

1.2- Follow the steps and complete successfully your NodeJS installation.
1.3- Make sure you add the npm as well as the node paths over your .bash_profile to avoid issues.
2- Install Apache Cordova using npm.

3-Hit Command +P on your Visual Studio IDE code and run Cordova:Prepare .


4-Now the common issues you might have:

4.1- FIRST COMMON ERROR: ANDROID_HOME not defined:

The fix is make sure you have your Android-sdk installed and set as environment variable, check the next picture.



4.2- SECOND COMMON ERROR: Another very common issue is when you are developing for multiple emulators, sometime you are testing android and your environment platform is set for IOS as below - during cordova prepare command:

Error: The provided path "/blablabla/" is not a Cordova iOS project.


Fix:
The fix for this is just go to your project home folder and run these commands:
- cordova platform rm ios (to remove IOS)
- cordova platform android(to add Android)


Now your Error: THe provided path "blablabla" is not a Cordova iOS project is fixed.

4.3- THIRD COMMON ERROR:
Running command: /Users/ThiagoGuimaraes/workspace/myapp/platforms/android/cordova/build 
[Error: Please install Android target: "android-22".

Hint: Open the SDK manager by running: /Users/ThiagoGuimaraes/adt-bundle-mac/sdk/tools/android
You will require:
1. "SDK Platform" for android-22
2. "Android SDK Platform-tools (latest)
3. "Android SDK Build-tools" (latest)]
ERROR building one of the platforms: Error: /Users/ThiagoGuimaraes/workspace/myapp/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /Users/ThiagoGuimaraes/workspace/myapp/platforms/android/cordova/build: Command failed with exit code 2"
F
Fix:

   Make sure you have all required Android packages installed on your MAC running the command:

- [ANDROID-SDK-HOME]/tools/android as below:


Command +P : Cordova Build should work fine now as below:
4.4- FOURTH COMMON ERROR:
During the cordova run command you hit error related of emulator such as:

/tguimaraesMacpro/platforms/android/cordova/node_modules/q/q.js:126
                throw e;
                      ^
ERROR : No emulator images (avds) found.


Fix:
  To fix this one you must create an ADV running this command on your terminal window.
/us/local/Cellar/android-sdk.24.4.1_1/tools/android adv






Now, finally, you are good to run your cordova: run command.





Then......your app in Apache Cordova finally launched to the mobile universe!!!


Please, find more about Apache Cordova here:





Happy coding. I hope it helps you, and talk to you soon.

Thiago Leoncio.