Android Proguard - 当shrinkResources为true时,构建失败

时间:2018-04-04 05:40:20

标签: android proguard android-proguard

我正在尝试使用proguard构建项目。如果我使用shrinkResources false它可以正常工作但是当shrinkResources为true且错误

时构建失败
Error:The string "--" is not permitted within comments.
Error:Execution failed for task ':app:packageDebug'.
> !directory.isDirectory()

我检查了字符串" - "在整个项目中,我没有找到字符串" - "在评论里面。所以我不理解这个错误。

这是我的gradle文件

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'io.fabric'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.eightsquare.eremit"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        dexOptions {
            javaMaxHeapSize "4g"
        }
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        debug {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility 1.8
        sourceCompatibility 1.8
    }
}

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

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

    dependencies {
        // These docs use an open ended version so that our plugin
        // can be updated quickly in response to Android tooling updates

        // We recommend changing it to the latest version from our changelog:
        // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin
        classpath 'io.fabric.tools:gradle:1.+'
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.android.support:appcompat-v7:$supportLibVersion"
    implementation "com.android.support:support-v13:$supportLibVersion"
    implementation "com.android.support:design:$supportLibVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibVersion"
    implementation "com.android.support:cardview-v7:$supportLibVersion"
    implementation "com.android.support:support-v4:$supportLibVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    //crashlytics
    implementation('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
        transitive = true
    }

    implementation "com.google.android.gms:play-services-vision:$firebase_version"

    //Android-Iconics
    implementation "com.mikepenz:iconics-core:2.8.8@aar"
    implementation 'com.mikepenz:google-material-typeface:3.0.1.1.original@aar'

    //Butterknife
    implementation "com.jakewharton:butterknife:8.8.1"
    kapt "com.jakewharton:butterknife-compiler:8.8.1"

    //saripaar validation library
    implementation 'com.mobsandgeeks:android-saripaar:2.0.3'

    //rootbeer for root checking
    implementation 'com.scottyab:rootbeer-lib:0.0.6'

    //kotpref
    implementation "com.chibatching.kotpref:kotpref:2.4.0"
    implementation "com.chibatching.kotpref:initializer:2.4.0" // optional
    implementation "com.chibatching.kotpref:enum-support:2.4.0" // optional
    implementation "com.chibatching.kotpref:gson-support:2.4.0" // optional
    implementation "com.chibatching.kotpref:livedata-support:2.4.0" // optional

    //encrypting kotpref
    implementation 'com.github.fly7632785:KotprefEncryptSupport:1.0.1'

    //afollestad/material-dialogs
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'

    //RippleView
    implementation 'com.github.traex.rippleeffect:ripple:1.3.1-OG'

    //for checking the current uploaded version on the Google Play
    implementation 'com.github.robohorse:gpversionchecker:1.4.0'

    //RxAndroid
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.0'

    //toasty
    implementation 'com.github.GrenderG:Toasty:1.2.5'

    //anko
    implementation "org.jetbrains.anko:anko:$anko_version"

    //picaso library
    implementation 'com.squareup.picasso:picasso:2.5.2'

    //image slider
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'

    //rx runtime permissions
    implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.5@aar'

    //circleimageview
    implementation 'com.makeramen:roundedimageview:2.3.0'

    //materialedittext
    implementation 'com.rengwuxian.materialedittext:library:2.1.4'

    //for recyclerview swipe
    implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'

    //facebook login
    implementation('com.facebook.android:facebook-android-sdk:4.30.0') {
        exclude group: 'com.google.zxing'
    }

    //firebase
    implementation "com.google.firebase:firebase-auth:$firebase_version"
    implementation "com.google.android.gms:play-services-auth:$firebase_version"

    //firebase Cloud Messaging
    implementation "com.google.firebase:firebase-messaging:$firebase_version"

    //graph
    implementation 'com.jjoe64:graphview:4.2.1'

    //Material date time picker
    implementation 'com.wdullaer:materialdatetimepicker:3.3.0'

    //signature pad
    implementation 'com.github.gcacace:signature-pad:1.2.1'

    //RxAndroid
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
    implementation 'io.reactivex.rxjava2:rxjava:2.1.8'

    //retrofit 2
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
    implementation "com.squareup.retrofit2:retrofit:$retrofit_version"

    //retrofit http interceptor
    implementation 'com.squareup.okhttp3:logging-interceptor:3.8.1'

    //gson converter factory
    implementation "com.squareup.retrofit2:adapter-rxjava2:$retrofit_version"
    implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
    implementation 'com.google.code.gson:gson:2.8.2'

    //input masking
    implementation 'com.redmadrobot:inputmask:2.3.0'

    implementation project(':idm-imgproc-1.1.99.70')
    implementation project(':opencv_3.2')
    implementation project(':card.io-5.5.1')

    //rxbinding
    implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
    implementation 'com.jakewharton.rxbinding2:rxbinding-design:2.1.1'

    //Multidex
    implementation 'com.android.support:multidex:1.0.1'
}


repositories {
    mavenCentral()
}


apply plugin: 'com.google.gms.google-services'

