Building apk with ionic cordova build android but geeting error

#1

Almost 5 hours I am searching for a solution but no luck , when I run ionic cordova build android I getting this below error message. i have already install java sdk and android studio

E:\Practice\Ionic\markerApp>ionic cordova build android
> ionic-app-scripts build --target cordova --platform android
[16:52:09]  ionic-app-scripts 3.1.11
[16:52:09]  build dev started ...
[16:52:09]  clean started ...
[16:52:09]  clean finished in 16 ms
[16:52:09]  copy started ...
[16:52:09]  deeplinks started ...
[16:52:09]  deeplinks finished in 83 ms
[16:52:09]  transpile started ...
[16:52:15]  transpile finished in 5.23 s
[16:52:15]  preprocess started ...
[16:52:15]  preprocess finished in less than 1 ms
[16:52:15]  webpack started ...
[16:52:15]  copy finished in 5.69 s
[16:52:21]  webpack finished in 6.70 s
[16:52:21]  sass started ...
Without `from` option PostCSS could generate wrong source map and will not find
Browserslist config. Set it to CSS file path or to `undefined` to prevent this w
arning.
[16:52:23]  sass finished in 1.87 s
[16:52:23]  postprocess started ...
[16:52:23]  postprocess finished in 10 ms
[16:52:23]  lint started ...
[16:52:23]  build dev finished in 14.27 s
[16:52:29]  lint finished in 5.79 s
> cordova build android
Android Studio project detected
ANDROID_HOME=C:\Users\Vishal-8\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk-10.0.2
(node:5968) UnhandledPromiseRejectionWarning: CordovaError: Requirements check f
ailed for JDK 1.8 or greater
    at E:\Practice\Ionic\markerApp\platforms\android\cordova\lib\check_reqs.js:
370:19
    at _fulfilled (E:\Practice\Ionic\markerApp\platforms\android\cordova\node_m
odules\q\q.js:854:54)
    at E:\Practice\Ionic\markerApp\platforms\android\cordova\node_modules\q\q.j
s:883:30
    at Promise.promise.promiseDispatch (E:\Practice\Ionic\markerApp\platforms\a
ndroid\cordova\node_modules\q\q.js:816:13)
    at E:\Practice\Ionic\markerApp\platforms\android\cordova\node_modules\q\q.j
s:624:44
    at runSingle (E:\Practice\Ionic\markerApp\platforms\android\cordova\node_mo
dules\q\q.js:137:13)
    at flush (E:\Practice\Ionic\markerApp\platforms\android\cordova\node_module
s\q\q.js:125:13)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:5968) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejection
 id: 1)
(node:5968) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
 Node.js process with a non-zero exit code.
#2

Did you install JDK 1.8?

What is your ionic info output?

#3

Kindly check below ionic info

E:\Practice\Ionic\markerApp>ionic info

Ionic:

   ionic (Ionic CLI)  : 4.0.3 (C:\Users\Vishal-8\AppData\Roaming\npm\node_module
s\ionic)
   Ionic Framework    : ionic-angular 3.9.2
   @ionic/app-scripts : 3.1.11

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : not available

System:

   NodeJS : v10.7.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.1.0
   OS     : Windows 8.1

Environment:

   ANDROID_HOME : not set
#4

That is strange. What does cordova platform list return?
What cordova-android does it list in config.xml and/or package.json?

Also:

#5

Ya, I already install JDK 1.8

cordova platform list

E:\Practice\Ionic\ ```
markerApp
```>cordova platform list
Installed platforms:
  android 7.0.0
Available platforms:
  browser ~5.0.1
  ios ~4.5.4
  osx ~4.0.1
  windows ~5.0.0
  www ^3.12.0

