简体   繁体   English

签名后Android应用崩溃

[英]Android app crashes after Signing

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'

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


android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.android.hello"
        minSdkVersion 9
        targetSdkVersion 21
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_7
            targetCompatibility JavaVersion.VERSION_1_7
        }
    }

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

dependencies {
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/bolts-android-1.2.0.jar')
    compile files('libs/facebook.jar')
    compile 'de.hdodenhof:circleimageview:1.2.1'
    compile 'com.android.support:recyclerview-v7:21.0.+'
    compile 'com.android.support:cardview-v7:21.0.+'
    compile 'com.github.bumptech.glide:glide:3.5.2'
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile('com.crashlytics.sdk.android:crashlytics:2.4.0@aar') {
        transitive = true;
    }

    compile project(':gcmv')
    compile 'com.android.support:design:22.2.0'
}

when i signing my app app through a key with "minify true" in gradle it crashes after finishes. 当我通过gradle中带有“ minify true”的键对我的应用程序应用程序签名时,完成后会崩溃。 but when i set "minify false" it works fine after signing. 但是当我设置“ minify false”时,签名后效果很好。 so tell me is there any addition in the gradle file to release the with "minify true" property. 所以告诉我gradle文件中是否有任何其他内容可以释放具有“ minify true”属性的属性。 For your reference i add the gradle file and my proguard file. 供您参考,我添加了gradle文件和我的proguard文件。

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in C:\Users\UMANH\AppData\Local\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 *;
#}
-optimizations !code/simplification/arithmetic,!code/simplification/cast,!field/*,!class/merging/*
-optimizationpasses 5
-allowaccessmodification
-dontpreverify

# The remainder of this file is identical to the non-optimized version
# of the Proguard configuration file (except that the other file has
# flags to turn off optimization).

-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-verbose

-keepattributes *Annotation*
-keepattributes Signature
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService

# For native methods, see http://proguard.sourceforge.net/manual/examples.html#native
-keepclasseswithmembernames class * {
    native <methods>;
}

# keep setters in Views so that animations can still work.
# see http://proguard.sourceforge.net/manual/examples.html#beans
-keepclassmembers public class * extends android.view.View {
   void set*(***);
   *** get*();
}

# We want to keep methods in Activity that could be used in the XML attribute onClick
-keepclassmembers class * extends android.app.Activity {
   public void *(android.view.View);
}

# For enumeration classes, see http://proguard.sourceforge.net/manual/examples.html#enumerations
-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 **.R$* {
    public static <fields>;
}

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }

-keep class android.support.v4.app.** { *; }
-keep interface android.support.v4.app.** { *; }

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

-keepattributes EnclosingMethod

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

-keep class android.support.v7.widget.RoundRectDrawable { *; }

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

-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**

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

-keep public class android.** {*;}
-keep public class com.google.android.** {*;}


-keep class com.facebook.** {*;}
# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**
-dontwarn com.facebook.**
-dontwarn com.squareup.okhttp.**

You need to configure your rules for proguard 您需要配置Proguard的规则

For Example ButterKnife 例如黄油刀

Butter Knife generates and uses classes dynamically which means that static analysis tools like ProGuard may think they are unused. Butter Knife动态地生成和使用类,这意味着像ProGuard这样的静态分析工具可能会认为它们未使用。 In order to prevent them from being removed, explicitly mark them to be kept. 为了防止将其删除,请明确标记要保留。 To prevent ProGuard renaming classes that use @Bind on a member field the keepclasseswithmembernames option is used. 为防止ProGuard重命名在成员字段上使用@Bind的类,请使用keepclasseswithmembernames选项。

-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

For Glide 对于滑翔

-keep public class * implements com.bumptech.glide.module.GlideModule

-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}

For gson 对于格森

https://google-gson.googlecode.com/svn/trunk/examples/android-proguard-example/proguard.cfg https://google-gson.googlecode.com/svn/trunk/examples/android-proguard-example/proguard.cfg

Similarly do this for all other external libraries which requires defining these rules. 类似地,对需要定义这些规则的所有其他外部库执行此操作。 You can check their websites or github project home page 您可以检查他们的网站或github项目主页

Where to add all the above 在哪里添加以上所有内容

The getDefaultProguardFile('proguard-android.txt') method obtains the default ProGuard settings from the Android SDK tools/proguard/ folder . getDefaultProguardFile('proguard-android.txt')方法从Android SDK tools / proguard /文件夹获取默认ProGuard设置。

The proguard-android-optimize.txt file is also available in this Android SDK folder with the same rules but with optimizations enabled. 在相同的规则但启用了优化的情况下,该Android SDK文件夹中也提供了proguard-android-optimize.txt文件。

proguard-rules.pro refers to the one under your project structure. proguard-rules.pro是指您的项目结构下的那个。

Having the rules defined will prevent obfuscating class names which will avoid crash. 定义规则将防止混淆类名,从而避免崩溃。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM