Proguard error while evaluating instruction - android

I upgrade my android project to 24 SDK version.
But I got error in Proguard path of build:
Unexpected error while evaluating instruction:
Class = [com/google/android/gms/iid/zzd]
Method = [zzeC(Ljava/lang/String;)V]
Instruction = [11] invokevirtual #50
Exception = [java.lang.ArrayIndexOutOfBoundsException] (1)
Unexpected error while performing partial evaluation:
Class = [com/google/android/gms/iid/zzd]
Method = [zzeC(Ljava/lang/String;)V]
Exception = [java.lang.ArrayIndexOutOfBoundsException] (1)
Warning: Exception while processing task java.io.IOException: java.lang.ArrayIndexOutOfBoundsException: 1
:PC:transformClassesAndResourcesWithProguardForDebug FAILED
FAILURE: Build failed with an exception.
My proguard.cfg file:
-printmapping /build/proguard-mapping.txt
-printusage /build/proguard-usage.txt
-printseeds /build/proguard-seeds.txt
-printconfiguration /build/proguard-configuration.txt
-optimizationpasses 5
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
-optimizations !class/unboxing/enum
-allowaccessmodification
-repackageclasses ''
-keepattributes Signature
-keepattributes SetJavaScriptEnabled
-keepattributes JavascriptInterface
-keepattributes InlinedApi
-keepattributes SourceFile, LineNumberTable
-keepattributes *Annotation*
-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 * extends android.preference.Preference
-libraryjars /libs
-dontwarn android.**
-dontwarn com.android.**
-dontwarn com.google.**
-dontwarn okio.**
-keep class com.google.** {*;}
-keepclassmembers class com.google.** { *; }
-keep class com.android.** {*;}
-keepclassmembers class com.android.** { *; }
-keep class okio.** {*;}
-keepclassmembers class okio.** { *; }
Build.gradle in project:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
classpath 'com.google.gms:google-services:3.0.0'
}
}
Build.gradle in app:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.2'
}
}
android {
compileSdkVersion 24
buildToolsVersion "24.0.0"
defaultConfig {
minSdkVersion 11
targetSdkVersion 24
signingConfig signingConfigs.release
}
buildTypes {
debug {
debuggable true
minifyEnabled true
signingConfig signingConfigs.release
proguardFile 'proguard.cfg'
}
release {
debuggable true
minifyEnabled true
signingConfig signingConfigs.release
proguardFile 'proguard.cfg'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services-gcm:9.0.0'
compile 'com.android.support:support-v4:24.0.0'
compile 'com.android.support:appcompat-v7:24.0.0'
}
This configs work fine on 22 android SDK, but after update to 24 got error.
I try add next but not success:
-keep class com.google.android.gms.analytics.**
-keep class com.google.analytics.tracking.**
-dontwarn com.google.android.gms.analytics.**
-dontwarn com.google.analytics.tracking.**
What is my error and what is a solution?

I ended up with the following proguard options:
# WORKAROUND for building project with GMS (google play services)
-keep class com.google.android.gms.iid.zzd { *; }
-keep class android.support.v4.content.ContextCompat { *; }

This is caused by buildtools working with 8.4 version of google play services. I tried excluding the particular class from optimization with -keep, but it didn't work. I ended up with migrating to google play services 9.0.2:
classpath 'com.android.tools.build:gradle:2.0.0'
classpath 'com.google.gms:google-services:3.0.0'
...
buildToolsVersion "24.0.0"
...
// google play services
compile ('com.google.android.gms:play-services-gcm:9.0.2')
compile ('com.google.android.gms:play-services-analytics:9.0.2')
...

Try using version 9.2.1; it seems they have fixed a proguard issue. Based on the release notes.
Refer link: https://developers.google.com/android/guides/releases

If you don't feel like bumping the play services just yet, you can also turn off the following optimizations in ProGuard, e.g.
-optimizations !method/marking/private,!method/marking/static,!method/removal/parameter,!method/propagation/parameter
Obviously, this might mean a performance hit, so use judiciously.

Try using version 9.2.1; it seems they have fixed a proguard issue. Based on the release notes.
Refer link: https://developers.google.com/android/guides/releases

Related

Signed apk getting crashed in proguard enable

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?
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
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.
What went wrong:
Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
Job failed, see logs for details
Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
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'
}
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**{*;}
the dependency tree
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.
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.** { *; }
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.** { *; }
If you are using latest android studio you might found this as proguard-rules.pro
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.**
If still not working than downgrade your circleimageview library : compile 'de.hdodenhof:circleimageview:1.3.0' This is working for me.
1) Keep all annotations
-keepattributes SourceFile,LineNumberTable,*Annotation*,EnclosingMethod,Signature,Exceptions,InnerClasses
2) Keep if you have any pojos or models and classes which are using for network call
Ex:
-keep class com.example.android.models.**
-keepclassmembers class com.example.android.models.** {
*;
}
-keepclassmembers class com.example.android.network.** {
public void set*(***);
public *** get*();
public *** is*();
}
3) For all the libraries you are using keep below proguard rules
Ex:
-dontwarn com.zl.reik.dilatingdotsprogressbar.**
-keep class com.zl.reik.dilatingdotsprogressbar.**{*;}
-keep interface com.zl.reik.dilatingdotsprogressbar.**{*;}
You even need to keep similar proguard rules for "foldingtabbar", as It is also a library
If the above solution does not solve, run ./gradlew app:dependencies in your repository and Send me the list of dependencies
Having the same version for all the support libraries is also very important. Sometimes libraries have recursive dependencies, where each has a different version which can lead to this error. Run:
./gradlew app:dependencies
to see the dependencies for each library and check whether they all have the same version. I already see, that you use 25.1.0 and 25.2.0 versions of support libraries. In addition, some of your libraries are old, thus, they probably use old versions.
Try to use:
-keep class beatbox.neelay.dummybeat.**{*;}
-dontwarn beatbox.neelay.dummybeat.**
instead of:
-keepnames beatbox.neelay.dummybeat.**{*;}
Proguard removes classes which are part of dependencies added the app. Try to keep them using:
-keep class hdodenhof.**
-keep class android.support.v4.** { *; }
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-keep class android.support.v7.internal.** { *; }
-keep interface android.support.v7.internal.** { *; }
Disable warning for dependency classes:
-dontwarn hdodenhof.**
-dontwarn android.support.v4.**
-dontwarn android.support.v7.**

