2016-05-11 44 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')通过添加此项,您可以通过导入包名来访问此模块中的任何类。根据我的知识,您不能排除特定包到项目模块。 –

相关问题