How to fix unable merge with dex in ionic? - android

I’m getting issue follow while taking android build.
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug’
Task :CordovaLib:compileDebugShaders UP-TO-DATE
Task :CordovaLib:generateDebugAssets UP-TO-DATE
Task :CordovaLib:packageDebugAssets UP-TO-DATE
Task :app:mergeDebugAssets
Task :app:validateSigningDebug UP-TO-DATE
Task :app:signingConfigWriterDebug UP-TO-DATE
Task :app:transformClassesWithDexBuilderForDebug UP-TO-DATE
Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 22s
35 actionable tasks: 3 executed, 32 up-to-date
/Users/panmoh/Documents/mobile-app/platforms/android/gradlew: Command failed with exit code 1 Error output:
D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 22s
[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.
Note : I tried cordova clean android and remove and add android platfoem as well

To fix this issue for those using Phonegap/Cordova
Install the “cordova-plugin-androidx” plugin
cordova plugin add cordova-plugin-androidx
Install “cordova-plugin-androidx-adapter” plugin
cordova plugin add cordova-plugin-androidx-adapter
Add these lines in your gradle.properties :
android.useAndroidX=true
android.enableJetifier=true
After this, make a build: cordova -d build android and check the result

solutions is following : make sure the following :
Upgrade com.android.tools.build:gradle to v3.2.1 or later.
Upgrade compileSdkVersion to 28 or later. . Update your app to use
Jetpack (AndroidX); follow the instructions in Migrating to AndroidX.
For Cordova/Ionic project just add the following plugins:
https://github.com/dpa99c/cordova-plugin-androidx
https://github.com/dpa99c/cordova-plugin-androidx-adapter
Those plugins will fix build error. and everything will work fine :)..

The solution accepted here is the true solution. I stuck with this issue for a week and than on last weekend i decided no matter what happens a'll find solution for it.
All credit goes to this person named (ProdoElmit) who answered it here.
Attaching screenshots for above solution to make it easier to follow:
Here my project name was app
In my case it was FCM which was using androidx and causing this issue. Hope this will help someone to resolve their issue as well.

Related

com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex in ionic 5

everyone, please help me. im running ionic cordova run android. then an error occured. before install plugin facebook4 things are going well, after instal the plugin im can not build or run android. i have running cordova clean and cordova build not solved my problem.
:app:transformClassesWithDesugarForDebug
:app:transformClassesWithDexBuilderForDebug
:app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
42 actionable tasks: 40 executed, 2 up-to-date
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
* 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 2m 49s
cmd: Command failed with exit code 1 Error output:
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: E:\PROJECT\spectraapp\platforms\android\app\src\main\java\org\apache\cordova\file\AssetFilesystem.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
* 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 2m 49s
[ERROR] An error occurred while running subprocess cordova.
cordova.cmd build android --device exited with exit code 1.
Re-running this command with the --verbose flag may provide more information.
Try removing platform and re-add it.
ionic cordova platform remove android
ionic cordova platform add android
then try
ionic cordova run android
If still have some issue
check it
solved. iam remove plugin facebook and add again with version #1.7.4
ionic cordova plugin add cordova-plugin-facebook4#1.7.4 --variable APP_ID="appid" --variable APP_NAME="appname"
add resource strings.xml in platforms/android/app/src/main/res/values/strings.xml
<string name="fb_app_id">appid</string>
<string name="fb_app_name">appname</string>
ionic cordova run android

Build Failed while run-android

