【问题标题】:Unable to build apk or run the app无法构建 apk 或运行应用程序
【发布时间】:2018-08-29 20:21:13
【问题描述】:

gradle 构建成功完成,但在运行应用程序或尝试构建 apk 时出现错误:

错误:任务 ':app:transformClassesWithMultidexlistForDebug' 执行失败。 java.io.IOException: Can't write [F:\TravEz\app\build\intermediates\multi-dex\debug\componentClasses.jar] (Can't read [C:\Users\hp.gradle\caches\transforms -1\files-1.1\support-core-ui-27.1.0.aar\51b8cdc0bcfc98652d9ae95f70697b30\jars\classes.jar(;;;;;;**.class)] (重复的 zip 条目 [classes.jar:android/支持/设计/小部件/CoordinatorLayout$Behavior.class]))

here提到的所有方法我都试过了

这是我的项目级 gradle 文件:

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:3.1.0'
}
}

allprojects {
repositories {
    google()
    jcenter()
    maven { url "https://jitpack.io"}
    //Glomadrian maven for animated switch
    maven { url "https://dl.bintray.com/glomadrian/maven"}
    maven { url  "http://dl.bintray.com/lukaville/maven"}
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

这是我的应用级 gradle 文件:

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.travez.travez"
    minSdkVersion 19
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
dexOptions {
    javaMaxHeapSize "4g"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//noinspection GradleCompatible
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
compile 'com.github.florent37:materialtextfield:1.0.7'
//library for cardview
implementation 'com.android.support:cardview-v7:26.1.0'
//library for dialog box
implementation 'com.github.d-max:spots-dialog:0.7@aar'
//library for animated switch
implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1@aar'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
//Firebase authentication library
implementation 'com.google.firebase:firebase-auth:11.0.4'
//Firebase database library
implementation 'com.google.firebase:firebase-database:11.0.4'
//Google play services and maps libraries
implementation 'com.google.android.gms:play-services-maps:11.0.4'
implementation 'com.google.android.gms:play-services:11.0.4'
implementation 'com.google.android.gms:play-services-location:11.0.4'
//Geofire library
compile 'com.firebase:geofire-android:2.3.0'
//Runtime perission library
compile 'com.github.karanchuri:PermissionManager:0.1.0'
//Material Edit Text library
implementation 'com.rengwuxian.materialedittext:library:2.1.4'
//Calligraphy library
implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
// CircleView library
implementation 'de.hdodenhof:circleimageview:2.2.0'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation 'id.zelory:compressor:2.1.0'
implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
compile 'com.android.support:multidex:1.0.0'
compile 'com.nbsp:library:1.8'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
apply plugin: 'com.google.gms.google-services'

【问题讨论】:

    标签: java android gradle


    【解决方案1】:
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    

    写了两次,删除其中一个。

    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    

    将 + 替换为库的当前版本

    【讨论】:

      【解决方案2】:

      问题是因为您的依赖项中有重复的支持库。

      android-image-cropper 正在使用 27+ 的支持库,您可以查看its build.gradle。 MaterialEditText 正在使用support library 22.2.0。 Material Animated Switch 使用的是support library 22.2.0。您需要从中排除支持库。

      所以,改为使用以下内容:

      compile 'com.github.florent37:materialtextfield:1.0.7'
      implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1@aar'
      implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
      

      使用以下内容:

      implementation 'com.android.support:support-annotations:26.1.0'
      
      implementation ('com.github.florent37:materialtextfield:1.0.7') {
          exclude group: 'com.android.support'
          exclude module: 'appcompat-v7'
          exclude module: 'support-annotations'
      }
      
      implementation ('com.github.glomadrian:MaterialAnimatedSwitch:1.1@aar') {
          exclude group: 'com.android.support'
          exclude module: 'appcompat-v7'
      }
      
      implementation ('com.theartofdev.edmodo:android-image-cropper:2.6.0') {
          exclude group: 'com.android.support'
          exclude module: 'appcompat-v7'
      }
      

      如果你仍然发现有冲突的库,你可以检查依赖树:

      ./gradlew app:dependencies
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-03
        • 1970-01-01
        • 2019-05-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多