Zebulon Li Zebulon Li - 1 month ago 12
Android Question

android gradle duplicate jar

I use

gradle
to build my project.

my project
:wxy


my lib-project
:news


in
:wxy build.gradle


android{
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/INDEX.LIST'
exclude 'META-INF/MANIFEST.MF'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile project(':news')
}


in
:news build.gradle


dependencies {
provided files('libs/Android_Location_V1.2.0.jar')
}


:wxy
and
:news
have the same jar "Android_Location_V1.2.0.jar" with same SHA hash. It builds successfully in
:wxy:assembleDebug
.

However, build failed in
:wxy:assembleRelease
which open proguard. It has error message:

Execution failed for task ':wxy:proguardRelease'.
java.io.IOException: Can't write
[C:\src\wxy\wxy\wxy\build\intermediates\classes-proguard\release\classes.jar]
(Can't read [C:\src\wxy\wxy\wxy\build\intermediates\exploded-aar\wxy\360news\unspecified\libs\Android_Location_V1.2.0.jar(;;;;;;!META-INF/MANIFEST.MF)]
(Duplicate zip entry [com/a/bn.class == Android_Location_V1.2.0.jar:com/aps/u.class]))


It seems that I compile the
Location.jar
twice. The 'provided' has no effect.

How should I do?

EDIT
wxy/build.gradle

apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "*****"
minSdkVersion 14
targetSdkVersion 21
versionCode 55555
versionName "4.1.3"
testApplicationId '******'
}



packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/INDEX.LIST'
}

lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}

productFlavors {
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}

signingConfigs {
key {
storeFile file("*****");
storePassword "****"
keyAlias "****"
keyPassword "***"
}
}

buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard.cfg'
signingConfig signingConfigs.key
}

debug {
applicationIdSuffix ".dev"
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
// compile 'com.android.support:appcompat-v7:21.0.3'
compile project(':news')
compile project(':libs:alipay')
androidTestCompile 'org.easymock:easymock:3.3.1'

}


news/build.gradle

apply plugin: 'com.android.library'
apply plugin: 'maven'

def propGroup = '*****'
def propArtifactId = '****'
def propVersion = '1.0.0'

android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
minSdkVersion 14
targetSdkVersion 21
versionCode 1
versionName "1.0"
}

sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
jniLibs.srcDirs = ['libs']
}
}

packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/MANIFEST.MF'
exclude 'libs/Android_Location_V1.2.0.jar'
}

}

dependencies {
compile files('libs/gson-2.2.4.jar')
compile files('libs/sharenews.jar')
provided files('libs/Android_Location_V1.2.0.jar')
provided files('libs/android-support-v4.jar')
}

uploadArchives {
repositories.mavenDeployer {
repository(url: '*****') {
authentication(userName: "deployment", password: "deployment123")
pom.groupId = propGroup
pom.version = propVersion
pom.artifactId = propArtifactId
pom.name = propArtifactId
pom.packaging = 'aar'
}
}
}


my proguard.cfg

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
#-dontskipnonpubliclibraryclassmembers
-dontpreverify
-verbose
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

-dontwarn org.jboss.netty.**
-keepattributes SourceFile,LineNumberTable

-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class * extends android.view.View
-keep class * extends android.support.v4.app.Fragment
-keep public class com.android.vending.licensing.ILicensingService

-keep class **.R$* {*;}
-keep class com.unionpay.upomp.bypay.** {*;}
-keep class android.support.v4.** {*;}
-dontwarn android.support.v4.**
-keep public class * implements java.io.Serializable {
public *;
}
-keepclassmembers class * implements java.io.Serializable {
static final long serialVersionUID;
private static final java.io.ObjectStreamField[] serialPersistentFields;
private void writeObject(java.io.ObjectOutputStream);
private void readObject(java.io.ObjectInputStream);
java.lang.Object writeReplace();
java.lang.Object readResolve();
}


-keepclasseswithmembers class * {
native <methods>;
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}

