When trying to build my ionic app in ubuntu it brings this error

BUILD FAILED

Total time: 14.083 secs

Error: /home/matynjr/newapp/platforms/android/gradlew: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

Where:
Build file ‘/home/matynjr/newapp/platforms/android/build.gradle’ line: 20

What went wrong:
A problem occurred evaluating root project ‘android’.

java.lang.UnsupportedClassVersionError: com/android/build/gradle/AppPlugin : Unsupported major.minor version 52.0
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Can you give us your ionic info output and your installed Android SDK packages?

here is my ionic info
ionic --version
2.2.2
ionic
_ _
() ()


| |/ _ | '_ | |/ |
| | (_) | | | | | (

||___/|| |||___| CLI v2.2.2

Usage: ionic task args

=======================
Available tasks:
(use --help or -h for more info)

start … Starts a new Ionic project in the specified PATH
serve … Start a local development server for app dev/testing
setup … Configure the project with a build tool (beta)
generate … Generate pages and components
platform … Add platform target for building an Ionic app
run … Run an Ionic project on a connected device
emulate … Emulate an Ionic project on a simulator or emulator
build … Build (prepare + compile) an Ionic project for a given platform.

plugin … Add a Cordova plugin
resources … Automatically create icon and splash screen resources (beta)
Put your images in the ./resources directory, named splash or icon.
Accepted file types are .png, .ai, and .psd.
Icons should be 192x192 px without rounded corners.
Splashscreens should be 2208x2208 px, with the image centered in the middle.

upload … Upload an app to your Ionic account
share … Share an app with a client, co-worker, friend, or customer
lib … Gets Ionic library version or updates the Ionic library
login … Login to your Ionic account
io … Integrate your app with Ionic Cloud services
security … Store your app’s credentials for the Ionic Cloud
push … Upload APNS and GCM credentials to Ionic Push
package … Use Ionic Package to build your app
config … Set configuration variables for your ionic app
service … Add an Ionic service package and install any required plugins
add … Add an Ion, bower component, or addon to the project
remove … Remove an Ion, bower component, or addon from the project
list … List Ions, bower components, or addons in the project
info … List information about the users runtime environment
help … Provides help for a certain command
link … Sets your Ionic App ID for your project
hooks … Manage your Ionic Cordova hooks
state … Saves or restores state of your Ionic Application using the package.json file
docs … Opens up the documentation for Ionic

and here are my sdk installed packages
matynjr@matynjr-HP-2000-Notebook-PC:~$ android list sdk --allRefresh Sources:
Packages available for installation or update: 177
1- Android SDK Tools, revision 25.2.5
2- Android SDK Platform-tools, revision 25.0.5
3- Android SDK Platform-tools, revision 26 rc1
4- Android SDK Build-tools, revision 26 rc1
5- Android SDK Build-tools, revision 25.0.3
6- Android SDK Build-tools, revision 25.0.2
7- Android SDK Build-tools, revision 25.0.1
8- Android SDK Build-tools, revision 25
9- Android SDK Build-tools, revision 24.0.3
10- Android SDK Build-tools, revision 24.0.2
11- Android SDK Build-tools, revision 24.0.1
12- Android SDK Build-tools, revision 24
13- Android SDK Build-tools, revision 23.0.3
14- Android SDK Build-tools, revision 23.0.2
15- Android SDK Build-tools, revision 23.0.1
16- Android SDK Build-tools, revision 23 (Obsolete)
17- Android SDK Build-tools, revision 22.0.1
18- Android SDK Build-tools, revision 22 (Obsolete)
19- Android SDK Build-tools, revision 21.1.2
20- Android SDK Build-tools, revision 21.1.1 (Obsolete)
21- Android SDK Build-tools, revision 21.1 (Obsolete)
22- Android SDK Build-tools, revision 21.0.2 (Obsolete)
23- Android SDK Build-tools, revision 21.0.1 (Obsolete)
24- Android SDK Build-tools, revision 21 (Obsolete)
25- Android SDK Build-tools, revision 20
26- Android SDK Build-tools, revision 19.1
27- Android SDK Build-tools, revision 19.0.3 (Obsolete)
28- Android SDK Build-tools, revision 19.0.2 (Obsolete)
29- Android SDK Build-tools, revision 19.0.1 (Obsolete)
30- Android SDK Build-tools, revision 19 (Obsolete)
31- Android SDK Build-tools, revision 18.1.1 (Obsolete)
32- Android SDK Build-tools, revision 18.1 (Obsolete)
33- Android SDK Build-tools, revision 18.0.1 (Obsolete)
34- Android SDK Build-tools, revision 17 (Obsolete)
35- Documentation for Android SDK, API 24, revision 1
36- SDK Platform Android 7.1.1, API 25, revision 3
37- SDK Platform Android 7.0, API 24, revision 2
38- SDK Platform Android 6.0, API 23, revision 3
39- SDK Platform Android 5.1.1, API 22, revision 2
40- SDK Platform Android 5.0.1, API 21, revision 2
41- SDK Platform Android 4.4W.2, API 20, revision 2
42- SDK Platform Android 4.4.2, API 19, revision 4
43- SDK Platform Android 4.3.1, API 18, revision 3
44- SDK Platform Android 4.2.2, API 17, revision 3
45- SDK Platform Android 4.1.2, API 16, revision 5
46- SDK Platform Android 4.0.3, API 15, revision 5
47- SDK Platform Android 4.0, API 14, revision 4
48- SDK Platform Android 3.2, API 13, revision 1
49- SDK Platform Android 3.1, API 12, revision 3
50- SDK Platform Android 3.0, API 11, revision 2
51- SDK Platform Android 2.3.3, API 10, revision 2
52- SDK Platform Android 2.3.1, API 9, revision 2
53- SDK Platform Android 2.2, API 8, revision 3
54- SDK Platform Android 2.1, API 7, revision 3
55- SDK Platform Android 2.0.1, API 6, revision 1 (Obsolete)
56- SDK Platform Android 2.0, API 5, revision 1 (Obsolete)
57- SDK Platform Android 1.6, API 4, revision 3 (Obsolete)
58- SDK Platform Android 1.5, API 3, revision 4 (Obsolete)
59- SDK Platform Android 1.1, API 2, revision 1 (Obsolete)
60- Android TV Intel x86 Atom System Image, Android API 25, revision 3
61- Android Wear ARM EABI v7a System Image, Android API 25, revision 3
62- Android Wear Intel x86 Atom System Image, Android API 25, revision 3
63- Google APIs ARM 64 v8a System Image, Android API 25, revision 4
64- Google APIs ARM EABI v7a System Image, Android API 25, revision 4
65- Google APIs Intel x86 Atom_64 System Image, Android API 25, revision 4
66- Google APIs Intel x86 Atom System Image, Android API 25, revision 4
67- Android TV Intel x86 Atom System Image, Android API 24, revision 10
68- ARM 64 v8a System Image, Android API 24, revision 7
69- ARM EABI v7a System Image, Android API 24, revision 7
70- Intel x86 Atom_64 System Image, Android API 24, revision 7
71- Intel x86 Atom System Image, Android API 24, revision 7
72- Google APIs ARM 64 v8a System Image, Android API 24, revision 11
73- Google APIs ARM EABI v7a System Image, Android API 24, revision 11
74- Google APIs Intel x86 Atom_64 System Image, Android API 24, revision 11
75- Google APIs Intel x86 Atom System Image, Android API 24, revision 11
76- Android TV ARM EABI v7a System Image, Android API 23, revision 3
77- Android TV Intel x86 Atom System Image, Android API 23, revision 9
78- Android Wear ARM EABI v7a System Image, Android API 23, revision 6
79- Android Wear Intel x86 Atom System Image, Android API 23, revision 6
80- Intel x86 Atom_64 System Image, Android API 23, revision 9
81- Intel x86 Atom System Image, Android API 23, revision 9
82- Google APIs ARM EABI v7a System Image, Android API 23, revision 20
83- Google APIs Intel x86 Atom_64 System Image, Android API 23, revision 20
84- Google APIs Intel x86 Atom System Image, Android API 23, revision 20
85- Android TV ARM EABI v7a System Image, Android API 22, revision 1
86- Android TV Intel x86 Atom System Image, Android API 22, revision 3
87- ARM EABI v7a System Image, Android API 22, revision 2
88- Intel x86 Atom_64 System Image, Android API 22, revision 5
89- Intel x86 Atom System Image, Android API 22, revision 5
90- Google APIs ARM EABI v7a System Image, Android API 22, revision 13
91- Google APIs Intel x86 Atom_64 System Image, Android API 22, revision 13
92- Google APIs Intel x86 Atom System Image, Android API 22, revision 13
93- Android TV ARM EABI v7a System Image, Android API 21, revision 3
94- Android TV Intel x86 Atom System Image, Android API 21, revision 3
95- ARM EABI v7a System Image, Android API 21, revision 4
96- Intel x86 Atom_64 System Image, Android API 21, revision 4
97- Intel x86 Atom System Image, Android API 21, revision 4
98- Google APIs ARM EABI v7a System Image, Android API 21, revision 19
99- Google APIs Intel x86 Atom_64 System Image, Android API 21, revision 19
100- Google APIs Intel x86 Atom System Image, Android API 21, revision 19
101- ARM EABI v7a System Image, Android API 19, revision 5
102- Intel x86 Atom System Image, Android API 19, revision 5
103- Google APIs ARM EABI v7a System Image, Android API 19, revision 27
104- Google APIs Intel x86 Atom System Image, Android API 19, revision 27
105- ARM EABI v7a System Image, Android API 18, revision 4
106- Intel x86 Atom System Image, Android API 18, revision 3
107- Google APIs ARM EABI v7a System Image, Android API 18, revision 5
108- Google APIs Intel x86 Atom System Image, Android API 18, revision 5
109- ARM EABI v7a System Image, Android API 17, revision 5
110- Intel x86 Atom System Image, Android API 17, revision 3
111- MIPS System Image, Android API 17, revision 1
112- Google APIs ARM EABI v7a System Image, Android API 17, revision 5
113- Google APIs Intel x86 Atom System Image, Android API 17, revision 5
114- ARM EABI v7a System Image, Android API 16, revision 4
115- Intel x86 Atom System Image, Android API 16, revision 5
116- MIPS System Image, Android API 16, revision 1
117- Google APIs ARM EABI v7a System Image, Android API 16, revision 5
118- Google APIs Intel x86 Atom System Image, Android API 16, revision 5
119- ARM EABI v7a System Image, Android API 15, revision 4
120- Intel x86 Atom System Image, Android API 15, revision 4
121- MIPS System Image, Android API 15, revision 1
122- Google APIs ARM EABI v7a System Image, Android API 15, revision 5
123- Google APIs Intel x86 Atom System Image, Android API 15, revision 5
124- ARM EABI v7a System Image, Android API 14, revision 2
125- ARM EABI v7a System Image, Android API 10, revision 4
126- Intel x86 Atom System Image, Android API 10, revision 4
127- Google APIs ARM EABI v7a System Image, Android API 10, revision 5
128- Google APIs Intel x86 Atom System Image, Android API 10, revision 5
129- Google APIs, Android API 24, revision 1
130- Google APIs, Android API 23, revision 1
131- Google APIs, Android API 22, revision 1
132- Google APIs, Android API 21, revision 1
133- Google APIs, Android API 19, revision 20
134- Glass Development Kit Preview, Android API 19, revision 11
135- Google APIs, Android API 18, revision 4
136- Google APIs, Android API 17, revision 4
137- Google APIs, Android API 16, revision 4
138- Google APIs, Android API 15, revision 3
139- Google APIs, Android API 14, revision 2 (Obsolete)
140- Google APIs, Android API 13, revision 1 (Obsolete)
141- Google TV Addon, Android API 13, revision 1 (Obsolete)
142- Google APIs, Android API 12, revision 1 (Obsolete)
143- Google TV Addon, Android API 12, revision 2 (Obsolete)
144- Google APIs, Android API 11, revision 1 (Obsolete)
145- Google APIs, Android API 10, revision 2 (Obsolete)
146- Google APIs, Android API 9, revision 2 (Obsolete)
147- Google APIs, Android API 8, revision 2 (Obsolete)
148- Google APIs, Android API 7, revision 1 (Obsolete)
149- Google APIs, Android API 6, revision 1 (Obsolete)
150- Google APIs, Android API 5, revision 1 (Obsolete)
151- Google APIs, Android API 4, revision 2 (Obsolete)
152- Google APIs, Android API 3, revision 3 (Obsolete)
153- Sources for Android SDK, API 25, revision 1
154- Sources for Android SDK, API 24, revision 1
155- Sources for Android SDK, API 23, revision 1
156- Sources for Android SDK, API 22, revision 1
157- Sources for Android SDK, API 21, revision 1
158- Sources for Android SDK, API 20, revision 1
159- Sources for Android SDK, API 19, revision 2
160- Sources for Android SDK, API 18, revision 1
161- Sources for Android SDK, API 17, revision 1
162- Sources for Android SDK, API 16, revision 2
163- Sources for Android SDK, API 15, revision 2
164- Sources for Android SDK, API 14, revision 1 (Obsolete)
165- Android Support Repository, revision 47
166- Google AdMob Ads SDK, revision 11 (Obsolete)
167- Google Analytics App Tracking SDK, revision 3 (Obsolete)
168- Android Auto Desktop Head Unit emulator, revision 1.1
169- Google Cloud Messaging for Android Library, revision 3 (Obsolete)
170- Google Play services for Froyo, revision 12 (Obsolete)
171- Google Play services, revision 39
172- Google Repository, revision 46
173- Google Play APK Expansion library, revision 1
174- Google Play Licensing Library, revision 1
175- Google Play Billing Library, revision 5
176- Android Auto API Simulators, revision 1
177- Google Web Driver, revision 2
matynjr@matynjr-HP-2000-Notebook-PC:~$

JDK is too old. You need 1.8.

but this is what i get when i check the version of java am using

matynjr@matynjr-HP-2000-Notebook-PC:~$ java -version
java version "1.8.0_91"
Java™ SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot™ 64-Bit Server VM (build 25.91-b14, mixed mode)

Check your JAVA_HOME variable, it might just be pointing to the wrong place.