AOSP 5.1.1 Renderscript Build Error

While building AOSP 5.1.1_r14 I encountered a build error with renderscript, in frameworks/rs. The error looks like following:

target level api 22 is out of range ('11' - '21')

The problem is AOSP 5.1 is API level 22, while it seems the renderscript is compatible till 21 only. Some searching through git logs of AOSP, I came across this commit. Although the commit is not directly applicable to current problem, but it provides a hint to solve the current compatibility issue. To summarise, the fix is, in core/ file, change the version number for variable renderscript_target_api := 21.