Dex error when trying to build ionic Android app

2019-06-23 04:28发布

问题:

I'm trying to build an ionic app for Android but when I run

ionic cordova run android

I get

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.
> com.android.build.api.transform.TransformException: java.lang.IllegalStateException: Dex archives: setting .DEX extension only for .CLASS files

Trying to run ./gradlew clean gets me

FAILURE: Build failed with an exception.

* What went wrong:
Could not create service of type ScriptPluginFactory using BuildScopeServices.createScriptPluginFactory().
> Could not create service of type FileHasher using BuildSessionScopeServices.createFileSnapshotter().

回答1:

I had the same issue but it was resolved. Thanks to information from @notlose at this link https://github.com/oney/react-native-gcm-android/issues/32

Solution:
just remove both 'build' folder in /android and /android/app and build again with
'react-native run-android' for react-native
'ionic cordova run android' for ionic