使用ProGuard构建错误

时间:2015-11-25 07:25:51

标签: android android-gradle android-build android-proguard

当我在启用ProGuard的情况下运行项目时出现以下错误:

Warning:Exception while processing task java.io.IOException: proguard.ParseException: Expecting opening '{' at '|' in line 66 of file '/home/pipt/AndroidStudioProjects/gallery/app/proguard-rules.pro'

这是我的应用级build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}


apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    signingConfigs {
        myConfig {
            ...
        }
    }
    defaultConfig {
        applicationId 'com.galleri5.android'
        multiDexEnabled true
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 13
        versionName "0.11"
        signingConfig signingConfigs.myConfig
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources false
            signingConfig signingConfigs.myConfig
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
    packagingOptions {
        exclude 'META-INF/COM_CRAS.SF'
        exclude 'META-INF/COM_CRAS.RSA'
        exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.properties'
        exclude 'META-INF/maven/com.squareup.okhttp/okhttp/pom.xml'
        exclude 'META-INF/maven/com.squareup/otto/pom.properties'
        exclude 'META-INF/maven/com.squareup/otto/pom.xml'
        exclude 'META-INF/maven/com.squareup.okhttp-protocols/okhttp-protocols/pom.properties'
        exclude 'META-INF/maven/com.squareup.okhttp-protocols/okhttp-protocols/pom.xml'
    }
}

    repositories {
        mavenCentral()
        mavenLocal()
        jcenter()
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
    }

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.1.0'
    compile 'com.android.support:support-v4:23.1.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.android.support:design:23.1.0'
    compile 'com.facebook.android:facebook-android-sdk:4.3.0'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.4.0'
    compile 'com.android.support:recyclerview-v7:23.1.0'
    compile 'com.android.support:cardview-v7:23.1.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'com.github.clans:fab:1.6.1'
    compile 'com.facebook.fresco:fresco:0.8.1+'
    compile 'com.facebook.fresco:imagepipeline-okhttp:0.8.1+'
    compile 'uk.co.chrisjenx:calligraphy:2.1.0'
    compile 'com.google.android.gms:play-services-analytics:8.1.0'
    compile 'com.commit451:PhotoView:1.2.4'
    compile 'com.github.liuguangqiang.swipeback:library:1.0.2@aar'
    compile 'me.imid.swipebacklayout.lib:library:1.0.0'
    compile 'com.github.2359media:EasyAndroidAnimations:0.8'
    compile('com.crashlytics.sdk.android:crashlytics:2.5.2@aar') {
        exclude group: 'com.squareup.okhttp', module: 'okhttp'
        transitive = true;
    }
}

这是我的proguard-rules.pro

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/pipipzz/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}
-dontwarn com.facebook.android.BuildConfig

#Butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

#retrofit
-dontwarn retrofit.**
-keep class retrofit.** { *; }
-keepattributes Signature
-keepattributes Exceptions

# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
    @com.facebook.common.internal.DoNotStrip *;
}

# Keep native methods
-keepclassmembers class * {
    native <methods>;
}

-dontwarn okio.**
-dontwarn javax.annotation.**
-dontwarn com.android.volley.toolbox.**

#Square
-dontwarn com.squareup.okhttp.**
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }

-keepattributes *Annotation*
-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**
-keepattributes SourceFile,LineNumberTable
-dontwarn com.crashlytics.**

-keep class <crashlytics | squareup | other>
-dontwarn <crashlytics | squareup | other>

我认为错误在ProGuard文件的语法中。我该如何解决这个问题?

修改:如果我删除了proguard-rules.pro的最后两行,那么我会收到有关构建过程的警告以及我的应用崩溃:

Warning: can't write resource [META-INF/maven/com.squareup.okhttp/okhttp-urlconnection/pom.properties] (Duplicate zip entry [META-INF/maven/com.squareup.okhttp/okhttp-urlconnection/pom.properties])
Warning: can't write resource [META-INF/maven/com.squareup.okhttp/okhttp-urlconnection/pom.xml] (Duplicate zip entry [META-INF/maven/com.squareup.okhttp/okhttp-urlconnection/pom.xml])
Warning: can't write resource [META-INF/maven/com.nineoldandroids/library/pom.properties] (Duplicate zip entry [META-INF/maven/com.nineoldandroids/library/pom.properties])
Warning: can't write resource [META-INF/maven/com.nineoldandroids/library/pom.xml] (Duplicate zip entry [META-INF/maven/com.nineoldandroids/library/pom.xml])
Warning: can't write resource [META-INF/maven/com.squareup.okio/okio/pom.properties] (Duplicate zip entry [META-INF/maven/com.squareup.okio/okio/pom.properties])
Warning: can't write resource [META-INF/maven/com.squareup.okio/okio/pom.xml] (Duplicate zip entry [META-INF/maven/com.squareup.okio/okio/pom.xml])
Warning: can't write resource [META-INF/maven/com.squareup.retrofit/retrofit/pom.properties] (Duplicate zip entry [META-INF/maven/com.squareup.retrofit/retrofit/pom.properties])
Warning: can't write resource [META-INF/maven/com.squareup.retrofit/retrofit/pom.xml] (Duplicate zip entry [META-INF/maven/com.squareup.retrofit/retrofit/pom.xml])
Warning: can't write resource [META-INF/maven/com.jakewharton/butterknife/pom.properties] (Duplicate zip entry [META-INF/maven/com.jakewharton/butterknife/pom.properties])
Warning: can't write resource [META-INF/maven/com.jakewharton/butterknife/pom.xml] (Duplicate zip entry [META-INF/maven/com.jakewharton/butterknife/pom.xml])
Warning: can't write resource [META-INF/maven/com.squareup.picasso/picasso/pom.properties] (Duplicate zip entry [META-INF/maven/com.squareup.picasso/picasso/pom.properties])
Warning: can't write resource [META-INF/maven/com.squareup.picasso/picasso/pom.xml] (Duplicate zip entry [META-INF/maven/com.squareup.picasso/picasso/pom.xml])
Warning: can't write resource [META-INF/services/javax.annotation.processing.Processor] (Duplicate zip entry [META-INF/services/javax.annotation.processing.Processor])
Warning: can't write resource [fabric/com.crashlytics.sdk.android.answers.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.answers.properties])
Warning: can't write resource [fabric/com.crashlytics.sdk.android.beta.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.beta.properties])
Warning: can't write resource [fabric/io.fabric.sdk.android.fabric.properties] (Duplicate zip entry [fabric/io.fabric.sdk.android.fabric.properties])
Warning: can't write resource [fabric/com.crashlytics.sdk.android.crashlytics-core.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.crashlytics-core.properties])
Warning: can't write resource [fabric/com.crashlytics.sdk.android.crashlytics.properties] (Duplicate zip entry [fabric/com.crashlytics.sdk.android.crashlytics.properties])

我该如何解决这个问题?

0 个答案:

没有答案