So I decided to create and record my first Android app.
Obviously I got into many stuck situations that I will detail below.
The best way to start is opening Android Tutorial page.
It will basically tell you to set up the following requirements:
- Install the SDK
- Install Eclipse and ADT plugin
- Install Java SDK (JDK) with the same CPU level as the SDK (32 bit or 64 bit)
The next stage is running Android SDK and downloading and installing all the appropriate packages.
This is a very important step and I advise doing it a few times by closing and reopening the application because it will often get more and more updates which are required in order to make apps compile correctly.
Furthermore, I will recommend installing these right away:
- Tools: Android SDK Tools, Android Platform Tools and Android Build Tools
- Android 4.4 (API 19) with SDK Platform and ARM EABI v7a System Image
- Extras: Android Support Library and Google USB Driver
- Using Eclipse with ADT is the fastest and simplest way of creating Android apps.
- We can just create a new app based on the Android Hello World template.
If we run into the "r cannot be resolved" error, there are a few things we can do:
- Clean and rebuild the project
- Quit Eclipse and start it back
- Open SDK Manager and do another update
- Do Ctrl+Shift+O to get the includes and then remove the "r" include
- All of the above!
There are three main files:
Contains your app details, name, version and capabilities.
You may want to change package="com.example.***" to package="com.yournamespace.***" as well as changing the import in the Main Activity and the com.example.*** file name in the project. Failing to do the above will throw:
Use um nome de pacote diferente. "com.example" é restrito. [PT]
Use a different package name. "com.example" is restricted. [EN]
As well as all other files in the res folder, this file name should me lowercase and use underscore as separator if need be. This particular file is the Activity. It is the "stuff" that your application does and can call other pages or activities.
This is your actual app. Your application project will be compiled into a single file with the apk extension that can be later uploaded to the store.
Now we just need to create our app code and contents, such as:
- Layout type (e.g. LinearLayout uses position awareness between controls and RelativeLayout lets you move controls around)
- Button and its code
- String resources and localization (basically create new folders such as \res\values-pt-rPT with a copy of strings.xml with translated values)
- Google Analytics (download v3, create the libs folder in the project, move the .jar file over there and follow the code changes as well as creating a new property in analytics to get the property ID)
Publishing an app to the store has a few requirements.
- Register to the developer console and pay $25 (should be a one time payment)
- Create a minimum of an application icon (PNG, 512x512) and two screenshots (to take the screenshots from a phone, run sdk\tools\monitor.bat)
- Each app submission should increase the app version in the manifest or you will get
Use outro código de versão para seu APK. Você já tem um APK com o código de versão 1. [PT]
Use another version code for your APK. You already have an APK with the version code 1 [EN]
- The app must be digitally signed right after the last build, before submitting to Google or you will get:
Você fez o upload de um APK não alinhado no zipalign. Execute o zipalign no APK e faça o upload novamente. [PT]
You have uploaded an APK not aligned with zipalign. Execute zipalign in the APK and upload it again. [EN]
This process is quite easy in Eclipse:
- Right-Click the Project Name, click "Export"
- Pick Android, Android Application
- For the first time, create a new Keystore, add a custom private password, then in the next screen, set the expiry to 25 years (recommended), add the password again and that's it. Next just just reuse the Keystore.