Ionic build failed on android

Hello,

I am new to Ionic and programming and this is my first question, so please bear with me.
I am trying to build the app on android to do better debugging and check for geolocation and camera apis. But I am not successful.

I have more than 50 errors showing on my build. But everything looks like more or less related to the environment is what I believe looking at the various support forums.

My enviroment ( building on Ubuntu 16.x)
Node version 9 and npm version 5

cli packages: (/usr/local/lib/node_modules)

@ionic/cli-utils  : 1.19.1
ionic (Ionic CLI) : 3.19.1

global packages:

cordova (Cordova CLI) : 8.0.0 

local packages:

@ionic/app-scripts : 3.1.8
Cordova Platforms  : android 7.0.0
Ionic Framework    : ionic-angular 3.9.2

System:

Android SDK Tools : 26.1.1
Node              : v9.0.0
npm               : 5.6.0 
OS                : Linux 4.13

Environment Variables:

ANDROID_HOME : /home/hari/Android/Sdk

My plugin list
cordova-plugin-advanced-http 1.10.1 "Advanced HTTP plugin"
cordova-plugin-contacts 3.0.1 "Contacts"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-file 6.0.1 "File"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-ionic-keyboard 2.0.5 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 1.1.16 "cordova-plugin-ionic-webview"
cordova-plugin-mauron85-background-geolocation 2.3.3 "CDVBackgroundGeolocation"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-whitelist 1.3.1 “Whitelist”

My package.json
"dependencies": {
"@angular/common": “5.0.3”,
"@angular/compiler": “5.0.3”,
"@angular/compiler-cli": “5.0.3”,
"@angular/core": “5.0.3”,
"@angular/forms": “5.0.3”,
"@angular/http": “5.0.3”,
"@angular/platform-browser": “5.0.3”,
"@angular/platform-browser-dynamic": “5.0.3”,
"@ionic-native/background-geolocation": “^4.5.3”,
"@ionic-native/camera": “4.3.3”,
"@ionic-native/contacts": “^4.5.3”,
"@ionic-native/core": “4.4.0”,
"@ionic-native/geolocation": “^4.5.3”,
"@ionic-native/http": “^4.5.3”,
"@ionic-native/splash-screen": “4.4.0”,
"@ionic-native/status-bar": “4.4.0”,
"@ionic/pro": “1.0.17”,
"@ionic/storage": “2.1.3”,
"@ngx-translate/core": “8.0.0”,
"@ngx-translate/http-loader": “^2.0.0”,
"@types/lodash": “^4.14.100”,
“cordova-android”: “^7.0.0”,
“cordova-plugin-advanced-http”: “^1.10.1”,
“cordova-plugin-contacts”: “^3.0.1”,
“cordova-plugin-device”: “^1.1.4”,
“cordova-plugin-file”: “^6.0.1”,
“cordova-plugin-geolocation”: “^4.0.1”,
“cordova-plugin-ionic-keyboard”: “^2.0.5”,
“cordova-plugin-ionic-webview”: “^1.1.16”,
“cordova-plugin-mauron85-background-geolocation”: “^2.3.3”,
“cordova-plugin-splashscreen”: “^4.0.3”,
“cordova-plugin-whitelist”: “^1.3.1”,
“core-js”: “^2.5.3”,
“firebase”: “^4.9.0”,
“geofire”: “^4.1.2”,
“ionic-angular”: “3.9.2”,
“ionicons”: “3.0.0”,
“lodash”: “^4.17.4”,
“mobx”: “^3.4.1”,
“mobx-angular”: “^2.1.1”,
“rxjs”: “5.5.2”,
“sw-toolbox”: “3.6.0”,
“zone.js”: “0.8.18”
},
“devDependencies”: {
"@ionic/app-scripts": “3.1.8”,
“prettier”: “^1.10.2”,
“typescript”: “2.4.2”
},
“description”: “An Ionic project”,
“cordova”: {
“plugins”: {
“cordova-plugin-geolocation”: {
“GEOLOCATION_USAGE_DESCRIPTION”: “To locate you”
},
“cordova-plugin-mauron85-background-geolocation”: {
“GOOGLE_PLAY_SERVICES_VERSION”: “+”,
“ICON”: “@mipmap/icon”,
“SMALL_ICON”: “@mipmap/icon”,
“ACCOUNT_NAME”: “@string/app_name”,
“ACCOUNT_LABEL”: “@string/app_name”,
“ACCOUNT_TYPE”: “$PACKAGE_NAME.account”,
“CONTENT_AUTHORITY”: “$PACKAGE_NAME”
},
“cordova-plugin-contacts”: {},
“cordova-plugin-advanced-http”: {},
“cordova-plugin-whitelist”: {},
“cordova-plugin-device”: {},
“cordova-plugin-splashscreen”: {},
“cordova-plugin-ionic-webview”: {},
“cordova-plugin-ionic-keyboard”: {},
“cordova-plugin-file”: {}
},
“platforms”: [
“android”
]
}

