Saturday, October 15, 2016

A checklist on common failures when installing Android Studio and running your Hello World program.

This is a checklist on common failures I met when I was trying to install Android Studio and to make the Hello Android program run.

1. Is the path to JDK set up properly?

Inside your project, go to File -> Project Structure to pop up a window and then check JDK location inside the SDK Location page.

Outside any of your projects, you can also set the same thing in Android Studio main screen. In the bottom, you see configure menu, and click to go to Project Defaults -> Project Structure.


 - When your JDK path is not set up properly, you may see some errors like

     "Error:CreateProcess error=216, This version of %1 is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher."


  cf. android-studio-error-errorcreateprocess-error-216-this-version-of-1-is-not-c 


2. Gradle version problems

Inside your project, go to File -> Settings to pop up a window and then find Gradle in Build, Execution, Deployment section. There can you find a place for you to set the path of your Gradle installation.

Note that build.gralde often has a version information about Gradle your project use to be built with.



  cf. gradle-project-refresh-failed-after-android-studio-update

3. JVM options for Gradle

I oftne see JVM options that should be modified for successful builds. Open up  gradle.properties in you project. You may see JVM options like

 - org.gradle.jvmargs=-Xmx1536m

but people in stackoverflow recommed me to cut it the maximum size down to

 - org.gradle.jvmargs=-Xmx512m -XX:MaxPermSize=512m

I do not know exactly why such a change gives me a success in building my Android project, but 1536m seems to be quite a big number for my notebook computer with 4GB RAM.


 - When you have a problem as one explained above, you may see a error like

 "Error:Unable to start the daemon process.
  This problem might be caused by incorrect configuration of the daemon.
  For example, an unrecognized jvm option is used.
  Please refer to the user guide chapter on the daemon
  at   http://gradle.org/docs/1.10/userguide/gradle_daemon.html
  Please read below process output to find out more:
    -----------------------
  Error occurred during initialization of VM Could not reserve enough space for object
  heap Error: Could not create the Java Virtual Machine.
  Error: A fatal exception has occurred. Program will exit."

 cf. android-studio-gradle-project-sync-failed

4. Too much space on C drive on my Windows due to Android studio, SDK, virtual machines, and projects.

Usually, I am using Windows where C drive is relatively small such as 100GB and D drive is relatively big such as 400GB. But Android Studio seems to install more on C drive by defaults. It may result in the shortage of C drive space in your Windows PC. It is possible to do the followings to mitigate this problem:

 - You can move Android SDK installed in C drive onto your preferred directory in D drive. After installing Android Studio, you can set SDK Location from the main Android studio window (Configure -> Project Defaults -> Project Structure -> SDK Location)

 - It does not mean that you Android Virtual device is created there. Each AVD is created under C:\Users\YourUserName\.android\.avd.  Until now, I do not know how I can move this directory to D drive. Once I know, I will post the information.

 - When you create you Android project, be careful to choose some folder in D drive. The default location is C drive.




Saturday, October 01, 2016

Using Gradle to build the standard C++ using VC++ compiler in Visual Studio 2015

This is a post about using Gradle to build the standard C++ using VC++ compiler in Visual Studio 2015 quickly.

I am using Gradle 2.4.7. My source code is the standard C++ as in the following directory structure on Windows:
 - myproject
 - myproject\src
 - myproject\src\main.cpp
 - myproject\build.gradle
main.cpp is just a Hello world C++ program.

I have Visual Studio 2015. I like to use its C++ compiler for the standard C++ programs.
build.gradle is as follows:
apply plugin: 'cpp'

model {
    components {
        main(NativeExecutableSpec) {
            sources {   
                cpp {
                    source {
                        srcDir "src"
                    }
                }
            }   
        }
    }

    binaries {
        all {
            if (toolChain in VisualCpp) {
                cppCompiler.args "-IC:\\Program Files (x86)\\Windows Kits\\10\\Include\\10.0.10240.0\\ucrt"
                linker.args "/LIBPATH:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.10240.0\\ucrt\\x86"
            }
        }
    }
}
The extra compiler option and linker option is due to some change in Visual studio 2015 from its previous versions. Without the options, you will get a compilation not able to finding corecrt.h or a linker error not able to finding libucrt.lib.
Hope this will help you to begin C++ compilation with Visual Studio 2015 quickly!!!