使用targetSdkVersion为25和minSdkVersion为19构建Android应用程序

12
我有一个Android应用程序,targetSdkVersion25。它在API 21+上运行良好,但我想修复它以在API 19+(KitKat)上运行。我的应用程序确实使用Material Design,我知道它是在API 21中引入的,但我已经看到这里应该有方法可以进行后移植。
但是,在构建和运行时,我会出现错误:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/activation/MimeTypeParseException.class

我在KitKat模拟器上运行时遇到了这个问题。

有人曾经在回溯测试他们的应用程序时见过这个错误吗?

我的gradle文件包含:

compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.android.support:percent:25.0.0'
compile 'com.android.support:palette-v7:25.0.0'
compile 'org.jetbrains:annotations-java5:15.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:support-v13:25.0.0'

我可以提供哪些额外的信息来帮助调试?

更新 完整的Gradle代码:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'idea'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'io.fabric'

android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/mimetypes.default'
    }
    compileSdkVersion 25
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "com.ohmd.ohmd"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 10
        versionName "2.2"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        vectorDrawables.useSupportLibrary = true
        renderscriptTargetApi 25
        renderscriptSupportModeEnabled true
    }
    dataBinding {
        enabled = true
    }
    lintOptions {
        abortOnError false
    }
    dexOptions {
        javaMaxHeapSize "4g"
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    buildTypes {
        release {
            minifyEnabled false
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            minifyEnabled false
            debuggable true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    compileSdkVersion 25
}


idea {
    module {
        downloadJavadoc = true
        downloadSources = true
    }
}

repositories {
    jcenter()
    maven { url 'http://repo1.maven.org/maven2' }
    maven { url "https://maven.java.net/content/groups/public/" }
    maven { url "https://jitpack.io" }
    maven { url 'https://maven.fabric.io/public' }
}


configurations.all {
    resolutionStrategy {
        force 'junit:junit:4.12'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'net.sf.flexjson:flexjson:2.1'
    compile('org.apache.abdera:abdera-i18n:1.1.1') {
        exclude module: 'support-v4'
    }
    compile('org.eclipse.paho:org.eclipse.paho.android.service:1.1.0') {
        exclude module: 'support-v4'
        transitive=true
    }
    compile('org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.1.0') {
        exclude module: 'support-v4'
    }

    compile 'com.android.support:appcompat-v7:25.0.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support:percent:25.0.0'
    compile 'com.android.support:palette-v7:25.0.0'
    compile 'com.mcxiaoke.volley:library:1.0.19'
    compile 'com.android.support:support-annotations:25.0.0'
    compile 'com.android.support:support-v4:25.0.0'
    compile 'com.sun.mail:android-mail:1.5.6'
    compile 'com.sun.mail:android-activation:1.5.6'
    compile 'com.afollestad.material-dialogs:core:0.9.0.2'
    compile 'com.afollestad.material-dialogs:commons:0.9.0.2'
    compile 'com.code-troopers.betterpickers:library:3.0.1'
    compile 'commons-codec:commons-codec:1.10'
    compile 'com.joanzapata.iconify:android-iconify-fontawesome:2.2.2'
    compile 'com.joanzapata.iconify:android-iconify-material:2.2.2'
    compile 'com.joanzapata.iconify:android-iconify-material-community:2.2.2'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'org.apache.commons:commons-lang3:3.4'
    compile 'com.github.satyan:sugar:1.5'
    compile 'org.apache.httpcomponents:httpcore:4.4.1'
    compile 'com.fasterxml.jackson.core:jackson-core:2.7.3'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
    compile 'com.github.boxme:asyncmanager:1.0.0'
    compile 'com.miguelcatalan:materialsearchview:1.4.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'de.hdodenhof:circleimageview:2.1.0'
    compile 'com.makeramen:roundedimageview:2.2.1'
    compile 'joda-time:joda-time:2.9.5'
    compile 'com.android.support:recyclerview-v7:25.0.0'
    compile 'com.github.stfalcon:frescoimageviewer:0.3.1'
    compile 'joda-time:joda-time:2.9.6'
    compile 'com.liuzhuang.opensource:rcimageview:0.0.2'
    compile 'com.uncopt:android.justified:1.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.google.auto.value:auto-value:1.2'
    compile 'com.karumi:dexter:2.3.0'
    compile 'io.reactivex:rxandroid:1.2.1'
    compile 'io.reactivex:rxjava:1.1.6'
    compile 'com.google.auto.value:auto-value:1.2'
    compile 'com.googlecode.libphonenumber:libphonenumber:7.2.2'
    compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'
    compile 'com.github.nekocode:Badge:1.6.2'
    compile 'com.sjl:Foredroid:1.0.0'
    compile 'com.kaopiz:kprogresshud:1.0.5'
    compile 'com.wang.avi:library:2.1.3'
    compile 'kr.pe.burt.android.lib:androidoperationqueue:0.0.2'
    apt "com.google.auto.value:auto-value:1.2"
    compile 'com.ryanharter.auto.value:auto-value-parcel:0.2.4-rc2'
    apt 'com.ryanharter.auto.value:auto-value-parcel:0.2.4-rc2'
    compile 'jp.wasabeef:recyclerview-animators:2.2.5'
    compile 'me.leolin:ShortcutBadger:1.1.10@aar'
    compile 'com.cocosw:bottomsheet:1.+@aar'
    compile 'com.github.tajchert:nammu:1.1.1'
    compile('com.frosquivel:magicalcamera:5.0.2@aar') {
        transitive = false;
    }

    // Circular progress bar
    compile 'com.github.castorflex.smoothprogressbar:library-circular:1.2.0'

    // Google Play services (old versions, but they work)
    compile 'com.google.android.gms:play-services:6.5.87'

    // Secure shared preferences
    compile 'online.devliving:securedpreferencestore:0.2.4'

    // Included libraries
    compile project(':animation-core')
    compile project(':animation-abslistview')
    compile project(':animation-circular-progress-button')

    // Fabic
    compile('com.crashlytics.sdk.android:crashlytics:2.6.5@aar') {
        transitive = true;
    }
    compile('com.crashlytics.sdk.android:answers:1.3.10@aar') {
        transitive = true;
    }

    // Segment
    compile 'com.segment.analytics.android:analytics:4.+'

    // Test components
    testCompile 'junit:junit:4.12'
    androidTestCompile 'com.android.support.test:runner:0.5'
    androidTestCompile 'com.android.support.test:rules:0.5'
    androidTestCompile 'com.android.support:support-annotations:25.0.0'
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestCompile('com.android.support.test.espresso:espresso-intents:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    androidTestCompile('com.android.support.test.espresso:espresso-web:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
}

更新2

我使用上面的gradle文件从Android Studio 2.2.2开始一个全新的Android应用程序,并且已经能够重复出现这个确切的错误,所以这似乎与我的应用程序内部的实际代码无关(这并不令人惊讶)。


请粘贴Gradle代码。 - Anurag Singh
@AnuragSingh 我已经更新了问题,并附上了我的整个Gradle文件。 - Brett
昨天,我检查了我昨天请求的gradel,并删除了以下行:compile 'com.sun.mail:android-mail:1.5.6',compile 'com.sun.mail:android-activation:1.5.6',然后它编译成功了。这与任何API级别无关。这是因为除了您删除的库之外,还有另一个库使用了相同的包和类avax/activation/MimeTypeParseException.class。 - Anurag Singh
我想提醒您正在使用已弃用的Volley版本。您应该将其更新到最新版本。 - suku
4个回答

6

已解决。罪魁祸首是:

compile 'com.sun.mail:android-mail:1.5.6'
compile 'com.sun.mail:android-activation:1.5.6'

我不知道为什么,但是删除这两个软件包让整个应用程序能够在 Android 版本小于 21 的设备上运行和部署。

2
昨天,我检查了我所请求的gradle,并删除了以下行 compile 'com.sun.mail:android-mail:1.5.6',compile 'com.sun.mail:android-activation:1.5.6',然后编译通过了。这与任何api级别无关。发生这种情况是因为除你删除的模块之外,还有另一个模块使用了相同的包和相同的类 avax/activation/MimeTypeParseException.class。你在Application类中添加了以下内容吗?
@Override
protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

1
你不能添加两个支持库,因为它们会重叠。只需使用一个:support-v4。

啊,说得好。不幸的是,即使删除了 com.android.support:support-v13:25.0.0,仍然会出现相同的 TransformException 错误。 - Brett

1
你需要尝试使用支持注解库而不是jetbrains注解。因此,请更改。
compile 'org.jetbrains:annotations-java5:15.0'

to

compile 'com.android.support:support-annotations:25.0.0'

然后使用,对于@Nullable注释:
import android.support.annotation.Nullable;

关于 @NonNull
import android.support.annotation.NonNull;

补充:
不要忘记更改您的buildToolsVersiontargetSdkVersioncompileSdkVersionSupport Library,以使用相同的API级别。


更新
根据android-apt文档,您需要移除apt插件并使用annotationProcessor

From apt to annotationProcessor

As of the Android Gradle plugin version 2.2, all functionality that was previously provided by android-apt is now available in the Android plugin. This means that android-apt is officially obsolete ;) Here are the steps to migrate:

  • Make sure you are on the Android Gradle 2.2 plugin or newer.
  • Remove the android-apt plugin from your build scripts
  • Change all apt, androidTestApt and testApt dependencies to their new format:

    dependencies {
        compile 'com.google.dagger:dagger:2.0'
        annotationProcessor 'com.google.dagger:dagger-compiler:2.0' 
    }
    

同时,从您的build.gradle中删除apt插件,即:

apply plugin: 'com.neenbedankt.android-apt'

删除重复的joda-time条目,只使用其中一个:

compile 'joda-time:joda-time:2.9.5'
compile 'joda-time:joda-time:2.9.6'

建议:
您需要移除一些与以下类似的库,它们具有相似的功能:

compile 'de.hdodenhof:circleimageview:2.1.0'
compile 'com.makeramen:roundedimageview:2.2.1'
compile 'com.liuzhuang.opensource:rcimageview:0.0.2'
compile 'com.github.siyamed:android-shape-imageview:0.9.+@aar'

选择一个最适合您需求的。不要浪费时间去检查它们所有。

此外,您只需要选择以下图片库中的一个:

compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.stfalcon:frescoimageviewer:0.3.1'
compile 'com.github.bumptech.glide:glide:3.7.0'

我已更新帖子,包括完整的gradle文件。buildToolsVersiontargetSdkVersioncompileSdkVersion和支持库都设置为api 25。我还删除了jetbrains注释,并用支持注释替换了它。但仍然出现相同的错误。 - Brett
你有一些重复的依赖项,例如:compile 'joda-time:joda-time:2.9.5'compile 'joda-time:joda-time:2.9.6' - ישו אוהב אותך
你不需要使用apt,而是使用annotationProcessor来代替apt "com.google.auto.value:auto-value:1.2" - ישו אוהב אותך
好的信息。我根据您的建议删除了 apt,并且删除了多余的 joda-time。我将继续处理剩余建议的单数形式。然而,原始问题仍然没有改进。我仍然在 API<21 的模拟器上看到"重复条目:javax/activation/MimeTypeParseException.class"的运行时错误。 - Brett

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接