ionic 运行问题记录

329 阅读1分钟
$ cordova build android

[...]

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;

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

BUILD FAILED

Total time: 3.379 secs
Error: /home/thor/Projects/App_CDP/platforms/android/gradlew: 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 unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lorg/apache/cordova/BuildHelper;

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
$ cordova plugin list
com.googlemaps.ios 2.2.0-fixed "Google Maps SDK for iOS"
com.moust.cordova.videoplayer 1.0.1 "Video Player"
cordova-plugin-camera 2.4.1 "Camera"
cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-facebook4 1.9.1 "Facebook Connect"
cordova-plugin-file 4.0.0 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-googlemaps 1.4.0 "phonegap-googlemaps-plugin"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-whitelist 1.3.1 "Whitelist"
ionic-plugin-keyboard 2.2.1 "Keyboard"
{}

很可能你正在使用新发布的版本cordova-android@6.3.0,现在包含BuildHelper.java(如你的错误信息中所述)和PermissionHelper.java,但是你的项目中仍然存在弃用的cordova-plugin-compat,导致构建失败,因为它也包含这些类

为了解决这个问题,cordova-plugin-compat从项目中移除以从cordova-android平台项目中卸载这些Java文件

cordova plugin rm cordova-plugin-compat --force

要坚持这个改变,添加cordova-plugin-compat@1.2一个引擎约束来防止Java文件被重新安装到cordova-android@6.3+平台中:

cordova plugin add cordova-plugin-compat@1.2

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

错误:资源android:attr / fontVariationSettings资源android:attr / ttcIndex未找到。

build.gradle添加:

 configurations.all {
     resolutionStrategy { force 'com.android.support:support-v4:27.1.0' }  
 }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

错误:could not find "msbuild.exe" 

log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')
    var notfoundErr = 'Can\'t find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed?'
    var cmd = 'C:\\Windows\\System32\\reg.exe query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'

找到\node-modules\node-gyp\lib\build.js做出一下替换更改就行:
var cmd = 'C:\\Windows\\System32\\reg.exe query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'