2017/02/26

Run gradlew in terminal instead of Android studio

About

Sometime it is useful for running gradlew in terminal directly. Therefore, here are problems I have solved when I am trying to do so.

Problem 1: Insufficient space for object heap

$ ./gradlew tasks check
...
-----------------------
Error occurred during initialization of VM
Could not reserve enough space for 1572864KB object heap
...

Solution

Define an environment variable in order to limit the heap size.
$ export _JAVA_OPTIONS=-Xmx512M

Reference

Problem 2: Invalid JDK installation

$ ./gradlew tasks check
.....
* What went wrong:
Execution failed for task ':app:compileReleaseJavaWithJavac'.
> Could not find tools.jar. Please check that C:\Program Files (x86)\Java\jre1.8.0_121 contains a valid JDK installation.
....

Solution

Explicitly set the JDK path through environment variable. For me, I simply reused the JRE from Android Studio.
$ export JAVA_HOME="C:\Program Files\Android\Android Studio\jre"

An example of successful run

$ ./gradlew tasks check
.....
BUILD SUCCESSFUL

Total time: 33.858 secs
Picked up _JAVA_OPTIONS: -Xmx512M

$ env | grep JAVA
_JAVA_OPTIONS=-Xmx512M
JAVA_HOME=C:\Program Files\Android\Android Studio\jre

Useful materials

An user guide on gradlew from android.

2017/02/19

Change a display card

Background

  • Current equipment
    • Motherboard: GA-P61-USB3P
    • Display card: GV-N56GOC-1GI
Recently, my screen is distorted somehow.
This is a blog about how I react on this disaster :(

Confirm which components are broken

  • Possible victims:
    • Display card
    • PCIE slot
    • Monitor
    • DVI Cable
    • PSU
Although I am pretty sure that problem is sourced from my display card, I need a confirmation. Luckily, I have an on-board display and a display card lent from my colleague.
Results of on-board display and another display card:
I need to buy a new display card :(

About shopping

| ITEM \ Display card | GV-N56GOC-1GI  | GTX 1050 Ti GAMING 4G | GTX 1050 GAMING 2G | Inno3D GeForce GTX 1050 | Inno3D GeForce GTX1050TI Compact | GV-N105TWF2OC-4GD | GV-N1050WF2OC-2GD | GV-N105TG1-GAMING-4GD | ROG-STRIX-GTX1050TI-O4G-GAMING | PH-GTX1050-2G  |
|---------------------|----------------|-----------------------|--------------------|-------------------------|----------------------------------|-------------------|-------------------|-----------------------|--------------------------------|----------------|
| GPU Clock (MHz)     | 830            | 1303                  | 1366               | 1354                    | 1290                             | 1328              | 1392              | 1366                  | 1392                           | 1354           |
| Card Bus            | PCIE 2.0 16pin | PCIE 3.0 16pin        | PCIE 3.0 16pin     | PCIE 3.0 16pin          | PCIE 3.0 16pin                   | PCIE 3.0 16pin    | PCIE 3.0 16pin    | PCIE 3.0 16pin        | PCIE 3.0 16pin                 | PCIE 3.0 16pin |
| Memory Type         | GDDR5          | GDDR5                 | GDDR5              | GDDR5                   | GDDR5                            | GDDR5             | GDDR5             | GDDR5                 | GDDR5                          | GDDR5          |
| Memory Clock (MHz)  | 4008           | 7008                  | 7008               | 7008                    | 7008                             | 7008              | 7008              | 7008                  | 7008                           | 7008           |
| Memory Size (GB)    | 1              | 4                     | 2                  | 2                       | 4                                | 4                 | 2                 | 4                     | 4                              | 2              |
| Memory Bus (Bit)    | 256            | 128                   | 128                | 128                     | 128                              | 128               | 128               | 128                   | 128                            | 128            |
| Physical Size (mm)  | H43  L238 W130 | H39 L229 W131         | H39 L229 W131      | H99.8 L145 W???         | H99.8 L145 W???                  | H40 L229 W118     | H40 L229 W118     | H40 L229 W118         | H40 L241 W129                  | H37 L192 W111  |
| Power               | 2 x 6 pin      | 6 pin                 | 6 pin              | 4 pin                   | 4 pin                            | 6 pin             | 6 pin             | 6 pin                 | 6 pin                          | ????           |
| GPU FAN             | 2              | 2                     | 2                  | 1                       | 1                                | 2                 | 2                 | 2                     | 2                              | 1              |

Install - Bios upgrade

  • Check bios version
    • Window terminal
      • wmic bios get smbiosbiosversion
    • Why update BIOS?
      • Problem from Nvidia form
An example for running command above
C:\Users\Mond>wmic bios get smbiosbiosversion
SMBIOSBIOSVersion
F5

Install

  • Take off the covers on the DVI port
  • Plugin the card into Motherboard carefully
  • Plugin the power cable
  • Enjoy

References

2017/02/13

A decision on installing Docker in WIN 10

Before reading

In my opinion, the feeling of using docker in Window is PRETTY BAD when comparing using docker in Ubuntu. If there are choices for you, do them on Linux platform. Things are smooth and easier.

Decision

Before downloading an installer and “next” “next” “next”, a decision on how to run docker you need to made first.
  • Run docker natively but UNABLE to run Virtual box etc anymore
  • Run docker in a Virtual box instead
Why there is such a decision? According to their website, they are using a Microsoft virtualization solution Hyper-V.
The reality of using Hyper-V is it conflicts with other virtualization solutions like Virtual Box and they are not able to run in a parallel manner. Although there is a kind of remedy, it is inconvenient at all.

If you prefer native docker solution

Please download the .msi executable from here

If you want to preserve Virtual box

Please download the docker toolbox from here

My choice is docker toolbox

I have picked the docker toolbox as my android simulators do not work with hyper-v and I do not like the boot loader switching remedy at all.

2017/02/05

Why written nested classes in Android

About

When I am working on my android project, I am quite curious about why templates from Android Studio prefers Nested classes design. After digging deeper in this issue, I believe this is worth for me to write a blog to record them down.

What is a Nested classes?

For detail please read this tutorial and this answer. Basically, Nested classes are classes defined inside of another class. For example,
class OuterClass {
    ...
    class InnerClass {
        ...
    }
}
InnerClass is a kind of Nest classes.
There are 4 types of inner classes in general:
  • static class: declared as a static member of another class
  • inner class: declared as an instance member of another class
  • local inner class: declared inside an instance method of another class
  • anonymous inner class: like a local inner class, but written as an expression which returns a one-off object

Why using nested classes?

According to the tutorial, pros for using nested classes:
  • Able to access container’s private attributes, methods for non static inner class
  • Saves some typing in certain cases for anonymous inner class like click handlers
  • Better code organizations for related classes
  • Enhance performances in certain cases like reusing identical handlers
According to this answer and this answer, cons for using nested classes:
  • Waste memories as there are implicit references from inner class to outer class
  • High potential causing memory leaks when using non static inner class

Idea of how memory is leaked

  • Objects are unable to be garbage collected if there are references to them
  • Inner class always holds a implicit reference to outer class
  • If there is a reference to the inner class object outside of the outer class,
    • Inner class object is unable to be collected
    • Outer class object is unable to be collected too as it is pointed by the inner class object
    • This is a serious leak in android activities (outer class) as they have associated many resources like views and context etc

Words before end…

I strongly suggested you to go through the answers I pasted in this blog especially this one. The one I highlighted answering why and how memory leaks in nested class very well.

References: