Saturday, July 21, 2018

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithDexBuilderForDebug'. > java.io.IOException: Could not delete path

I was working in a ReactNative project and while setting up it's environment was getting error as follows:

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithDexBuilderForDebug'. > java.io.IOException: Could not delete path


After removing the build directory from root directory -> android -> app 

it just did the trick :)

Error: Incompatible HAX module version 3, requires minimum version 4 in Android Studio


Sometimes it is needed to create virtual device while working on android studio that I did on working in an android project. But when tried to launch the device some errors occurred as follows:

Emulator: Incompatible HAX module version 3, requires minimum version 4
Emulator: No accelerator found.
Emulator: failed to initialize HAX: Invalid argument

So found the solution to sort this out as follows:

Steps:

Android Studio: Tools -> SDK Manager

Under Default Settings:

Appearance & Behavior -> System Settings -> Android SDK:

You should see “Android SDK Location” with text field. Copy that location and search through in your windows explorer. For me the location is: “C:\Users\YourUser\AppData\Local\Android\Sdk” in this location navigate through other segment like: 

\extras\intel\Hardware_Accelerated_Execution_Manager so the full path is: 

C:\Users\YourUser\AppData\Local\Android\Sdk\extras\intel\Hardware_Accelerated_Execution_Manager

And there find the file name “intelhaxm-android.exe” and click on it to install. 

After installing it launch again the AVD device.

Cool! It’s done J

Wednesday, July 18, 2018

Sort array of objects by property name in javascript

I was working with javascript sort method to sort out an array of objects with a scenario like I needed to sort by object property 'name' but using only sort method didn't fullfill my requirements so I came with additional method implemented as a middleware of sort method like below:

Current Result:
const objArray = [
{ name: 'Z', age: 32},
{ name: 'B', age: 23},
{ name: 'C', age: 45},
{ name: 'E', age: 33},
{ name: 'A', age: 53}
];

Expected result:
const objArray = [
{ name: 'A', age: 53}
{ name: 'B', age: 23},
{ name: 'C', age: 45},
{ name: 'E', age: 33},
{ name: 'Z', age: 32}
];

objArray.sort(sortBy('name', false));


function sortBy(key, reverse) {
 var moveSmaller = reverse ? 1 : -1;
 var moveLarger = reverse ? -1 : 1;
 return function(a, b) {
  if (a[key] < b[key]) {
    return moveSmaller;
  }
  if (a[key] > b[key]) {
    return moveLarger;
  }
  return 0;
 };
 
}

It may help someone like me :)