【问题标题】:Android app crashes after Signing签名后 Android 应用程序崩溃
【发布时间】:2015-07-31 06:56:13
【问题描述】:
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'
}

当我通过 gradle 中的“minify true”密钥签署我的应用程序应用程序时,它在完成后崩溃。 但是当我设置“minify false”时,它在签名后工作正常。 所以告诉我在 gradle 文件中是否有任何添加来释放带有“minify true”属性的内容。 供您参考,我添加了 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.**

【问题讨论】:

标签: android android-gradle-plugin proguard


【解决方案1】:

你需要为proguard配置你的规则

例如黄油刀

Butter Knife 动态生成和使用类,这意味着像 ProGuard 这样的静态分析工具可能认为它们没有被使用。为了防止它们被删除,明确标记它们要保留。为了防止 ProGuard 重命名在成员字段上使用 @Bind 的类,请使用 keepclasseswithmembernames 选项。

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

对于gson

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

对所有其他需要定义这些规则的外部库也这样做。你可以查看他们的网站或github项目主页

在哪里添加以上所有内容

getDefaultProguardFile('proguard-android.txt') 方法从 Android SDK tools/proguard/ 文件夹 获取默认的 ProGuard 设置。

proguard-android-optimize.txt 文件也可在此 Android SDK 文件夹中找到,具有相同的规则,但启用了优化。

proguard-rules.pro 指的是您的项目结构下的那个。

定义规则将防止混淆类名,从而避免崩溃。

【讨论】:

  • 在你的 gradle 文件中查看@proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
  • 好的,如果我将它 proguard-rules.pro 更改为 proguard-android-optimize.txt 它是否对我有用
  • @Umang 这不是问题。您只需要定义规则,以便 proguard 不会混淆您的类名。您是否为所有提到的库定义了规则?
  • 不,我没有上述库的规则。你能告诉我这些图书馆的规则吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-04
  • 1970-01-01
相关资源
最近更新 更多