I want to run my project on physical device. However while I run android Build failed.
then getting an error.
Task :app:transformDexArchiveWithDexMergerForDebug FAILED
C:\Users\Alperen\Desktop\AwesomeProject>npx react-native run-android
info Running jetifier to migrate libraries to AndroidX. You can disable it using "--no-jetifier" flag.
Jetifier found 885 file(s) to forward-jetify. Using 4 workers...
info Starting JS server...
info Installing the app...
> Task :app:transformDexArchiveWithDexMergerForDebug FAILED
Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/5.5/userguide/command_line_interface.html#sec:command_line_warnings
36 actionable tasks: 2 executed, 34 up-to-date
D8: Program type already present: com.zmxv.RNSound.BuildConfig
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: com.zmxv.RNSound.BuildConfig
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
com.android.tools.r8.utils.ExceptionUtils.withCompilationHandler(ExceptionUtils.java:66)
... 11 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithDexMergerForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: com.zmxv.RNSound.BuildConfig
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BU�LD FAILED in 7s
error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
D8: Program type already present: com.zmxv.RNSound.BuildConfig
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
NOTE:
I am using 11. verison of jdk.
It's just a hello world project.
yesterday I builded smoothly for apk.
How can I fix that problem ?
Your best bet for handling any Android Studio specific errors is to do a clean+rebuild.
Sometimes the module compilation tend to screw up so running inside your android folder should help.
rm .idea/modules.xml
rm your-project-name.iml
Just make sure you have exited Android Studio before you run those two commands.

Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver on Ionic

i'm building app with ionic
i have add firebase cloud message, everything work fine
But today, when i build that show error.
ionic cordova platform rm android
remove plugins
clear & clean cache
remove package-lock.js
npm i
6 ionic cordova platform add android
7 ionic cordova prepare
8 ionic cordova build android
Task :app:transformDexArchiveWithExternalLibsDexMergerForDebug FAILED
37 actionable tasks: 7 executed, 30 up-to-date
D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
Get more help at https://help.gradle.org
BUILD FAILED in 18s
/////*/platforms/android/gradlew: Command failed with exit code 1 Error output:
D8: Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.os.ResultReceiver$MyResultReceiver
I had the same issue, and found out it was because of the firebase and googleplus plugins. Finally found a solution that worked for me :
ionic cordova plugin add cordova-plugin-androidx
ionic cordova plugin add cordova-plugin-androidx-adapter
Simply adding these plugins removed any build error.

Flutter build failed with D8: Program type already present

I am developing a flutter app.
I found a sample flutter project so folk it.
But the project... build failed with below log message.
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:preDebugBuild'.
> Android dependency 'androidx.core:core' has different version for the compile (1.0.0) and runtime (1.0.1) classpath. You should manually set the same version via DependencyResolution
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
*******************************************************************************************
The Gradle failure may have been because of AndroidX incompatibilities in this Flutter app.
See https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility for more information on the problem and how to fix it.
*******************************************************************************************
Finished with error: Gradle task assembleDebug failed with exit code 1
The project is not special.
The android part, there are no other modifications.
It is totally same with the "new flutter project'.
I tried something:
Migration to AndroidX
This is failed with error popup. I tried to migration using "refactor > migration to android x", but it shows error popup.
The error popup said to me use compilesdkversion at least 28.
But I already use 28.. what should I do?......
change gradle version from 3.2.1 to 3.3.2.
But build failed with different log
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
D8: Program type already present: android.support.v4.app.INotificationSideChannel
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
> com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives:
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
Program type already present: android.support.v4.app.INotificationSideChannel
I don't know what should i do...
It make me to tired...
I just want to coding...
I resolve this issue following this link: https://flutter.dev/docs/development/packages-and-plugins/androidx-compatibility
There is 2 migration guide.
Recommended
Not Recommended
In my case, 'Recommended' solution doesn't work...
But, 'Not recommended' solution works...
...
It's not easy...
I tried this two lines of code
flutter clean and then
flutter run

Android Studio Build Error Execution Failure

I'm a student trying to use Android Studio and as shown below, I'm having errors when I try to build why is this happening? Also, how can I fix it?
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:mergeDebugResources'.
> Error: java.util.concurrent.ExecutionException:
com.android.builder.internal.aapt.v2.Aapt2Exception: AAPT2 error: check logs
for
details
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --
debug
option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 4s
9 actionable tasks: 1 executed, 8 up-to-date
P.S: I'm not sure what the thing that says in the try section means.
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
see this link, Aapt2 is enabled by default to speed up builds.
Update your gradle version and this error should disappear, alternatively disable aapt2, but prefer to upgrade the gradle version, as just disabeling aapt2 hides the problem, and also slowes down your build.
updating
build.gradle(top level)
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.1.4
}
}
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
alternatively disable it in gradle.properties
android.enableAapt2=false

Categories

Resources