config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.company.AppName" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>markerApp</name>
    <description>Location Marker App</description>
    <author email="vishal.n@gmail.com" href="#">Vishal</author>
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <preference name="ScrollEnabled" value="false" />
    <preference name="android-minSdkVersion" value="19" />
    <preference name="BackupWebStorage" value="none" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <preference name="FadeSplashScreenDuration" value="300" />
    <preference name="SplashShowOnlyFirstTime" value="false" />
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <platform name="android">
        <allow-intent href="market:*" />
        <icon density="ldpi" src="resources/android/icon/drawable-ldpi-icon.png" />
        <icon density="mdpi" src="resources/android/icon/drawable-mdpi-icon.png" />
        <icon density="hdpi" src="resources/android/icon/drawable-hdpi-icon.png" />
        <icon density="xhdpi" src="resources/android/icon/drawable-xhdpi-icon.png" />
        <icon density="xxhdpi" src="resources/android/icon/drawable-xxhdpi-icon.png" />
        <icon density="xxxhdpi" src="resources/android/icon/drawable-xxxhdpi-icon.png" />
        <splash density="land-ldpi" src="resources/android/splash/drawable-land-ldpi-screen.png" />
        <splash density="land-mdpi" src="resources/android/splash/drawable-land-mdpi-screen.png" />
        <splash density="land-hdpi" src="resources/android/splash/drawable-land-hdpi-screen.png" />
        <splash density="land-xhdpi" src="resources/android/splash/drawable-land-xhdpi-screen.png" />
        <splash density="land-xxhdpi" src="resources/android/splash/drawable-land-xxhdpi-screen.png" />
        <splash density="land-xxxhdpi" src="resources/android/splash/drawable-land-xxxhdpi-screen.png" />
        <splash density="port-ldpi" src="resources/android/splash/drawable-port-ldpi-screen.png" />
        <splash density="port-mdpi" src="resources/android/splash/drawable-port-mdpi-screen.png" />
        <splash density="port-hdpi" src="resources/android/splash/drawable-port-hdpi-screen.png" />
        <splash density="port-xhdpi" src="resources/android/splash/drawable-port-xhdpi-screen.png" />
        <splash density="port-xxhdpi" src="resources/android/splash/drawable-port-xxhdpi-screen.png" />
        <splash density="port-xxxhdpi" src="resources/android/splash/drawable-port-xxxhdpi-screen.png" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
        <icon height="57" src="resources/ios/icon/icon.png" width="57" />
        <icon height="114" src="resources/ios/icon/icon@2x.png" width="114" />
        <icon height="40" src="resources/ios/icon/icon-40.png" width="40" />
        <icon height="80" src="resources/ios/icon/icon-40@2x.png" width="80" />
        <icon height="120" src="resources/ios/icon/icon-40@3x.png" width="120" />
        <icon height="50" src="resources/ios/icon/icon-50.png" width="50" />
        <icon height="100" src="resources/ios/icon/icon-50@2x.png" width="100" />
        <icon height="60" src="resources/ios/icon/icon-60.png" width="60" />
        <icon height="120" src="resources/ios/icon/icon-60@2x.png" width="120" />
        <icon height="180" src="resources/ios/icon/icon-60@3x.png" width="180" />
        <icon height="72" src="resources/ios/icon/icon-72.png" width="72" />
        <icon height="144" src="resources/ios/icon/icon-72@2x.png" width="144" />
        <icon height="76" src="resources/ios/icon/icon-76.png" width="76" />
        <icon height="152" src="resources/ios/icon/icon-76@2x.png" width="152" />
        <icon height="167" src="resources/ios/icon/icon-83.5@2x.png" width="167" />
        <icon height="29" src="resources/ios/icon/icon-small.png" width="29" />
        <icon height="58" src="resources/ios/icon/icon-small@2x.png" width="58" />
        <icon height="87" src="resources/ios/icon/icon-small@3x.png" width="87" />
        <icon height="1024" src="resources/ios/icon/icon-1024.png" width="1024" />
        <splash height="1136" src="resources/ios/splash/Default-568h@2x~iphone.png" width="640" />
        <splash height="1334" src="resources/ios/splash/Default-667h.png" width="750" />
        <splash height="2208" src="resources/ios/splash/Default-736h.png" width="1242" />
        <splash height="1242" src="resources/ios/splash/Default-Landscape-736h.png" width="2208" />
        <splash height="1536" src="resources/ios/splash/Default-Landscape@2x~ipad.png" width="2048" />
        <splash height="2048" src="resources/ios/splash/Default-Landscape@~ipadpro.png" width="2732" />
        <splash height="768" src="resources/ios/splash/Default-Landscape~ipad.png" width="1024" />
        <splash height="2048" src="resources/ios/splash/Default-Portrait@2x~ipad.png" width="1536" />
        <splash height="2732" src="resources/ios/splash/Default-Portrait@~ipadpro.png" width="2048" />
        <splash height="1024" src="resources/ios/splash/Default-Portrait~ipad.png" width="768" />
        <splash height="960" src="resources/ios/splash/Default@2x~iphone.png" width="640" />
        <splash height="480" src="resources/ios/splash/Default~iphone.png" width="320" />
        <splash height="2732" src="resources/ios/splash/Default@2x~universal~anyany.png" width="2732" />
    </platform>
    <plugin name="cordova-plugin-whitelist" spec="1.3.3" />
    <plugin name="cordova-plugin-device" spec="2.0.2" />
    <plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
    <plugin name="cordova-plugin-ionic-webview" spec="^2.0.0" />
    <plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
    <plugin name="cordova-plugin-admob-free" spec="^0.17.4" />
    <engine name="android" spec="7.0.0" />
