Cordova + WorkManager 异常
Cordova + WorkManager exception
我选择 WorkManager 进行计划服务,当基于 cordova 的应用程序关闭时,这将帮助我 post 数据到服务器。
因此,我首先将依赖项包含在 build.gradle(模块:应用程序)
中
dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
//THIS LINE HERE IS FOR WORKMANAGER
implementation "android.arch.work:work-runtime:1.0.0-alpha01"
// SUB-PROJECT DEPENDENCIES START
implementation(project(path: ":CordovaLib"))
compile "com.android.support:support-v4:24.1.1+"
// SUB-PROJECT DEPENDENCIES END
}
现在我运行遵循命令
cordova clean
cordova build android
我抛出异常:
Execution failed for task
':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge
dex
所以,我添加了这一行
android {
defaultConfig {
versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
applicationId privateHelpers.extractStringFromManifest("package")
//THIS LINE HERE
multiDexEnabled true
if (cdvMinSdkVersion != null) {
minSdkVersion cdvMinSdkVersion
}
}
lintOptions {
abortOnError false;
}
compileSdkVersion cdvCompileSdkVersion
buildToolsVersion cdvBuildToolsVersion
我再次 运行 清理和构建命令。
现在,我得到新的异常:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write [C:\Users\hjhkjn\Desktop\cordova\hjhkjnad\platforms\android\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\hjhkjn\Desktop\cordova\hjhkjnad\platforms\android\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [19.jar:android/support/v4/content/PermissionChecker$PermissionResult.class]))
如有任何帮助,我们将不胜感激。谢谢
编辑:
我也收到这个错误
对于 Cordova 有一个 Multidex Plugin 而你可能只是可以编辑生成 build.gradle
的文件并在那里启用它......为了不安装那个没有的插件很多目的,但添加这两行 - 仅适用于 Android 而不适用于其他平台。
defaultConfig {
multiDexEnabled true
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
参见 Enable multidex for apps with over 64K methods。
针对 API 级别 > 21 的建筑也应该可以工作,因为默认情况下会启用它。
如果有人遇到这个问题,请回答我自己的问题。
我做了这个 SO 问题中提到的事情:
//
//adding the following to the root level of the Gradle file
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}
我选择 WorkManager 进行计划服务,当基于 cordova 的应用程序关闭时,这将帮助我 post 数据到服务器。
因此,我首先将依赖项包含在 build.gradle(模块:应用程序)
中dependencies {
implementation fileTree(dir: 'libs', include: '*.jar')
//THIS LINE HERE IS FOR WORKMANAGER
implementation "android.arch.work:work-runtime:1.0.0-alpha01"
// SUB-PROJECT DEPENDENCIES START
implementation(project(path: ":CordovaLib"))
compile "com.android.support:support-v4:24.1.1+"
// SUB-PROJECT DEPENDENCIES END
}
现在我运行遵循命令
cordova clean
cordova build android
我抛出异常:
Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex
所以,我添加了这一行
android {
defaultConfig {
versionCode cdvVersionCode ?: new BigInteger("" + privateHelpers.extractIntFromManifest("versionCode"))
applicationId privateHelpers.extractStringFromManifest("package")
//THIS LINE HERE
multiDexEnabled true
if (cdvMinSdkVersion != null) {
minSdkVersion cdvMinSdkVersion
}
}
lintOptions {
abortOnError false;
}
compileSdkVersion cdvCompileSdkVersion
buildToolsVersion cdvBuildToolsVersion
我再次 运行 清理和构建命令。 现在,我得到新的异常:
Execution failed for task ':app:transformClassesWithMultidexlistForDebug'.
> java.io.IOException: Can't write [C:\Users\hjhkjn\Desktop\cordova\hjhkjnad\platforms\android\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\hjhkjn\Desktop\cordova\hjhkjnad\platforms\android\app\build\intermediates\transforms\desugar\debug.jar(;;;;;;**.class)] (Duplicate zip entry [19.jar:android/support/v4/content/PermissionChecker$PermissionResult.class]))
如有任何帮助,我们将不胜感激。谢谢
编辑:
我也收到这个错误
对于 Cordova 有一个 Multidex Plugin 而你可能只是可以编辑生成 build.gradle
的文件并在那里启用它......为了不安装那个没有的插件很多目的,但添加这两行 - 仅适用于 Android 而不适用于其他平台。
defaultConfig {
multiDexEnabled true
}
dependencies {
implementation 'com.android.support:multidex:1.0.3'
}
参见 Enable multidex for apps with over 64K methods。
针对 API 级别 > 21 的建筑也应该可以工作,因为默认情况下会启用它。
如果有人遇到这个问题,请回答我自己的问题。
我做了这个 SO 问题中提到的事情:
//
//adding the following to the root level of the Gradle file
configurations {
all*.exclude group: 'com.android.support', module: 'support-v4'
}