在gradle中不排除Apache公共依赖项Android的

时间:2017-02-27 20:40:27

标签: android gradle janrain

我有一个使用org.apache.http.legacy库的库项目(Janrain:Jump)。当我尝试构建我的项目时,我得到了如下的重复错误:

com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/commons/codec/StringEncoderComparator.class

所以我认为org.apache.commons是重复的条目,因为Janrain使用它,它也包含在Android 24中(作为外部库)。所以我试图从:跳跃gradle中删除公共:

configurations {
    all*.exclude group: 'org.apache.commons'
}

现在,我希望这会删除org.apache.commons,但我仍然会收到重复的条目gradle错误。

这是:跳转gradle文件

apply plugin: 'com.android.library'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.3"
    //If building with strict Android 6.0 the following will need to be uncommented
    //See: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html
    //And: http://stackoverflow.com/questions/31653002/how-to-use-the-legacy-apache-http-client-on-android-m
    useLibrary "org.apache.http.legacy"

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 24
        // replace the below string with your own Google client ID. Make sure this is consistent
        // with the values used in openid_appauth_idp_configs.xml
        manifestPlaceholders = [
                <my values>]
    }

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

    }
}

configurations {
    all*.exclude group: 'org.apache.commons'
}

dependencies {
    compile 'com.android.support:support-v4:24.2.0'
    compile files('libs/org.apache.http.legacy.jar')
    compile 'com.squareup.okhttp:okhttp:2.5.0'
    compile 'com.squareup.okhttp:okhttp-apache:2.5.0'
    compile 'com.squareup.okio:okio:1.6.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.retrofit:retrofit:1.8.0'
    compile 'net.openid:appauth:0.4.1'
}

allprojects {
    repositories {
        jcenter()
    }
    gradle.projectsEvaluated {
        tasks.withType(JavaCompile) {
            options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
        }
    }
}

为什么即使我将org.apache.commons包含在配置中,@SuppressWarnings("deprecation") public ItemStack[] loadSecoundtLaserInventory(){ ItemStack pan = new ItemStack(Material.STAINED_GLASS_PANE, 1, DyeColor.BLACK.getWoolData()); ItemMeta panmeta = pan.getItemMeta(); panmeta.setDisplayName(""); pan.setItemMeta(panmeta); List<ItemStack> content = new ArrayList<ItemStack>(); content.add(pan); // for(String str : getConfig().getConfigurationSection("lasers").getKeys(false)){ if(!str.startsWith("2")){ } String[] amounts = getConfig().getString("lasers." + str + "amount").split(";"); ItemStack is1 = new ItemStack(getConfig().getInt("lasers." + str + ".block-id")); ItemMeta ismeta1 = is1.getItemMeta(); ismeta1.setLore(Arrays.asList(HiddenStringUtil.encodeString(str))); ismeta1.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("lasers." + str + ".dname-amount").replace("{amount}", amounts[0]))); ItemStack is2 = new ItemStack(getConfig().getInt("lasers." + str + ".block-id")); ItemMeta ismeta2 = is2.getItemMeta(); ismeta2.setLore(Arrays.asList(HiddenStringUtil.encodeString(str))); ismeta2.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("lasers." + str + ".dname-amount").replace("{amount}", amounts[1]))); ItemStack is3 = new ItemStack(getConfig().getInt("lasers." + str + ".block-id")); ItemMeta ismeta3 = is3.getItemMeta(); ismeta3.setLore(Arrays.asList(HiddenStringUtil.encodeString(str))); ismeta3.setDisplayName(ChatColor.translateAlternateColorCodes('&', getConfig().getString("lasers." + str + ".dname-amount").replace("{amount}", amounts[2]))); is2.setItemMeta(ismeta2); if(!content.contains(is1)){ content.add(is1); } if(content.size() == 2){ content.add(pan); content.add(pan); } if(!content.contains(is2)){ content.add(is2); } if(content.size() == 5){ content.add(pan); content.add(pan); } if(!content.contains(is3)){ content.add(is3); } if(content.size() == 8){ content.add(pan); return content.stream().toArray(ItemStack[]::new); } } return null; } 也不会被排除?

1 个答案:

答案 0 :(得分:1)

只需将此任务添加到build.gradle,然后运行gradle findDuplicates即可找到jars

task findDuplicates {
    doLast {
        def findMe = 'org/apache/commons/codec/StringEncoderComparator.class'
        configurations.runtime.asFileTree.matching {
            include '**/*.jar'
        }.files.each { File jarFile ->
            zipTree(jarFile).visit { FileVisitDetails fvd ->
                if (fvd.path == findMe) {
                    println "Found $findMe in $jarFile.name"
                }
            }
        }
    }
}