这是proguard-rules.pro文件 - `

# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# 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 *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
-optimizationpasses 5

#When not preverifing in a case-insensitive filing system, such as Windows. Because this tool unpacks your processed jars, you should then use:
-dontusemixedcaseclassnames

#Specifies not to ignore non-public library classes. As of version 4.5, this is the default setting
-dontskipnonpubliclibraryclasses

#Preverification is irrelevant for the dex compiler and the Dalvik VM, so we can switch it off with the -dontpreverify option.
-dontpreverify

#Specifies to write out some more information during processing. If the program terminates with an exception, this option will print out the entire stack trace, instead of just the exception message.
-verbose

#The -optimizations option disables some arithmetic simplifications that Dalvik 1.0 and 1.5 can't handle. Note that the Dalvik VM also can't handle aggressive overloading (of static fields).
#To understand or change this check http://proguard.sourceforge.net/index.html#/manual/optimizations.html
-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*

#To repackage classes on a single package
#-repackageclasses ''

#Uncomment if using annotations to keep them.
-keepattributes *Annotation*

#Keep classes that are referenced on the AndroidManifest
-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 com.android.vending.licensing.ILicensingService


#To remove debug logs:
-assumenosideeffects class android.util.Log {
    public static *** d(...);
    public static *** v(...);
}



#Maintain java native methods
-keepclasseswithmembernames class * {
    native <methods>;
}

#To maintain custom components names that are used on layouts XML.
#Uncomment if having any problem with the approach below
#-keep public class custom.components.package.and.name.**

#To maintain custom components names that are used on layouts XML:
-keep public class * extends android.view.View {
    public <init>(android.content.Context);
    public <init>(android.content.Context, android.util.AttributeSet);
    public <init>(android.content.Context, android.util.AttributeSet, int);
    public void set*(...);
}

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

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

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

#To keep parcelable classes (to serialize - deserialize objects to sent through Intents)
-keep class * implements android.os.Parcelable {
  public static final android.os.Parcelable$Creator *;
}

#Keep the R
-keepclassmembers class **.R$* {
    public static <fields>;
}

###### ADDITIONAL OPTIONS NOT USED NORMALLY

#To keep callback calls. Uncomment if using any
#http://proguard.sourceforge.net/index.html#/manual/examples.html#callback
#-keep class mypackage.MyCallbackClass {
#   void myCallbackMethod(java.lang.String);
#}

#Uncomment if using Serializable
-keepclassmembers class * implements java.io.Serializable {
    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();
}

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

#appcompat support
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

#kotpref
-keep class * extends com.chibatching.kotpref.KotprefModel

-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}

#design support
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }


# Retrofit 2.X
## https://square.github.io/retrofit/ ##

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

-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}

#Gson & hawk
-keep class com.google.gson.** { *; }
-keep class org.sqlite.** { *; }
-keep class org.sqlite.database.** { *; }


## GSON 2.2.4 specific rules ##

# Gson uses generic type information stored in a class file when working with fields. Proguard
# removes such information by default, so configure it to keep all of it.
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes *Annotation*

-keepattributes EnclosingMethod

# Gson specific classes
#-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.stream.** { *; }


# Application classes that will be serialized/deserialized over Gson
-keep class com.eightsquare.eremit.model.** { *; }


#saripaar
-keep class com.mobsandgeeks.saripaar.** {*;}
-keep @com.mobsandgeeks.saripaar.annotation.ValidateUsing class * {*;}

-keep class me.zhanghai.android.materialprogressbar.** { *; }

#proguard
-dontwarn com.squareup.okhttp.**

#jsoup rules
-keep public class org.jsoup.** {
    public *;
}


#apache
-dontnote android.net.http.*
-dontnote org.apache.http.**
-keep class org.apache.http.** { *; }
-dontwarn org.apache.http.**
-keep class android.net.http.** { *; }
-dontwarn android.net.http.**
-dontnote org.apache.commons.codec.**

#Data bindings
-dontwarn android.databinding.**
-keep class android.databinding.** { *; }

-dontwarn okio.**
-dontwarn retrofit2.Platform$Java8
-keepclasseswithmembers class * {
    @retrofit2.http.* <methods>;
}

#gson
-keep class com.google.**
-dontwarn com.google.**

#eremit package
-keep class com.eightsquare.eremit.model.** { *; }

# Keep the support library
-keep class android.support.v4.** { *; }
-keep interface android.support.v4.** { *; }


-keepattributes javax.xml.bind.annotation.*
-keepattributes javax.annotation.processing.*
-keepclassmembers class * extends java.lang.Enum { *; }
-keepclasseswithmembernames class android.**
-keepclasseswithmembernames interface android.**
-dontwarn android.databinding.**

#Android-Iconics
-keep class .R
-keep class **.R$* {
    <fields>;
}

#gpversionchecker
-keep public class org.jsoup.** {
public *;
}

# If you are using custom exceptions, add this line so that custom exception types are skipped during obfuscation:
-keep public class * extends java.lang.Exception

# For Fabric to properly de-obfuscate your crash reports, you need to remove this line from your ProGuard config:
#-printmapping mapping.txt

-dontwarn rx.**
-dontwarn okio.**

-keepattributes *Annotation*,EnclosingMethod,Signature
-dontwarn com.squareup.okhttp.**


-dontwarn javax.annotation.**
-dontwarn javax.inject.**
-dontwarn sun.misc.Unsafe


-dontobfuscate
-dontoptimize
-keepnames class ** { *; }
-keepnames interface ** { *; }
-keepnames enum ** { *; }

0 个答案:

没有答案