Showing posts with label android. Show all posts
Showing posts with label android. Show all posts

Tuesday, January 09, 2018

Android Studio nightmares

Today I tried to build an Android Studio that was written by someone else three years ago. After some initial progress I got stuck with Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception. After hours of struggle and fruitless trials, I finally looked at the details of the Gradle stack trace and saw that the top message was Execution failed for task :app:mergeDebugResources  and the bottom message was com.android.builder.png.AaptProcess$NotifierProcessOutput.out.

My problem was due to an image file name ending with .9.png. I changed the ending to .png and the problem disappeared. Thanks Gradle for the cryptic concurrent.ExecutionException (!) This sort of unhelpful error messages is a typical theme when developing Android apps, especially when dealing with legacy code. You can get stuck for days on problems that you could not have foreseen.

Monday, November 27, 2017

Mobile Games for Kids

Below is a list of mobile (Android) games that my 5 year old plays on his tablet and I recommend:
  • Minecraft
  • Monument Valley 2
  • Alto's Adventure
  • Samorost 3
  • Cat Quest
  • War Robots
  • Badland 2
  • Contre Jour
  • World of Goo
  • Bowmasters

Friday, March 31, 2017

Android client connecting to java server example

As a case study on how to use a VPS, I bought a VPS from Amazon LightSail, wrote a server in Java and a client in Android:

VPS:
  1. I selected the preconfigured Ubuntu option. It has no GUI, you have to do everything on the command line.
  2. I created a static IP. 
  3. In order to access it freely (ping etc.), go to networking tab, under firewall add “All TCP+UDP”
  4. On Ubuntu, I installed OpenJDK8:
    1. sudo apt-get update
    2. sudo apt-get install openjdk-8*
  5. I installed Putty to use as an SSH terminal
  6. I installed Filezilla for file transfers.
Server software:
  1. Wrote server in Java on my laptop and transferred the code to VPS via FileZilla.
  2. I used gson for object-JSON conversions. The latest gson jar file can be downloaded from here.
  3. I wrote a java build script in Ubuntu using nano.
    1. Note that if you write the script in Windows and transfer it to Ubuntu, it might not work because line endings in Windows and Linux are different.
    2. To make the file executable: chmod +x filename
  4. I built and run the server. I prepared a shell script and ran it like so: ./script.sh
  5. To make sure that server keeps running when I disconnect putty, I used nohup and disown
  6. Update 15.10.2017: To keep nodejs server running do the following: 
    1. nodejs index.js> stdout.txt 2> stderr.txt &
    2. Do not close putty by clicking the top right "x", type exit.
  7. To kill a process
    1. Note PID by running ps -ef (or better, pgrep <process name>)
    2. Kill process with sudo kill PID

Android client software:
  1. Wrote client in Android Studio.
  2. I used gson for object-JSON conversions.
  3. I had to use AsyncTask for connection, otherwise I get NetworkOnMainThreadException
The source code for java server and android client is on GitHub.

TODO:
  • Server: Handle multiple simultaneous connection requests

Tuesday, February 21, 2017

Android development tips

When developing Android apps with Android Studio, I get strange errors from time to time, whose solutions were not obvious to me:

Problem: When you create a Google Maps demo and run it using an emulator of API level 24 (e.g. Nexus 5 API 24), the app opens on the emulator with the message "...won’t run unless you update Google Play services".

Solution:  In \app\build.gradle file, com.google.android.gms:play-services version might be 10.2.0. Change it to 9.8.0 and your app will run fine.

Problem: In Android Studio, when I try to generate signed APK, I get "android execution failed for task validatesigningrelease" error.

Solution: Make sure you specify full path of key file.

Problem: When I try to generate signed APK, I get “Execution failed… method ID not in [0, 0xffff]: 65536” error.

Solution: If you are using Google Maps, limit the number of libraries you use by replacing in your gradle file the line compile ‘com.google.android.gms:play-services:9.8.0’ with
compile 'com.google.android.gms:play-services-maps:9.8.0' and
compile 'com.google.android.gms:play-services-location:9.8.0'

Friday, January 20, 2017

My first Android app: Rescue Map

A friend of mine is a member of the search and rescue organization AKUT. He asked if there is an app that could draw the estimated victim region on a map according to victim category.

The category specifies at what speed the victim is expected to be moving. The app has to have offline map capability so that it can be used when there is no reliable internet connection.

I did a quick search on Google Play and could not find anything that did the job. So, I decided to write it myself as a first project in Android. The source code is on GitHub. I don't plan on publishing it to Google Play until my friend says that the app is really useful and others could benefit from it.