编辑:
Error: java.util.zip.ZipException: duplicate entry的解决方案在这里不起作用,因为我没有support-v4模块的问题
我正在尝试构建一个使用SpongyCastle的Android项目,但不幸的是它需要来自jndi库的javax.naming包.
我添加了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:javaee-api:7.0中排除javax.mail时,我得到了:
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的重复,这是我甚至不需要的方式?
解决方法
要正确地包含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" ...