</widget>

package.json

{
  "name": "markerApp,
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/admob-free": "^4.11.0",
    "@ionic-native/core": "~4.11.0",
    "@ionic-native/splash-screen": "~4.11.0",
    "@ionic-native/status-bar": "~4.11.0",
    "@ionic/lab": "^1.0.5",
    "@ionic/pro": "2.0.3",
    "@ionic/storage": "2.1.3",
    "cordova-admob-sdk": "^0.17.0",
    "cordova-android": "7.0.0",
    "cordova-plugin-admob-free": "^0.17.4",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-ionic-keyboard": "^2.1.2",
    "cordova-plugin-ionic-webview": "^2.0.2",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "cordova-promise-polyfill": "0.0.2",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@ionic/app-scripts": "^3.1.11",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-admob-free": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {}
    },
    "platforms": [
      "android"
    ]
  }
}
#6

Your Cordova tooling seems to be out of date, which might be causing all kinds of problems.
You can read about how to figure out the current Cordova versions and how to update CLI, platforms and plugins here: https://ionic.zone/cordova/update

What does ionic cordova requirements return?

#7

@Sujan12
I install ionic 2 days back so how can version is out of date

E:\Practice\Ionic\markerApp>ionic cordova requirements
> cordova requirements
Android Studio project detected

Requirements check results for android:
Java JDK: installed
Android SDK: installed true
Android target: not installed
cmd: Command failed with exit code 1 Error output:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annota
tion/XmlSchema
        at com.android.repository.api.SchemaModule$SchemaModuleVersion.<init>(Sc
hemaModule.java:156)
        at com.android.repository.api.SchemaModule.<init>(SchemaModule.java:75)
        at com.android.sdklib.repository.AndroidSdkHandler.<clinit>(AndroidSdkHa
ndler.java:81)
        at com.android.sdklib.tool.AvdManagerCli.run(AvdManagerCli.java:213)
        at com.android.sdklib.tool.AvdManagerCli.main(AvdManagerCli.java:200)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlSchema

        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinCla
ssLoader.java:582)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(C
lassLoaders.java:190)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
        ... 5 more
Gradle: installed C:\Program Files\Android\Android Studio\gradle\gradle-4.4\bin\
gradle
(node:9916) UnhandledPromiseRejectionWarning: CordovaError: Some of requirements
 check failed
    at C:\Users\Vishal-8\AppData\Roaming\npm\node_modules\cordova\src\cli.js:414
:27
    at _fulfilled (C:\Users\Vishal-8\AppData\Roaming\npm\node_modules\cordova\no
de_modules\cordova-lib\node_modules\q\q.js:787:54)
    at C:\Users\Vishal-8\AppData\Roaming\npm\node_modules\cordova\node_modules\c
ordova-lib\node_modules\q\q.js:816:30
    at Promise.promise.promiseDispatch (C:\Users\Vishal-8\AppData\Roaming\npm\no
de_modules\cordova\node_modules\cordova-lib\node_modules\q\q.js:749:13)
    at C:\Users\Vishal-8\AppData\Roaming\npm\node_modules\cordova\node_modules\c
ordova-lib\node_modules\q\q.js:557:44
    at flush (C:\Users\Vishal-8\AppData\Roaming\npm\node_modules\cordova\node_mo
dules\cordova-lib\node_modules\q\q.js:108:17)
    at process._tickCallback (internal/process/next_tick.js:61:11)
(node:9916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This
error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejection
 id: 1)
(node:9916) [DEP0018] DeprecationWarning: Unhandled promise rejections are depre
cated. In the future, promise rejections that are not handled will terminate the
 Node.js process with a non-zero exit code.
#8