Strange NoClassDefFoundError error when launching a signed release APK with proguard enabled

Some Things I have Tried:
Removing the Facebook Dependency makes the app not crash anymore but then it only shows a blank white screen. This is with proguard and multidex enabled.
Upgrading gradle to the latest version doesn't solve anything. I upgraded to gradle 2.0.0-beta4 plugin and gradle 2.10.0.
Installing a previous version of Android Studio 1.5.1 did not solve anything.
I have installed Java JDK 1.8 if this is a clue into anything. I can also post some logcat logs to see what is happening.
I am using MultiDex support in my application with Proguard enabled.
Everything works fine when I build a APK file WITHOUT proguard enabled and install that on my android phone (I have more than 8 phones so a phone is a non-issue).
When I build a release APK WITH proguard enabled it crashes on app startup after i install the app.
I get the following log messages:
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.app.n>
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.app.n>
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.app.o>
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.app.o>
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.app.r>
I/art: Rejecting re-init on previously-failed class java.lang.Class<android.support.v4.app.r>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.facebook.FacebookActivity>
I/art: Rejecting re-init on previously-failed class java.lang.Class<com.facebook.FacebookActivity>
And I see the following RuntimeException:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.mycustomapp.app, PID: 6814
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/facebook/FacebookActivity;
at com.facebook.b.aa.c(Validate.java:175)
at com.facebook.p.M(FacebookSdk.java:160)
at com.mycustomapp.app.utils.a.b.a.<init>(CustomFacebookManagerUtility.java:68)
at com.mycustomapp.app.utils.a.b.a.ct(CustomFacebookManagerUtility.java:54)
at com.mycustomapp.app.utils.application.MyCustomApplication.onCreate(MyCustomApplication.java:84)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1021)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5990)
at android.app.ActivityThread.access$1700(ActivityThread.java:205)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1756)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:6895)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.FacebookActivity" on path: DexPathList[[zip file "/data/app/com.mycustomapp.app-1/base.apk"],nativeLibraryDirectories=[/data/app/com.mycustomapp.app-1/lib/arm, /vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
at com.facebook.b.aa.c(Validate.java:175) 
at com.facebook.p.M(FacebookSdk.java:160) 
at com.mycustomapp.app.utils.a.b.a.<init>(CustomFacebookManagerUtility.java:68) 
at com.mycustomapp.app.utils.a.b.a.ct(CustomFacebookManagerUtility.java:54) 
at com.mycustomapp.app.utils.application.MyCustomApplication.onCreate(MyCustomApplication.java:84) 
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1021) 
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5990) 
at android.app.ActivityThread.access$1700(ActivityThread.java:205) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1756) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:145) 
at android.app.ActivityThread.main(ActivityThread.java:6895) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199) 
Suppressed: java.lang.NoClassDefFoundError: com.facebook.FacebookActivity
at dalvik.system.DexFile.defineClassNative(Native Method)
at dalvik.system.DexFile.defineClass(DexFile.java:226)
at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:219)
at dalvik.system.DexPathList.findClass(DexPathList.java:321)
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:54)
... 18 more
Suppressed: java.lang.ClassNotFoundException: com.facebook.FacebookActivity
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 17 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
At a loss of what could be causing this issue, but through process of elimination Proguard seems to cause some issues.
I looked at the Facebook SDK docs, and they mentioned I don't need any specific proguard rules for their Facebook SDK.
Anybody know how to solve this?
EDIT: Adding in the app's build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
classpath "com.newrelic.agent.android:agent-gradle-plugin:5.4.0"
}
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
apply plugin: 'com.neenbedankt.android-apt'
apply plugin: 'newrelic'
repositories {
maven { url 'https://maven.fabric.io/public' }
}
android {
compileSdkVersion 23
buildToolsVersion "22.0.1"
packagingOptions {
exclude 'META-INF/services/javax.annotation.processing.Processor'
exclude '.readme'
exclude 'LICENSE.txt'
exclude 'README.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/MANIFEST.MF'
}
defaultConfig {
applicationId "com.mycustomapp.app"
minSdkVersion 15
targetSdkVersion 23
versionCode 3
versionName "1.2"
/**
* Enabling multidex support.
*/
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets { main { assets.srcDirs = ['src/main/assets', 'src/main/assets/'] } }
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/gcm.jar')
/**
* For MultiDex Support
*/
compile 'com.android.support:multidex:1.0.1'
/**
* android support/compatibility libraries.
*/
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.google.android.gms:play-services-gcm:8.3.0'
/**
* facebook sdk
*/
compile 'com.facebook.android:facebook-android-sdk:4.1.0'
compile 'com.squareup.okhttp:okhttp:2.2.0'
compile 'com.squareup.okio:okio:1.1.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.jakewharton:disklrucache:2.0.2'
compile('com.crashlytics.sdk.android:crashlytics:2.5.2#aar') {
transitive = true;
}
compile 'com.amplitude:android-sdk:2.2.0'
compile 'com.appboy:android-sdk-ui:1.11.+'
compile 'joda-time:joda-time:2.3'
compile 'com.facebook.conceal:conceal:1.0.1#aar'
compile 'com.newrelic.agent.android:android-agent:5.4.0'
}
Proguard Rules:
# Obfuscation parameters:
#-dontobfuscate
-useuniqueclassmembernames
-keepattributes SourceFile,LineNumberTable
-allowaccessmodification
# Ignore warnings:
#-dontwarn org.mockito.**
#-dontwarn org.junit.**
#-dontwarn com.robotium.**
# Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
**[] $VALUES;
public *;
}
# Crashlytics
-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**
# Ignore warnings: We are not using DOM model
-dontwarn com.fasterxml.jackson.databind.ext.DOMSerializer
# Ignore warnings: https://github.com/square/okhttp/wiki/FAQs
-dontwarn com.squareup.okhttp.internal.huc.**
# Ignore warnings: https://github.com/square/okio/issues/60
-dontwarn okio.**
# Ignore warnings: https://github.com/square/retrofit/issues/435
-dontwarn com.google.appengine.api.urlfetch.**
# Keep GSON stuff
-keep class sun.misc.Unsafe { *; }
-keep class com.google.gson.** { *; }
# Keep Jackson stuff
-keep class org.codehaus.** { *; }
-keep class com.fasterxml.jackson.annotation.** { *; }
# Butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
# Keep these for GSON and Jackson
-keepattributes Signature
-keepattributes *Annotation*
-keepattributes EnclosingMethod
# Retrofit 1.X
-keep class com.squareup.okhttp.** { *; }
-keep class retrofit.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-dontwarn retrofit.**
-dontwarn rx.**
-keepclasseswithmembers class * {
#retrofit.http.* <methods>;
}
# If in your rest service interface you use methods with Callback argument.
-keepattributes Exceptions
# If your rest service methods throw custom exceptions, because you've defined an ErrorHandler.
-keepattributes Signature
# Joda Time
-dontwarn org.joda.convert.**
-dontwarn org.joda.time.**
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *; }
# Keep Picasso
-keep class com.squareup.picasso.** { *; }
-keepclasseswithmembers class * {
#com.squareup.picasso.** *;
}
-keepclassmembers class * {
#com.squareup.picasso.** *;
}
# RenderScript
-keep class android.support.v8.renderscript.** { *; }
# DBFlow
-keep class com.raizlabs.android.dbflow.config.GeneratedDatabaseHolder
# AppBoy
-dontwarn com.amazon.device.messaging.**
-dontwarn bo.app.**
-dontwarn com.appboy.ui.**
-dontwarn com.google.android.gms.**
-keep class bo.app.** { *; }
-keep class com.appboy.** { *; }
# Android Volley
# see: http://stackoverflow.com/questions/21816643/volley-seems-not-working-after-proguard-obfuscate
-keep class org.apache.commons.logging.** { *; }
WOW. It was NewRelic and KeepAttributes that was causing issues, adding the following proguard rules solved the issue:
# New Relic
-keep class com.newrelic.** { *; }
-dontwarn com.newrelic.**
-keepattributes Exceptions, Signature, InnerClasses
Maybe this is not the best answer but I hope it will help you. as far as the facebook concern when enabling the proguard, yes in the documentation there are no rules for the facebook sdk.
NOTE : I'm using skd version 4.7.0 'com.facebook.android:facebook-android-sdk:4.7.0'. and I have implement this on my project and and got no problem in it. and please try this on your project :
use buildToolsVersion "23" or latest version 23.0.2
use thid below buildToolsVersion useLibrary 'org.apache.http.legacy'
try to change your root gradle in the dependencies classpath 'com.android.tools.build:gradle:1.3.1'
and below I show you my proguard rules and my build.gradle.
hope this can fix your problem.
this is my rules :
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
-dontwarn com.squareup.okhttp.**
#
# Twitter library - start
#
-dontwarn twitter4j.**
-keep class twitter4j.** { *; }
#
# Twitter library - end
#
# adcolony start
-dontwarn com.immersion.**
-dontnote com.immersion.**
-dontwarn android.webkit.**
#adcolony end
#app billing
-keep class com.android.vending.billing.**
#end app billing
and this is my build.gradle :
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "antiboring.game"
minSdkVersion 16
targetSdkVersion 23
versionCode 11
versionName "1.9.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/services/javax.annotation.processing.Processor'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
sourceSets {
androidTest {
java.srcDirs = ['androidTest/java']
}
main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] }
}
lintOptions {
disable 'InvalidPackage'
}
}
repositories {
mavenCentral()
}
dependencies {
// App dependencies
compile 'com.android.support:support-annotations:23.1.1'
compile 'com.google.guava:guava:18.0'
//unit testing
androidTestCompile 'com.android.support:support-annotations:23.1.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
//apps library
compile files('libs/twitter4j-core-4.0.2.jar')
compile fileTree(dir: 'libs', include: ['adcolony.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:palette-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.balysv.materialmenu:material-menu-toolbar:1.5.4'
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.jakewharton:butterknife:7.0.1'
compile 'com.squareup.picasso:picasso:2.5.2'
//social media
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
//animation
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.easing:library:1.0.1#aar'
compile 'com.daimajia.androidanimations:library:1.1.3#aar'
}

Instabug Proguard issue

I have a problem including instabug library in an obfuscated project (all other third party libraries are ok).
The error I get is following ( I know there have been other question about this error message, but my problem appears only with instabug, and none of the proposed solutions work for it ).
Error:Execution failed for task ':app:packageRelease'.
Unable to compute hash of C:\Projects\ProguardExample\app\build\intermediates\classes-proguard\release\classes.jar
I have added some statements to my configuration file when trying to solve the problem.
-dontwarn android.support.**
-keep class android.support.v7.** { *; }
-keep interface android.support.v7.** { *; }
-keep class com.google.android.gms.** { *; }
-dontwarn com.google.android.gms.**
-keep class com.instabug.** { *; }
// here I tried also to change the proguard-project.txt
and to my proguard-rules.pro
-dontwarn java.nio.file.Files
-dontwarn java.nio.file.Path
-dontwarn java.nio.file.OpenOption
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Here is how my build.gradle looks like.
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.config
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:appcompat-v7:23.0.1'
//compile 'com.github.danieltwagner:android-async-logger:0.1.0#aar'
compile 'com.instabug.library:instabugsupport:1+'
// compile 'org.apache.commons:commons-collections4:4.0'
}
I would be very thankful if you could guide me towards solving this problem. Even if you don't know its solution, but suspect in which area, should I research to find it, please share with me :)
The guys from instabug helped me out via email. So here is the solution (that totally works for me) - add those statements to you proguard-rules.pro
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn com.google.android.gms.**
-dontwarn com.android.volley.toolbox.**
-dontwarn com.instabug.**

Unable to build APK due to proguard error

When I set minifyEnabled to true in build.gradle, I get the following error when trying to build my signed APK:
Error:Execution failed for task ':app:packageRelease'.
> Unable to compute hash of .../app/build/intermediates/classes-proguard/release/classes.jar
I am not sure why this is happening. Any help appreciated.
You are adding proguard rules for 3rd party libraries, right?
For example for ButterKnife you have to add this to proguard file:
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
Solved this by adding the following to my build.gradle:
android {
useLibrary 'org.apache.http.legacy'
}
More here: https://developer.android.com/about/versions/marshmallow/android-6.0-changes.html#behavior-apache-http-client

Can I write some of the code in Scala (using AndroidStudio)?

I'm using AndroidStudio, and I want to stick to using it because it's the official IDE.
All I want to do is to be able to write some classes in Scala, sounds reasonable to me.
However, all I could find online is a way to create a new project using SBT (+ Android plugins and idea plugin) then load it in AndroidStudio. Of course, I had to deal with all the strange errors and the like until I finally made it compile and run on the emulator. But then I tried to add a fragment drawer and again I ran into problem because I need to add some extra Android libraries and I have no clue to do that.
The sane approach should be to use AndroidStudio as it is (because it's the official IDE) and be able to add Scala files somehow that then get compiled into java bytecode then get treated like normal Java code by the Android compiler. Is there a way to do that?
I use Scala and Gradle (yeah, I know Gradle is written in Groovy). It's a pain to get set up at first, but I like Scala a lot, so it is worth it.
To do it you will need to rely on a groovy plugin. Here is what you do:
1. Add classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.3.1" to your top-level gradle file like so (also work around the problem with proguard):
build.gradle (top-level):
buildscript {
repositories {
mavenLocal() // Remove this if your repository is not local
jcenter()
}
dependencies {
classpath "com.android.tools.build:gradle:1.0.0"
classpath "jp.leafytree.gradle:gradle-android-scala-plugin:1.3.1"
// Default version of proguard v4.8 (?) and v5.1 fail with ArrayIndexOutOfBoundsException: 4
classpath ('net.sf.proguard:proguard-gradle:5.0') {
force = true
}
...
2. Apply your plugins and set the Scala dependency in the module, like "app" or "wear", level gradle file:
build.gradle (module-level):
...
apply plugin: "jp.leafytree.android-scala"
android {
...
buildTypes {
release {
debuggable false
minifyEnabled true
...
debug {
debuggable true
minifyEnabled true
...
}
dependencies {
...
compile 'org.scala-lang:scala-library:2.11.4'
}
3. Make sure you are using Proguard (Scala code has to be minified to work with Android). Here is the main proguard file I use--you will want to change that "keep public class" line at the top to match your project domain:
proguard-rules.pro:
-dontpreverify
-dontskipnonpubliclibraryclasses
-dontskipnonpubliclibraryclassmembers
-dontusemixedcaseclassnames
# ----
-dontoptimize
# ----
-keep public class com.keithpinson.** { public protected *; }
##
## SCALA SETTINGS
##
-dontwarn scala.**
-dontnote scala.Enumeration
-ignorewarnings
# temporary workaround; see Scala issue SI-5397
-keep class scala.collection.SeqLike {
public protected *;
}
-keep class scala.math.ordering { *; }
-keep class scala.Function1 { *; }
-keep class scala.Function2 { *; }
##
## ANDROID SETTINGS
##
-keep class android.support.v13.** { *; }
-keep interface android.support.v13.** { *; }
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet);
}
-keepclasseswithmembers class * {
public <init>(android.content.Context, android.util.AttributeSet, int);
}
-keepclassmembers class * extends android.app.Activity {
public void *(android.view.View);
}
-keepclassmembers enum * {
public static **[] values();
public static ** valueOf(java.lang.String);
}
-keep class * implements android.os.Parcelable {
public static final android.os.Parcelable$Creator *;
}
# Joda Time 2.3
-keep class org.joda.time.** { *; }
-keep interface org.joda.time.** { *; }
If I haven't forgotten something and Gradle is downloading the leafytree plugin and if you have the right versions of Scala and Android, it should work fine.

Categories

Resources