-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}

-keepclassmembers class * implements com.comisys.gudong.client.task.pay.PayTask{
public <init>(android.app.Activity);
}

-keepclassmembers class com.comisys.gudong.client.model.**{
public void set*(***);
public *** get*();
public boolean is*();
<fields>;
}
-keepclassmembers class com.comisys.gudong.client.net.model.**{
public void set*(***);
public *** get*();
public boolean is*();
<fields>;
}
-keepclassmembers class com.comisys.gudong.client.uiintepret.bean.**{
public void set*(***);
public *** get*();
public boolean is*();
<fields>;
}

-keep interface com.comisys.gudong.client.net.model.protocal.IUserEncode{
*;
}
-keepclassmembers class * implements com.comisys.gudong.client.net.model.protocal.IUserEncode {
<fields>;
public void set*(***);
public *** get*();
public boolean is*();
}

-keep interface com.comisys.gudong.client.net.model.protocal.IUserEncode$IENCODE{
*;
}
-keep class * implements com.comisys.gudong.client.net.model.protocal.IUserEncode$IENCODE{
public ** encode(**);
public ** decode(**);
}

-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}

-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
-keepclassmembers class * extends android.app.Activity{
public void permissionFilter(android.view.View);
}




#第三方包
-keep public class com.comisys.pinyin.Helper
{
public *;
}

-keep class org.jboss.** {*;}
-keep class com.iflytek.** {*;}
-keep class com.mapabc.** {*;}
-dontwarn com.mapabc.**
-keep class cn.yunzhisheng.** {*;}
-keep class com.comisys.gudong.client.util.pinyin.**{*;}

#-libraryjars ../business/libs/fastjson-1.1.37.jar
-keep class com.alibaba.fastjson.** { *; }
-dontwarn com.alibaba.fastjson.**

#-libraryjars /libs/Android_Location_V1.2.0.jar
#-libraryjars /libs/Android_Services_V2.2.0.jar
#-libraryjars /libs/Android_Map_V2.2.0.jar
-keep class com.amap.api.**{*;}
-dontwarn com.amap.**
-dontwarn demo.**
-dontwarn com.so.newsplugin.**
-keep class ru.truba.touchgallery.**{*;}
-dontwarn ru.truba.touchgallery.**
-keepattributes Signature
-keep class com.comisys.gudong.client.ui.view.MyGallery{
*;
}
# begin 360news
#反射类不能进行混淆编译,需加入
-dontwarn com.so.newsplugin.model.**
-keep class com.so.newsplugin.model.** {*;}

-dontwarn com.so.newsplugin.service.**
-keep class com.so.newsplugin.service.** {*;}

-dontwarn com.so.newsplugin.activity.**
-keep class com.so.newsplugin.activity.** {*;}

-dontwarn com.so.newsplugin.fragment.**
-keep class com.so.newsplugin.fragment.** {*;}

-dontwarn com.so.newsplugin.widget.**
-keep class com.so.newsplugin.widget.** {*;}

-dontwarn com.so.newsplugin.imgcache.**
-keep class com.so.newsplugin.imgcache.** {*;}

# Application classes that will be serialized/deserialized over Gson
-keep class com.google.gson.examples.android.model.** { *; }

-keepclassmembers class fqcn.of.javascript.interface.for.webview {
public *;
}

# end 360news

-keep class com.comisys.gudong.client.WebViewActivity$HtmlJSInterface{
*;
}


only the

-keep class com.amap.api.**{*;}

-dontwarn com.amap.**


affact the Location.jar.I keep all classes in Location.jar.

Answer

Yeah,I make it.

The solution is at Computing Version code in multi-flavor setup. Capture Handling transitive dependencies for local artifacts (jars and aar).

solution 1,upload the jar to maven repository.And reference it.

dependencies {
    compile '*****'
}

solution 2, create a libproject,move the jar into the project. :wxy and :news both reference it.

dependencies {
    compile project('*****')
}
Comments