2017-10-10 33 views
1

我正在嘗試將eclipse項目導入到android studio中。之後,將我的jar文件(即支持jar)添加到build gradle文件中,無論我在eclipse中使用什麼。雖然這樣做得到低於錯誤。如何解決android studio中bulid gradle中的重複條目

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'. 
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: android/support/v4/database/DatabaseUtilsCompat.class 

和我的gradle構建文件是:

apply plugin: 'com.android.application' 
configurations { 
    // all*.exclude group: 'com.android.support', module: 'support-v4' 
    // all*.exclude group: 'com.android.support', module: 'support-annotations' 
} 
android { 
    compileSdkVersion 25 
    buildToolsVersion "26.0.0" 

    useLibrary 'org.apache.http.legacy' 
    defaultConfig { 
     applicationId "com.xxx.xxxxx" 
     minSdkVersion 19 
     targetSdkVersion 25 
     multiDexEnabled true 
    } 

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

    aaptOptions { 
     cruncherEnabled = false 
    } 

} 

dependencies { 
    //compile 'com.android.support:appcompat-v7:25.2.0' 
    compile 'com.google.android.gms:play-services:+' 
    compile files('libs/android-query-full.0.26.7.jar') 
    compile files('libs/commons-httpclient-3.0.1.jar') 
    compile files('libs/glide-3.6.1.jar') 
    compile files('libs/httpmime-4.1.3.jar') 
    compile files('libs/library-1.2.1.jar') 
    compile files('libs/mpandroidchartlibrary-2-2-4.jar') 
    compile files('libs/picasso-2.4.0.jar') 
    compile files('libs/android-support-v4.jar') 
    compile files('libs/android-support-v7-appcompat.jar') 
    compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') { 
     exclude module: 'support-v4' // exclude duplicate library 
    } 

} 
+0

我被困在這裏。請幫我 – Durga

回答

0

把下面的代碼下面buildTypes重建再次投射

packagingOptions { 
    exclude 'META-INF/NOTICE' // will not include NOTICE file 
    exclude 'META-INF/LICENSE' // will not include LICENSE file 
    exclude 'META-INF/DEPENDENCIES' // will not include LICENSE file 
    exclude 'META-INF/LICENSE.txt' 
    exclude 'META-INF/NOTICE.txt' 
} 
+0

我在哪裏可以將這段代碼放在我的文件中 – Durga

+0

在build.gradle ...下面buildTypes標記 –

0

刪除線

compile files('libs/android-support-v4.jar') 
compile files('libs/android-support-v7-appcompat.jar') 
compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') { 
    exclude module: 'support-v4' // exclude duplicate library 
} 

,並添加此行

compile 'com.android.support:appcompat-v7:25.4.0' 
compile 'com.android.support:support-v4:25.4.0' 
compile org.eclipse.paho:org.eclipse.paho.android.service:1.0.2 

而且在Android {}

repositories { 
    mavenCentral() 
} 

欲瞭解更多信息裏面添加這個檢查此鏈接 https://www.eclipse.org/paho/clients/android/

+0

我試過這個..不工作..給我任何其他解決方案 – Durga

+0

檢查更新的代碼 – Anonymous

+0

如果我替換這個給出另一個錯誤..安裝知識庫和同步項目 – Durga

4

java.util.zip.ZipException:重複條目: android/support/v4/database/DatabaseUtilsCompat.class

問題

  • exclude module: 'support-v4'

不要

compile('org.eclipse.paho:org.eclipse.paho.android.service:1.0.2') { 
    exclude module: 'support-v4' // exclude duplicate library 
} 

你應該使用

compile group: 'org.eclipse.paho', name: 'org.eclipse.paho.android.service', version: '1.0.2' 

如果問題來然後在build.gradle部分

packagingOptions { 
     exclude 'META-INF/DEPENDENCIES' 
     exclude 'META-INF/NOTICE' 
     exclude 'META-INF/LICENSE' 
    } 

然後Clean-Rebuild-Run添加此。

+0

我已經嘗試過的代碼..它不會改變錯誤 – Durga

+0

@Durga添加'packagingOptions {METAL INF/DEPENDENCIES' 排除'META-INF/NOTICE' 排除'META-INF/LICENSE' }' –

+0

我必須添加此代碼.. ??! – Durga

相關問題