编辑:来自Error: java.util.zip.ZipException: duplicate entry的解决方案在这里不起作用,因为我对support-v4模块没有问题
我正在尝试构建一个使用SpongyCastle的Android项目,但不幸的是它需要来自javax.naming
库的jndi
个包。
我添加了jndi甚至javaEE来使它工作,但gradle仍然有运行项目的问题(构建成功)
我的gradle.build文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "grylls.cryptotexting"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'javax:javaee-api:7.0'
compile files('lib/jndi-1.2.1.jar')
}
Gradle抛出此错误:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.>
com.android.build.api.transform.TransformException:java.util.zip.ZipException:
duplicate entry:javax/mail/AuthenticationFailedException.class
当我尝试从javax.mail
中排除javax:javaee-api:7.0
时,我得到了:
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException:
com.android.ide.common.process.ProcessException:
org.gradle.process.internal.ExecException:
Process 'command 'C:\Program Files\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 1
在哪里可以找到javax.mail的重复版本,我甚至不需要这样做?
答案 0 :(得分:4)
要正确包含SpongyCastle,我必须对依赖项进行更改:
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.madgag.spongycastle:core:1.51.0.0'
compile 'com.madgag.spongycastle:prov:1.51.0.0'
compile 'com.madgag.spongycastle:pkix:1.51.0.0'
compile 'com.madgag.spongycastle:pg:1.51.0.0'
}
创建一个插入BouncyCastle Provider
的类import android.app.Application;
import java.security.Security;
public class Dynks extends Application {
static { Security.insertProviderAt(new org.spongycastle.jce.provider.BouncyCastleProvider(), 1); }
}
并将其包含在“application”标签下的AndroidManifest.xml中:
...
<application
android:name="Dynks"
...