2016-05-11 77 views
0

我有我的項目,其中包例如com.example.something,我將gradle lib項目添加到我的項目,我知道有相同的包。我嘗試編譯(項目(':插件機器人:應用')){ 排除組:'com.example.something' } 但它給出了錯誤: com.android.build.api.transform.TransformException:java .util.zip.ZipException:重複條目:如何在android studio中添加lib項目,但不包含特定的包?

是否有添加lib項目,同時排除該包及其下的所有java類?

這是LIB項目gradle這個

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.2" 

    defaultConfig { 
     minSdkVersion 11 
     targetSdkVersion 23 
     compileOptions { 
      sourceCompatibility JavaVersion.VERSION_1_7 
      targetCompatibility JavaVersion.VERSION_1_7 
     } 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt' 
     } 
    } 

} 

dependencies { 
    compile 'com.android.support:appcompat-v7:23.+' } 

,這是例如我的項目gradle產出的

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

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 'Google Inc.:Google APIs:23' 
    buildToolsVersion "23.0.3" 
    useLibrary 'org.apache.http.legacy' 

    defaultConfig { 
     applicationId "xxx.xxxx.xxxx" 
     minSdkVersion 11 
     targetSdkVersion 23 
     multiDexEnabled true 

     ndk { 
      moduleName "xxxxx-xxx" 
     } 
    } 
    dexOptions { 
     javaMaxHeapSize "2g" 
     preDexLibraries true 
    } 

    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard.cfg'), 'proguard-rules.txt' 
     } 
     debug { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard.cfg'), 'proguard-rules.txt' 
     } 
     debug { 
      jniDebuggable true 
      debuggable true 
     } 
    } 

    productFlavors { 
     emulator { 
     } 
     player { 
     } 
    } 

    sourceSets { 
     main { 
      jni { 
      } 
     } 
     emulator { 
     } 
     player { 
     } 
    } 

} 

dependencies { 
    compile "com.google.android.gms:play-services:8.1.0" 
    compile 'com.android.support:multidex:1.0.0' 
    compile 'com.android.support:appcompat-v7:23.0.1' 
    compile 'com.android.support:design:23.0.1' 
    compile fileTree(dir: 'src/main/libs', include: ['*.jar']) 
    compile (project(':plugin-imagecode-android:app')) { 
     //trying to exclude package com.example.something from the lib project 
    } 
} 
+0

你排除包或傳遞依賴? –

+0

我想排除java包。我不太確定傳遞依賴是什麼? –

+0

據我所知,你不能以這種方式排除一個包裹。您只能排除依賴關係。 –

回答

0

希望這有助於 你可以嘗試不包括包這樣

sourceSets { 
    main { 
     java { 
      include 'com/ourcompany/somepackage/activityadapter/**' 
      include 'com/ourcompany/someotherpackage/**' 
      exclude 'com/ourcompany/someotherpackage/fragment/**' 
     } 
    } 
} 
+0

這是在lib項目gradle中嗎?如果這樣做將無法工作,因爲項目提供編譯錯誤,它需要該包。 –

0

如果您嘗試以這種方式嘗試排除外部罐或包裝

compile ('com.android.something') { 
exclude module: 'name of module'`} 

或者如果你想排除類然後試試這個。

sourceSets { 
main { 
    java { 
     exclude 'classname.class' 
    } 
} 

}

+0

我想排除只在lib項目中的類,並將其包含在我的項目中,這不會這樣做 –

+0

讓我看看你的lib gradle文件,然後只有人可以理解你想做什麼。添加build.gradle文件先在qs。 –

+0

編譯項目(':library module name')通過添加此項,您可以通過導入包名來訪問此模塊中的任何類。根據我的知識,您不能排除特定包到項目模塊。 –

相關問題