我使用gradle
来构建我的项目。
我的项目:wxy
我的lib-project :news
: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')
}
:news build.gradle
中的
dependencies {
provided files('libs/Android_Location_V1.2.0.jar')
}
:wxy
和:news
具有相同的jar“Android_Location_V1.2.0.jar”,具有相同的SHA哈希值。它在:wxy:assembleDebug
。
但是,在:wxy:assembleRelease
打开proguard时,构建失败。它有错误消息:
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]))
似乎我编译了Location.jar
两次。 “提供”没有效果。
我该怎么办?
修改 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'
}
新闻/的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'
}
}
}
我的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{
*;
}
只有
-keep class com.amap.api.**{*;}
-dontwarn com.amap.**
关注Location.jar.I将所有类保留在Location.jar。
答案 0 :(得分:1)
是的,我做到了。
解决方案是Computing Version code in multi-flavor setup。 捕获处理本地工件(罐子和罐子)的传递依赖性。
解决方案1,将jar上传到maven repository.And引用它。
dependencies {
compile '*****'
}
解决方案2,创建一个libproject,将jar移动到项目中。 :wxy和:news都引用它。
dependencies {
compile project('*****')
}
答案 1 :(得分:0)
你有没有把这些
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt')
}
}
}
或
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}