无法构建apk或运行应用程序

时间:2018-03-20 21:02:23

标签: java android gradle

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

  

错误:任务':app:transformClassesWithMultidexlistForDebug'的执行失败。   java.io.IOException:无法写[F:\ TravEz \ app \ build \ intermediates \ multi-dex \ debug \ componentClasses.jar](无法读取[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'

2 个答案:

答案 0 :(得分:0)

implementation 'com.android.support.constraint:constraint-layout:1.0.2'

写两次,删除其中一个。

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

将+替换为库的当前版本

答案 1 :(得分:0)

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

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
相关问题