I have an existing Hybrid Remote app built with an older version of the SDK. I need to update it due to known vulnerabilities in the included version of Cordova. After experimenting with updating the existing app in place, I decided to just start fresh with a new
forcehybrid project. After some work (outlined below), I am able to build a debug version of the app, which runs in the the emulator and on device successfully. However, when I try to build the release version, I get the following failure:
> Task :app:mergeDexRelease FAILED D8: Program type already present: org.apache.cordova.AuthenticationToken com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: Program type already present: org.apache.cordova.AuthenticationToken Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes. at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:131) <SNIP>
I have reviewed the "learn how to resolve" link in the error message; it discusses having a dependency which is also included by another dependency. However, I'm unable to find such a dependency. Google has turned up a number of "Program type already present" errors, but they all seem to be specific to other libraries. I've tried building from command line and from Android Studio, with the same result. I've run the
androidDependency gradle task from Android Studio, but cannot see a duplicated dependency. I have no idea how to determine which modules/plugins/whatever are trying to include
These are the steps I followed to get a working debug build:
- Installed latest Cordova (
- Created a new project with
- Added my existing
config.xmlwith settings from my existing project.
- Added cordova plugins. I went through the list of plugins in the old project and found the modern equivalents, nearly all
- email@example.com (to keep existing GCM config, this may not be needed/correct)
- Removed and re-added the MobileSDK Cordova Plugin as outlined in the docs after adding other plugins
- Updated icon & splash files, and added custom
- Updated icon names (via search/replace) from
@mipmap/ic_launcher, since I rely on cordova to create various sizes of icons from
app/resources/icon, and I can't figure out how to change the generated file names. I've always had to do this in older builds as well.
- At this point, I thought I was ready, but I was getting some build errors regarding android support libraries; googling suggested adding the plugin
cordova-plugin-androidx-adapter. This fixed the build errors. I then removed and re-added the MobileSDK Cordova Plugin again, and fixed the icon names again.
- At this point, the app would build, but would crash in the emulator. Debugging via Android Studio showed that the app couldn't find the SalesforceSDK module. A good bit of research and experimentation led to me updating
SalesforceHybrid. Adding only
SalesforceSDK(for example) led to another missing module; in the end I added them all. Prior to my changes, only
app(my app directory name) were included. With this change, I was able to build a working debug APK.
- I tried to build a release apk, and got the error found above. While researching, I found several different "Program type already present" error reports which were allegedly fixed by adding
cordova-plugin-androidx-adapter. Since I had already added
cordova-plugin-androidx-adapter, I went ahead and added
cordova-plugin-androidx(and removed/re-added the SF Mobile plugin again), but it didn't change anything.
So at this point I can build the debug APK, but not the release APK. I cannot figure out how to track down the source of the error. How can I fix, or at least find the root cause?