Cordova CLI installs a “safe” version by default, newly released versions are not installed by default - you have to specify the version explicitly when installing the platform. Seems you didn’t do that.

Do you have any Android targets installed via Android Studio?

You might also want to try to install a standalong gradle from gradle.org/install

#9

Yes just updated Cordova V 7 to V8 & installed Gradle also

Right now I am getting this admob error, If I set ‘’=" to “:” error gone and apk generated but no ads display

E:\Practice\Ionic\markerApp>ionic cordova build android
> ionic-app-scripts build --target cordova --platform android
[08:21:10]  ionic-app-scripts 3.1.11
[08:21:10]  build dev started ...
[08:21:10]  clean started ...
[08:21:10]  clean finished in 124 ms
[08:21:10]  copy started ...
[08:21:11]  deeplinks started ...
[08:21:11]  deeplinks finished in 43 ms
[08:21:11]  transpile started ...
[08:21:27]  typescript: E:/Practice/Ionic/markerApp/src/pages/home/home.ts, lin
e: 22
            **Cannot find name 'id'.**

      L21:      const addConfig: AdMobFreeBannerConfig = {
[08:21:27]  typescript: E:/Practice/Ionic/markerApp/src/pages/home/home.ts, lin
e: 22
      L22:  **id=** 'ca-app-pub-2456995914729075/4764095881',
      L23:  isTesting: false,

            **'='** can only be used in an object literal property inside a destruct
uring assignment.

      L21:      const addConfig: AdMobFreeBannerConfig = {
      L22:  id= 'ca-app-pub-2456995914729075/4764095881',
      L23:  isTesting: false,

[08:21:27]  ionic-app-script task: "build"
[08:21:27]  Error: Failed to transpile program
Error: Failed to transpile program
    at new BuildError (E:\Practice\Ionic\markerApp\node_modules\@ionic\app-scri
pts\dist\util\errors.js:16:28)
    at E:\Practice\Ionic\markerApp\node_modules\@ionic\app-scripts\dist\transpi
le.js:159:20
    at new Promise (<anonymous>)
    at transpileWorker (E:\Practice\Ionic\markerApp\node_modules\@ionic\app-scr
ipts\dist\transpile.js:107:12)
    at Object.transpile (E:\Practice\Ionic\markerApp\node_modules\@ionic\app-sc
ripts\dist\transpile.js:64:12)
    at E:\Practice\Ionic\markerApp\node_modules\@ionic\app-scripts\dist\build.j
s:109:82
[ERROR] An error occurred while running subprocess ionic-app-scripts.

        ionic-app-scripts build --target cordova --platform android exited with

        exit code 1.

        Re-running this command with the --verbose flag may provide more
        information.
events.js:167
      throw er; // Unhandled 'error' event
      ^

TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be one of type strin
g or Buffer. Received type object
    at validChunk (_stream_writable.js:258:10)
    at WriteStream.Writable.write (_stream_writable.js:292:21)
    at process.<anonymous> (C:\Users\Vishal-8\AppData\Roaming\npm\node_modules\i
onic\bin\ionic:9:63)
    at process.emit (events.js:182:13)
    at emitPromiseRejectionWarnings (internal/process/promises.js:105:20)
    at process._tickCallback (internal/process/next_tick.js:69:34)
Emitted 'error' event at:
    at validChunk (_stream_writable.js:261:12)
    at WriteStream.Writable.write (_stream_writable.js:292:21)
    [... lines matching original stack trace ...]
    at process._tickCallback (internal/process/next_tick.js:69:34)

Admob code

import { AdMobFree , AdMobFreeBannerConfig } from '@ionic-native/admob-free';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {

  constructor(public navCtrl: NavController, private admobFree: AdMobFree) {
  	this.loadBanner();
  }

  loadBanner(){

  	const addConfig: AdMobFreeBannerConfig = {
	 id: 'ca-app-pub-2456995914729075/4764095881',
	 isTesting: false,
	 autoShow: true
	};
	this.admobFree.banner.config(addConfig);

	this.admobFree.banner.prepare()
	  .then(() => {
	    console.log("Banner Is desplayed");
	  })
	  .catch(e => console.log(e));
  }

admob code found from this link https://forum.ionicframework.com/t/errors-after-installing-the-admob-free-plugin/114429/16

#10

That Admob code you found still uses :, not =.

But did I read correctly that you can now build for Android successfully?

For your Admob problem, please open a new topic.