Can not Build an APK for Android


#1

Hey guys, Please I need help. I am trying to build an APK for android, and it keeps giving me the following error. I tried everything out there online, and never worked. Please help.

BUILD FAILED
FAILURE: Build failed with an exception.

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

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/cordova/PermissionHelper.class

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

Total time: 1 mins 51.939 secs
Error: cmd: Command failed with exit code 1 Error output:
FAILURE: Build failed with an exception.

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

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/cordova/PermissionHelper.class

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

[ERROR] An error occurred while running cordova build android (exit code 1).


#2

Try for removing platform and adding again.
If it doesn’t work create a new project and add your code to the new project and try .


#3

What is your ionic info output?
What plugins are you using?
Anything in config.xml for these plugins?


#4

$ ionic info

cli packages: (C:\Users\shawe\AppData\Roaming\npm\node_modules)

@ionic/cli-plugin-proxy : 1.5.6
@ionic/cli-utils        : 1.19.0
ionic (Ionic CLI)       : 3.19.0

global packages:

cordova (Cordova CLI) : not installed

local packages:

@ionic/app-scripts : 3.1.3
Cordova Platforms  : android 6.3.0
Ionic Framework    : ionic-angular 3.9.2

System:

Node : v8.9.1
npm  : 5.5.1
OS   : Windows 10

Environment Variables:

ANDROID_HOME     : not set
HTTP_PROXY       : not set
http_proxy       : not set
HTTPS_PROXY      : not set
https_proxy      : not set
IONIC_HTTP_PROXY : not set
PROXY            : not set
proxy            : not set

Misc:

backend : pro

My Plugins:

cordova-plugin-actionsheet 2.3.3 "ActionSheet"
cordova-plugin-camera 3.0.0 "Camera"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-dialogs 1.3.4 "Notification"
cordova-plugin-geolocation 3.0.0 "Geolocation"
cordova-plugin-ionic-webview 1.1.11 "Ionic’s WKWebView Engine"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-whitelist 1.3.1 "Whitelist"
me.tonny.cordova.plugins.multidex 0.1.0 "Cordova Multi Dex"
mx.ferreyra.callnumber 0.0.2 “Cordova Call Number Plugin”


#5

This looks wrong.

6.4.0 is available and should be used.


#6

@Sujan I’m bit lost how to update all the pieces in the project after Ionic CLI : 3.19.0 update,
How do I update Cordova Platforms?
Thank you in advance.
Alex


#7

Same as you always did:

ionic cordova platform remove android
ionic cordova platform add android@6.4.0


#8

Use following commands in sequence -

1. npm install -g ionic cordova
2. ionic cordova platform add android

After above commands, use following to build your apk file -

ionic cordova build android
OR
ionic cordova build android --prod

Follow official guides.


#9

Thank you @Sujan12 , does anywhere exist a “current” set of libraries that work together? Or even set of libraries the went along in a past? It is almost impossible to release or even serve projects started in September 2017. Upgrading stuff and fighting versions conflicts is now 30% of my daily routine, which actually contradicts the advantage of hybrid apps,

Edit:

Same as you always did:

This is the problem. I have never set the android version manually all the documentation uses simple ionic cordova platform add android which installs the version defined by the CLI. Meanwhile Ionic releases dozens of CLI updates (some weeks every day) but there is no hint I’m supposed to update ie Cordova Android platform or other stuff. There is no reference in the CHANGELOG, so how should I know the combinations? What is the good practice here?


#10

Always add the word latest.
Android@latest.


#11

Thanks @Sujan12 . That worked for me.

I have a question for everybody. So recently angularfire2 released an update which made fetching data nit working unless u update the syntax and add the right words. Noe, what if the app is live, so we would have a completly not working app until we fix the stuff and wait for 2-3 days until the app store and google play approve the binary!!!


#12

Please post that question in its own topic nd don’t hijack this one.


#13

Ionic CLI updates have absolutely no influence on Cordova CLI or platforms. Updating Ionic CLI is 100% painless in regard to your actual code dependency versions.

If you have pinned your Cordova and other npm dependencies versions, you can just continue using them. They won’t break.
If you want to update something because you wnat a newer version or something is broken, you have to actually read the changelogs and releases of those to find out what is going on.

In your case, you came here posting with a problem. The baseline you have to do here is to update everything to newest versions to make sure your problem is not solved by this and all the debugging would be for naught.
In general: npm outdated tells you which of your dependencies are outdated.