已签名的APK在Proguard Enable中崩溃 [英] Signed apk getting crashed in proguard enable

查看:172
本文介绍了已签名的APK在Proguard Enable中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中使用proguard,将proguard设置为true,然后问题开始了,当我使用Proguard时,通过遵循这也.请Plz指导我如何执行此操作?

I am trying to use proguard in my app set the proguard to true and then the problem starts I am importing lib when I use proguard by following this -keepnames class com.somepackage.* with my package name the app is getting getting crashed when I try to use the signed apk. I know this iS a dumb question but I am stuck at this for last 5 hr not able to find an easy solution as I am using about 20 lib. I followed this also. Plz guide me in this how can I do this?

这是我的proguard规则类代码

This is my proguard rule class code

-keepnames class beatbox.neelay.dummybeat.*
-keepnames com.srx.widget.*
-keepnames de.hdodenhof.circleimageview.CircleImageView.*
-keepnames com.bumptech.glide.*
-keepnames com.romainpiel.shimmer.*
-keepnames com.vansuita.gaussianblur.GaussianBlur
-keepnames com.antonyt.infiniteviewpager.InfinitePagerAdapter
-keepnames com.antonyt.infiniteviewpager.InfiniteViewPager
-keepnames com.eftimoff.viewpagertransformers.CubeOutTransformer
-keepnames com.ms.square.android.glassview.GlassView
-keepnames me.alexrs.fontpagertitlestrip.lib.FontPagerTitleStrip

我现在无法生成任何已签名的apk.错误是.

I am not able to generate any signed apk now . the error is.

Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

作业失败,请参阅日志以获取详细信息

Job failed, see logs for details

任何提示都会有所帮助. 控制台输出

any hint will be helpful. console output

FAILURE: Build failed with an exception.

  • 出了什么问题: 任务':app:transformClassesAndResourcesWithProguardForRelease'的执行失败.

    • What went wrong: Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.

      作业失败,请参阅日志以获取详细信息

      Job failed, see logs for details

    • 尝试: 使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行,以获取更多日志输出.

    • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

      编辑build.gradle

      Editing build.gradle

      apply plugin: 'com.android.application'
      
      android {
      compileSdkVersion 25
      buildToolsVersion "25.0.1"
      defaultConfig {
          applicationId "beatbox.neelay.dummybeat"
          minSdkVersion 16
          targetSdkVersion 25
          versionCode 1
          versionName "1.0"
          renderscriptTargetApi 24
          renderscriptSupportModeEnabled true
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
      
          vectorDrawables.useSupportLibrary = true
      }
      lintOptions {
          checkReleaseBuilds false
          abortOnError false
      }
      buildTypes {
          release {
              shrinkResources true
              minifyEnabled true
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      }
      
      repositories {
      jcenter()
      mavenCentral()
      maven { url "https://jitpack.io" }
      maven { url 'http://Manabu-GT.github.com/GlassView/mvn-repo' }
      }
      
      dependencies {
      compile fileTree(include: ['*.jar'], dir: 'libs')
      androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
          exclude group: 'com.android.support', module: 'support-annotations'
      })
      compile project(':foldingtabbar')
      compile 'com.android.support:appcompat-v7:25.2.0'
      compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha7'
      compile 'com.android.support:design:25.2.0'
      compile 'com.github.bumptech.glide:glide:3.7.0'
      compile 'com.intuit.sdp:sdp-android:1.0.4'
      compile 'com.leo.simplearcloader:simplearcloader:1.0.1'
      compile 'com.ms.square:glassview:0.1.0'
      compile 'de.hdodenhof:circleimageview:2.1.0'
      compile 'com.romainpiel.shimmer:library:1.4.0@aar'
      compile 'com.github.StephenVinouze:ShapeView:1.1.0'
      compile 'com.eftimoff:android-viewpager-transformers:1.0.1@aar'
      compile 'com.github.antonyt:InfiniteViewPager:v1.0.0'
      compile 'me.alexrs:font-pager-titlestrip:1.0.0'
      compile 'com.github.florent37:arclayout:1.0.1'
      compile 'com.android.support:cardview-v7:25.1.0'
      compile 'com.android.support:support-v4:25.1.0'
      compile 'com.github.jrvansuita:GaussianBlur:v1.0.2'
      compile 'com.google.code.gson:gson:2.7'
      compile 'com.android.support:support-vector-drawable:25.2.0'
      testCompile 'junit:junit:4.12'
      }
      

      我尝试使用proguard-rule.pro的另一种方法

      another way i tried for proguard-rule.pro

      -keepnames class beatbox.neelay.dummybeat.**{*;}
      -keepnames class com.srx.widget.**{*;}
      -keepnames class de.hdodenhof.circleimageview.CircleImageView.**{*;}
      -keepnames class com.bumptech.glide.**{*;}
      -keepnames class com.romainpiel.shimmer.**{*;}
      -keepnames class com.vansuita.gaussianblur.**{*;}
      -keepnames class com.antonyt.infiniteviewpager.**{*;}
      -keepnames class com.eftimoff.viewpagertransformers.**{*;}
      -keepnames class com.ms.square.android.glassview.**{*;}
      -keepnames class me.alexrs.fontpagertitlestrip.lib.FontPagerTitleStrip**{*;}
      

      依赖树

      推荐答案

      原因: 并非每个类或库都在启用Proguard的情况下进行了优化,因此Proguard所做的是,如果未对类或库进行优化,则会删除这些类,这会导致崩溃和项目中的错误.

      Reason : Not every Class or Library are optimized with Proguard enabled , So what Proguard do is that it removes classes if they are not optimize which results crash and bugs in project.

      解决方案::在您的proguard.cfg文件中保留,是progaurd不支持的类或​​库.尝试抓住这里描述的所有内容:
      尝试添加:

      Solution : In your proguard.cfg file keep that classes or library which are not supported by progaurd . Try the catch all described here :
      Try adding :

      -keep class android.support.v7.internal.** { *; }
      -keep interface android.support.v7.internal.** { *; }
      -keep class android.support.v7.** { *; }
      -keep interface android.support.v7.** { *; }
      


      或者,如果您使用的是v4 lib:


      Or , if you are using v4 lib :

      -dontwarn android.support.v4.**
      -keep class android.support.v4.** { *; }
      -dontwarn android.support.v7.**
      -keep class android.support.v7.** { *; }
      


      如果您使用的是最新的android studio,您可能会发现它为proguard-rules.pro


      If you are using latest android studio you might found this as proguard-rules.pro


      您的情况也请尝试使用 -dontwarn和类名.像您的错误所示,它无法优化circleimageview库.所以也尝试添加它:


      In your case try using -dontwarn as well with classname. Like your error show that it can not optimize circleimageview Library . so try to add this as well :

      -dontwarn hdodenhof.**
      -keep class hdodenhof.**
      


      如果仍然无法正常运行,请降级您的circleimageview库:
      compile 'de.hdodenhof:circleimageview:1.3.0'这对我来说是正常的.


      If still not working than downgrade your circleimageview library :
      compile 'de.hdodenhof:circleimageview:1.3.0' This is working for me.

      这篇关于已签名的APK在Proguard Enable中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