Ionic Apk Build error

#1

i am new in ionic framewrok. i have created a project but when i try to build apk with onic cordova build android

there is an error

[ERROR] An error occurred while running subprocess cordova.

    cordova build android exited with exit code 1.

    Re-running this command with the --verbose flag may provide more information.

and i tried to run

cordova build android --verbose

and get this

No scripts found for hook "before_build".
No scripts found for hook "before_prepare".
Checking config.xml and package.json for saved platforms that haven't been added to the project
Config.xml and package.json platforms are the same. No pkg.json modification.
Package.json and config.xml platforms are different. Updating config.xml with most current list of platforms.
PlatformApi successfully found for platform android
Android Studio project detected
Checking config.xml for saved plugins that haven't been added to the project
Checking for any plugins added to the project that have not been installed in android platform
No differences found between plugins added to project and installed in android platform. Continuing...
Generating platform-specific config.xml from defaults for android at C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\app\src\main\res\xml\config.xml
Merging project's config.xml into platform-specific android config.xml
Merging and updating files from [www, platforms\android\platform_www] to platforms\android\app\src\main\assets\www
Wrote out android application name "MyApp" to C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\app\src\main\res\values\strings.xml
android-versionCode not found in config.xml. Generating a code based on version in config.xml (0.0.1): 1
Wrote out Android package name "io.ionic.starter" to C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\app\src\main\java\io\ionic\starter\MainActivity.java
Updating icons at platforms\android\app\src\main\res
Updating splash screens at platforms\android\app\src\main\res
This app does not have additional resource files defined
Prepared android project successfully
No scripts found for hook "after_prepare".
No scripts found for hook "before_compile".
ANDROID_HOME=C:\Users\zdx\AppData\Local\Android\sdk
JAVA_HOME=C:\Program Files\java\jdk1.8.0_191
studio
Subproject Path: CordovaLib
Subproject Path: app
Running command: cmd "/s /c "C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\gradlew.bat cdvBuildDebug -b C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m""

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':CordovaLib'.
> Could not resolve all files for configuration ':CordovaLib:classpath'.
   > Could not find android-maven-gradle-plugin.jar (com.github.dcendents:android-maven-gradle-plugin:1.5).
     Searched in the following locations:
         https://jcenter.bintray.com/com/github/dcendents/android-maven-gradle-plugin/1.5/android-maven-gradle-plugin-1.5.jar

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

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Command finished with error code 1: cmd /s /c "C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\gradlew.bat cdvBuildDebug -b C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\build.gradle -Dorg.gradle.daemon=true -Dorg.gradle.jvmargs=-Xmx2048m"
cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':CordovaLib'.
> Could not resolve all files for configuration ':CordovaLib:classpath'.
   > Could not find android-maven-gradle-plugin.jar (com.github.dcendents:android-maven-gradle-plugin:1.5).
     Searched in the following locations:
         https://jcenter.bintray.com/com/github/dcendents/android-maven-gradle-plugin/1.5/android-maven-gradle-plugin-1.5.jar

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

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':CordovaLib'.
> Could not resolve all files for configuration ':CordovaLib:classpath'.
   > Could not find android-maven-gradle-plugin.jar (com.github.dcendents:android-maven-gradle-plugin:1.5).
     Searched in the following locations:
         https://jcenter.bintray.com/com/github/dcendents/android-maven-gradle-plugin/1.5/android-maven-gradle-plugin-1.5.jar

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

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
    at ChildProcess.whenDone (C:\Users\zdx\Desktop\projects\ionic\simpleApp\platforms\android\cordova\node_modules\cordova-common\src\superspawn.js:169:23)
    at ChildProcess.emit (events.js:182:13)
    at maybeClose (internal/child_process.js:962:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
#2

Try this…and run your build cmd again.

ionic cordova platform rm android
ionic cordova platform add android@6.3.0
2 Likes
#3

Hi, Check your gradle version
4.1 + version u can use this problem has solved so install gradle 4 above version then build on apk

2 Likes
#4

hi the problem has been solved by adding

modify:
mavenCentral()
jcenter()

to:
maven { url "https://maven.google.com" }	
jcenter { url "http://jcenter.bintray.com/"}

in files:
platforms/android/build.gradle
platforms/android/app/build.gradle
platforms/android/CordovaLib/build.gradle
#5

I have the same error. It is still not resolved.

#6

ionic cordova platform add android@latest