2017-08-09 37 views
0

錯誤:執行任務':app:transformClassesWithJarMergingForRelease'失敗。

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/widget/CursorAdapter$MyDataSetObserver.class - List item

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 26 
    buildToolsVersion "26.0.1" 
    dexOptions { 
     javaMaxHeapSize "4g" 
    } 
    defaultConfig { 
     applicationId "com.omairm.hoops" 
     minSdkVersion 14 
     targetSdkVersion 23 
     multiDexEnabled true 

     ndk { 
      moduleName "player_shared" 
     } 
    } 
    sourceSets { 
      main { 
       jni.srcDirs = [] 
      } 
     } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
     } 
    } 
} 

dependencies { 
    compile ('com.google.android.gms:play-services:+'){exclude module: 'Support-v4'} 
    compile files('libs/PTAdRevMob.jar') 
    compile files('libs/dagger-1.2.2.jar') 
    compile files('libs/javax.inject-1.jar') 
    compile files('libs/nineoldandroids-2.4.0.jar') 
    compile files('libs/support-v4-19.0.1.jar') 
} 

我需要刪除CursorAdapter.class?

+0

究竟是你想使用JAR什麼文件?你意識到你正在使用真正舊的庫,對吧? –

+0

@ cricket_007這就是我從buildbox導出中得到的東西,我沒有絲毫的餘地,我會沿着 – Omair

+0

的方向學習更多......我可能會建議在深入Android之前學習Java基礎知識。那麼你可以選擇學習更多關於Maven或Gradle ... –

回答

0

您應該添加類似這樣的東西到你的build.gradle,其中添加了重複的文件,以排除

android { 
    configurations { 
    all*.exclude group: 'com.android.support', module: 'support-v4' 
    all*.exclude group: 'com.android.support', module: 'support-annotations' 
} 
} 
+0

是的,這表明他添加了重複的文件,如圖所示 –

+0

我不確定如何用重複文件對其進行編碼。我真的是編碼世界的新手 – Omair

1

do i need to delete the cursoradapter.class

這是很好的,你正在閱讀的錯誤和認識的至少一部分是什麼它告訴你,但你不能只從JAR文件中刪除一個類。 Gradle經歷的構建過程只會在發現的第一類衝突時拋出錯誤,而如果您只專注於該類衝突,那麼將會出現更多錯誤。


我的建議是找到每個JAR文件的正確和當前的庫,並隨時刪除jar文件。

另外,儘量實際使用一個數字值,而不是隻對版本加,因爲你不希望被使用會改變每隔幾個星期庫的α/β版本

如果您search around Maven可以替代大部分的JAR文件

dependencies { 
    compile "com.android.support:appcompat-v7:26+" 
    // Don't use just a plus here 
    compile ('com.google.android.gms:play-services:+'){exclude module: 'support-v4'} 
    compile files('libs/PTAdRevMob.jar') 
    compile group: 'com.squareup.dagger', name: 'dagger', version: '1.2.2' 
    // compile group: 'com.nineoldandroids', name: 'library', version: '2.4.0' 
} 

另外值得一提的是,nineoldandroids已被棄用的。既然你使用minSdkVersion 14,我認爲你甚至不需要它。

匕首也有很多版本,因爲1.2版本,但它已經包含的javax注入框架(見編譯依賴https://mvnrepository.com/artifact/com.squareup.dagger/dagger/1.2.2

你肯定會想看看Google Play | Selectively compiling APIs into your executable了。

注意,如果PTAdRevMob.jar有仍然在這裏任何其他庫衝突的任何類,你還是會得到一個錯誤,並可能需要切換到不同的廣告商