ANDROID_HOME=/home/hari/Android/Sdk
JAVA_HOME=/usr/lib/jvm/java-8-oracle

And finally the build errors
cordova/BackgroundGeolocationPlugin.java:563: error: cannot find symbol
@TargetApi(Build.VERSION_CODES.KITKAT)
^
symbol: variable KITKAT
location: class VERSION_CODES

cordova/file/FileUtils.java:97: error: cannot find symbol
Manifest.permission.READ_EXTERNAL_STORAGE,
^
symbol: variable READ_EXTERNAL_STORAGE
location: class permission

android/app/src/main/java/org/apache/cordova/file/FileUtils.java:998: error: cannot find symbol
ret.put(“externalDataDirectory”, toDirUrl(context.getExternalFilesDir(null)));
^
symbol: method getExternalFilesDir()

symbol: variable LOLLIPOP
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/org/apache/cordova/file/LocalFilesystem.java:424: error: cannot find symbol
for (File f : context.getExternalMediaDirs()) {
^
symbol: method getExternalMediaDirs()
location: variable context of type Context
/home/hari/mysharedv1/platforms/android/app/src/main/java/org/apache/cordova/contacts/ContactAccessorSdk5.java:999: error: cannot find symbol
photoCursor = mApp.getActivity().getContentResolver().query(photoUri, new String[] {ContactsContract.Contacts.Photo.PHOTO}, null, null, null);
^
symbol: variable PHOTO
location: class Photo
/home/hari/mysharedv1/platforms/android/app/src/main/java/org/apache/cordova/splashscreen/SplashScreen.java:290: error: cannot find symbol
LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
^
symbol: variable MATCH_PARENT
location: class LayoutParams
/home/hari/mysharedv1/platforms/android/app/src/main/java/org/apache/cordova/splashscreen/SplashScreen.java:290: error: cannot find symbol
LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
^
symbol: variable MATCH_PARENT
location: class LayoutParams
/home/hari/mysharedv1/platforms/android/app/src/main/java/org/apache/cordova/device/Device.java:132: error: cannot find symbol
String serial = android.os.Build.SERIAL;
^
symbol: variable SERIAL
location: class Build
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/LocationService.java:189: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
^
symbol: variable JELLY_BEAN_MR2
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/LocationService.java:190: error: cannot find symbol
handlerThread.quitSafely();
^
symbol: method quitSafely()
location: variable handlerThread of type HandlerThread
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/LocationService.java:198: error: method does not override or implement a method from a supertype
@Override
^
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/LocationService.java:207: error: cannot find symbol
super.onTaskRemoved(rootIntent);
^
symbol: method onTaskRemoved(Intent)
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/LocationService.java:421: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
^
symbol: variable HONEYCOMB
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/LocationService.java:422: error: cannot find symbol
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, location);
^
symbol: variable THREAD_POOL_EXECUTOR
location: class AsyncTask
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java:55: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
^
symbol: variable JELLY_BEAN_MR1
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java:56: error: cannot find symbol
elapsedRealtimeNanos = location.getElapsedRealtimeNanos();
^
symbol: method getElapsedRealtimeNanos()
location: variable location of type Location
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java:58: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
^
symbol: variable JELLY_BEAN_MR2
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java:59: error: cannot find symbol
isFromMockProvider = location.isFromMockProvider();
^
symbol: method isFromMockProvider()
location: variable location of type Location
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java:567: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
^
symbol: variable JELLY_BEAN_MR1
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java:568: error: cannot find symbol
l.setElapsedRealtimeNanos(elapsedRealtimeNanos);
^
symbol: method setElapsedRealtimeNanos(long)
location: variable l of type Location
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/BackgroundLocation.java:592: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
^
symbol: variable JELLY_BEAN_MR1
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java:118: error: cannot find symbol
Log.d(TAG, "Creating db: " + this.getDatabaseName());
^
symbol: method getDatabaseName()
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteOpenHelper.java:172: error: method does not override or implement a method from a supertype
@Override
^
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java:113: error: method queryNumEntries in class DatabaseUtils cannot be applied to given types;
return DatabaseUtils.queryNumEntries(db, LocationEntry.TABLE_NAME, whereClause, whereArgs);
^
required: SQLiteDatabase,String
found: SQLiteDatabase,String,String,String[]
reason: actual and formal argument lists differ in length
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/data/sqlite/SQLiteLocationDAO.java:154: error: cannot find symbol
db.beginTransactionNonExclusive();
^
symbol: method beginTransactionNonExclusive()
location: variable db of type SQLiteDatabase
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/sync/BatchManager.java:70: error: cannot find symbol
db.beginTransactionNonExclusive();
^
symbol: method beginTransactionNonExclusive()
location: variable db of type SQLiteDatabase
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/sync/SyncAdapter.java:71: error: constructor AbstractThreadedSyncAdapter in class AbstractThreadedSyncAdapter cannot be applied to given types;
super(context, autoInitialize, allowParallelSyncs);
^
required: Context,boolean
found: Context,boolean,boolean
reason: actual and formal argument lists differ in length
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/sync/SyncService.java:60: error: cannot find symbol
settingsBundle.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false);
^
symbol: variable SYNC_EXTRAS_DO_NOT_RETRY
location: class ContentResolver
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/marianhello/bgloc/HttpPostService.java:59: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
^
symbol: variable KITKAT
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:148: error: cannot find symbol
criteria.setHorizontalAccuracy(translateDesiredAccuracy(config.getDesiredAccuracy()));
^
symbol: method setHorizontalAccuracy(Integer)
location: variable criteria of type Criteria
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:166: error: cannot find symbol
if (provider != LocationManager.PASSIVE_PROVIDER) {
^
symbol: variable PASSIVE_PROVIDER
location: class LocationManager
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:187: error: cannot find symbol
accuracy = Criteria.ACCURACY_LOW;
^
symbol: variable ACCURACY_LOW
location: class Criteria
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:190: error: cannot find symbol
accuracy = Criteria.ACCURACY_MEDIUM;
^
symbol: variable ACCURACY_MEDIUM
location: class Criteria
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:193: error: cannot find symbol
accuracy = Criteria.ACCURACY_HIGH;
^
symbol: variable ACCURACY_HIGH
location: class Criteria
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:196: error: cannot find symbol
accuracy = Criteria.ACCURACY_HIGH;
^
symbol: variable ACCURACY_HIGH
location: class Criteria
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:199: error: cannot find symbol
accuracy = Criteria.ACCURACY_MEDIUM;
^
symbol: variable ACCURACY_MEDIUM
location: class Criteria
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:463: error: cannot find symbol
criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH);
^
symbol: variable ACCURACY_HIGH
location: class Criteria
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/bgloc/DistanceFilterLocationProvider.java:467: error: cannot find symbol
locationManager.requestSingleUpdate(criteria, singleUpdatePI);
^
symbol: method requestSingleUpdate(Criteria,PendingIntent)
location: variable locationManager of type LocationManager
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/cordova/BackgroundGeolocationPlugin.java:535: error: cannot find symbol
activity.bindService(locationServiceIntent, mConnection, Context.BIND_IMPORTANT);
^
symbol: variable BIND_IMPORTANT
location: class Context
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/cordova/BackgroundGeolocationPlugin.java:569: error: cannot find symbol
return getContext().registerReceiver(locationModeChangeReceiver, new IntentFilter(LocationManager.MODE_CHANGED_ACTION));
^
symbol: variable MODE_CHANGED_ACTION
location: class LocationManager
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/cordova/BackgroundGeolocationPlugin.java:585: error: cannot find symbol
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
^
symbol: variable ACTION_APPLICATION_DETAILS_SETTINGS
location: class Settings
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/cordova/BackgroundGeolocationPlugin.java:598: error: cannot find symbol
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
^
symbol: variable KITKAT
location: class VERSION_CODES
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/cordova/BackgroundGeolocationPlugin.java:599: error: cannot find symbol
locationMode = Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.LOCATION_MODE);
^
symbol: variable LOCATION_MODE
location: class Secure
/home/hari/mysharedv1/platforms/android/app/src/main/java/com/tenforwardconsulting/cordova/BackgroundGeolocationPlugin.java:600: error: cannot find symbol
return locationMode != Settings.Secure.LOCATION_MODE_OFF;
^
symbol: variable LOCATION_MODE_OFF
location: class Secure
/home/hari/mysharedv1/platforms/android/app/src/main/java/io/ionic/keyboard/IonicKeyboard.java:91: error: cannot find symbol
display.getSize(size);
^
symbol: method getSize(Point)
location: variable display of type Display
/home/hari/mysharedv1/platforms/android/app/src/main/java/io/ionic/keyboard/IonicKeyboard.java:131: error: cannot find symbol
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list);
^
symbol: method removeOnGlobalLayoutListener(OnGlobalLayoutListener)
location: class ViewTreeObserver
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
53 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ‘:app:compileDebugJavaWithJavac’.

Compilation failed; see the compiler error output for details.

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

Requesting help with how to proceed further from here.

I tried to remove and add plugins, I moved to different api level ,

Which way should i proceed?

Add cordova-android@6.4.0 to your package.json. Version 7.0.0 is used default and that gives the error. Just fixed myself this morning with this.

Hi @clockwise , thanks for the response. I added cordova-android@6.4.0 to my package json, but still gives me the error.

Ionics, any pointers? @aaronksaunders any help :slight_smile:

hello @shriharip
refer this link https://stackoverflow.com/questions/36568423/cordova-build-run-failed-compiledebugjavawithjavac
hope so this helps u :slight_smile:

Hi @demokumar,
I tried the suggestion, but still facing the same issue.

I’m currently facing this issue and only happened when I added the background location plugins. Same errors on my end.

@cedrickd thanks for that input . I checked the plugin issues again today and found a solution .

https://github.com/mauron85/cordova-plugin-background-geolocation/issues/362 check this out.