Gradle Build Failure - android

My project compiles and executes well on debug mode but when i try to generate a signed apk, errors arise. This appears on the message log:
:app:proguardRelease
Warning:android.support.v4.app.DialogFragment: can't find referenced class android.support.v4.app.DialogFragment$DialogStyle
Warning:android.support.v4.app.FragmentTransaction: can't find referenced class android.support.v4.app.FragmentTransaction$Transit
Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ResolvedLayoutDirectionMode
Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayoutDirectionMode
Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$LayerType
Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$AccessibilityLiveRegion
Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$ImportantForAccessibility
Warning:android.support.v4.view.ViewCompat: can't find referenced class android.support.v4.view.ViewCompat$OverScroll
Warning:android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$EdgeGravity
Warning:android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$LockMode
Warning:android.support.v4.widget.DrawerLayout: can't find referenced class android.support.v4.widget.DrawerLayout$State
Warning:there were 11 unresolved references to classes or interfaces.
You may need to add missing library jars or update their versions.
If your code works fine without the missing classes, you can suppress
the warnings with '-dontwarn' options.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Exception while processing task
java.io.IOException: Please correct the above warnings first.
at proguard.Initializer.execute(Initializer.java:473)
at proguard.ProGuard.initialize(ProGuard.java:233)
at proguard.ProGuard.execute(ProGuard.java:98)
at proguard.gradle.ProGuardTask.proguard(ProGuardTask.java:1074)
at com.android.build.gradle.tasks.AndroidProGuardTask.doMinification(AndroidProGuardTask.java:139)
at com.android.build.gradle.tasks.AndroidProGuardTask$1.run(AndroidProGuardTask.java:115)
at com.android.builder.tasks.Job.runTask(Job.java:48)
at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:227)
at java.lang.Thread.run(Thread.java:745)
:app:dexRelease UP-TO-DATE
:app:crashlyticsStoreDeobsRelease
:app:crashlyticsUploadDeobsRelease
:app:validateExternalOverrideSigning
:app:packageRelease FAILED
Error:Execution failed for task ':app:packageRelease'.
> Unable to compute hash of /home/kombo/RAL/Mpasho/app/build/intermediates/classes-proguard/release/classes.jar
I have tried every possible way of remedying this by updating my build tools, using the latest gradle version, checking all the dependencies and the error still shows up.
I am pretty sure the v4 support library is present in the project since no errors arise in debug mode.

I also had this issue when upgrading everything that is built related to 23 (Android Libraries, SDK etc).
This proguard configuration fixed it for me:
-dontwarn org.apache.http.**
-dontwarn android.net.http.AndroidHttpClient
-dontwarn com.google.android.gms.**
-dontwarn com.android.volley.toolbox.**
Source

Turns out I had omitted the getDefaultProguardFile('proguard-android.txt') line on the proguard files and was just using proguard-rules.pro

added these two line in progaurd
-dontwarn android.net.http.AndroidHttpClient
-dontwarn com.google.android.gms.**
and it works..
It is related to library used in project.

The default ProGuard file already has a rule to ignore support library warnings. If you don't have it you can add to your file
-dontwarn android.support.**
but would be better to add the default one. See Proguard configuration#Android Developers

This also could happen due to errors/warnings related to included .jar files
Check in build output for proguard warnings/errors.
I had issue related to opencsv jar file. Hint by Lakedaemon in above comment helped me and its solved.

Try to look up in the whole error message. It may contain info that you include a library twice. This was the problem in my case and it was fixed after removing duplicated includes.

Try add this code in your proguard-rules.pro:
-ignorewarnings
It solved my problem.

I think your app build.gradle buildTypes > release > minifyEnabled is true
That cause you get this error message.
Avoid this error message, set buildTypes > release > minifyEnabled is false
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

Related

Databinding issues on building app for release

I'm trying to run an app ono release mode in my mobile. After click on run my message log is filled with these errors:
Warning:android.databinding.DataBindingUtil: can't find referenced class android.databinding.DataBinderMapper
Warning:android.databinding.DataBindingUtil: can't find referenced class android.databinding.DataBindingComponent
Warning:android.databinding.ViewDataBinding: can't find referenced class android.databinding.DataBinderMapper
Warning:android.databinding.ViewDataBinding: can't find referenced class android.databinding.DataBindingComponent
Warning:android.databinding.ViewDataBinding: can't find referenced class android.databinding.DataBinderMapper
Warning:android.databinding.ViewDataBinding: can't find referenced class android.databinding.DataBindingComponent
Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:there were 46 unresolved references to classes or interfaces.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForStageRelease'.
> Job failed, see logs for details
This is some part of my build.gradle
buildTypes {
release {
debuggable false
minifyEnabled true
zipAlignEnabled true
shrinkResources true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.bom
pseudoLocalesEnabled false
}
debug {
debuggable true
}
}
Inserting dataBinding{enabled true } in the release part the errors drops to about 3.
Information:Gradle tasks [:app:assembleStageRelease]
Warning:okio.DeflaterSink: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:okio.Okio: can't find referenced class org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
Warning:there were 3 unresolved references to classes or interfaces.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForStageRelease'.
> Job failed, see logs for details
Is there a reason for this?
Your build is failing due to warnings from ProGuard. These aren't always blocking, and you can add a -dontwarn line to Proguard to get around them. The best thing to do is find which libraries the affected code is in, and find documentation from the library for what ProGuard rules are safe to add.

How to use ProGuard in Library Module

I want to enable ProGuard in library module but getting compilation error that package does not exists. Why package not exists after apply ProGuard in library module?
library module build.gradle
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
Log Error
/home/hitesh/Documents/Android Studio Project/ALPR-Sample/app/src/main/java/com/alpr/sample/GalleryActivity.java
Error:(15, 32) error: package com.alprlib.alpr.doc does not exist
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
here doc class file exist in library module
ProGuard file rules
-keep class com.alprlib.alpr.** { *; }
-keepclassmembers class alprlib.alpr.** {*;}
It makes sense to me to specify proguard settings for a library (like which library files shouldn't be obfuscated) in the library project. I've found that I also need to include proguard configurations from my library modules in my application. To do this, I added the following to the defaultConfig section in my library's build.gradle
consumerProguardFiles 'proguard-rules.pro'
and then configured the proguard-rules.pro file in my library module to keep the names of important serialized classes.
See also consumerProguardFiles
Please see this post:
https://stackoverflow.com/a/48636288/8770663
you can write on your proguard file -
-keep public class * extends android.app.Activity
Or what ever class you want to keep.
Have a look on this - https://www.guardsquare.com/en/proguard/manual/examples

After exclude module 'answer-shim' in the android gradle for io.branch.sdk couldn't build with proguard

When try to build the release build with proguard enable getting below warning and couldn't build the APK successfully.
Warning:io.branch.referral.ExtendedAnswerProvider: can't find referenced class com.crashlytics.android.answers.shim.KitEvent
Warning:io.branch.referral.ExtendedAnswerProvider: can't find referenced class com.crashlytics.android.answers.shim.AnswersOptionalLogger
Warning:io.branch.referral.ExtendedAnswerProvider: can't find referenced class com.crashlytics.android.answers.shim.KitEventLogger
Warning:io.branch.referral.ExtendedAnswerProvider: can't find referenced class com.crashlytics.android.answers.shim.AnswersOptionalLogger
Warning:io.branch.referral.ExtendedAnswerProvider: can't find referenced class com.crashlytics.android.answers.shim.KitEventLogger
Warning:io.branch.referral.ExtendedAnswerProvider: can't find referenced class com.crashlytics.android.answers.shim.KitEvent
Warning:there were 14 unresolved references to classes or interfaces.
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
Error:java.lang.RuntimeException: Job failed, see logs for details
Error:java.io.IOException: Please correct the above warnings first.
add
-dontwarn com.crashlytics.android.answers.shim.**
to the proguard file
If you want to exclude Crashlytics from Proguard you can use these 2 lines
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
Check out Fabric's Proguard page

ProGuard error trying to generate signed apk

This is my log. the problem happens when I try to generate signed apk:
Initializing...
Note: the configuration refers to the unknown class 'com.sourcey.example.SignupActivity'
Note: com.google.android.gms.internal.zzro calls 'Field.getType'
Note: butterknife.internal.ViewInjector calls 'Class.getEnclosingClass'
Warning:com.google.android.gms.common.GooglePlayServicesUtil: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification
Warning:com.google.android.gms.gcm.zza: can't find referenced method 'void setLatestEventInfo(android.content.Context,java.lang.CharSequence,java.lang.CharSequence,android.app.PendingIntent)' in library class android.app.Notification
Note: com.google.android.gms.maps.internal.zzy: can't find dynamically referenced class com.google.android.gms.maps.internal.CreatorImplGmm6
Note: com.google.android.gms.maps.internal.zzy: can't find dynamically referenced class com.google.android.gms.maps.internal.CreatorImpl
Note: org.apache.james.mime4j.storage.DefaultStorageProvider calls '(org.apache.james.mime4j.storage.StorageProvider)Class.forName(variable).newInstance()'
Note: there were 1 references to unknown classes.
You should check your configuration for typos.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: there were 1 classes trying to access generic signatures using reflection.
You should consider keeping the signature attributes
(using '-keepattributes Signature').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 1 classes trying to access enclosing classes using reflection.
You should consider keeping the inner classes attributes
(using '-keepattributes InnerClasses').
(http://proguard.sourceforge.net/manual/troubleshooting.html#attributes)
Note: there were 2 unresolved dynamic references to classes or interfaces.
You should check if you need to specify additional program jars.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Note: there were 1 class casts of dynamically created class instances.
You might consider explicitly keeping the mentioned classes and/or
their implementations (using '-keep').
(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclasscast)
Warning:there were 2 unresolved references to library class members.
You probably need to update the library versions.
(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedlibraryclassmember)
Warning:Exception while processing task java.io.IOException: Please correct the above warnings first.
:app:transformClassesAndResourcesWithProguardForRelease FAILED
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Please correct the above warnings first.
Information:BUILD FAILED
Information:Total time: 22.714 secs
Information:1 error
Information:4 warnings
Information:See complete output in console
My module build.grade:
defaultConfig {
applicationId "com.sourcey.example"
minSdkVersion 15
//targetSdkVersion 22
targetSdkVersion 23
versionCode 28
versionName "3.0.2.1"
signingConfig signingConfigs.config
}
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
May be the problem is the warnings but I don't know
My project build.gradle:
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Finally, my proguard-rules.pro:
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { #butterknife.InjectView *;}
-dontwarn butterknife.Views$InjectViewProcessor
-dontwarn com.gc.materialdesign.views.**
-dontwarn com.kosalgeek.**
-dontwarn org.apache.**
-dontwarn android.support.v4.**
Thanks for helping me!
Thanks a lot
You have 2 warnings originating from Google GMS services. To ignore them use the following configuration:
-dontwarn com.google.android.gms.**
There are also a few more notes that you should also take into account:
-keepattributes Signature,InnerClasses
The remaining notes are more or less harmless, but you may want to ignore them with appropriate -dontnote configurations.

build tools 21.1.1 proguard not recognizing `-keep` and rules

Warning:library class org.apache.http.conn.ManagedClientConnection extends or implements program class org.apache.http.HttpClientConnection
despite having -dontwarn org.apache.** in my proguard rules file
Warning:org.joda.time.Weeks: can't find referenced class org.joda.convert.FromString
despite having -dontwarn org.joda.** in my proguard rules file, and -keep class org.** { *; } along with -keep interface org.** { *; }
Warning:there were 140 instances of library classes depending on program classes.
Error:Execution failed for task ':app:proguardRelease'.
> java.io.IOException: Please correct the above warnings first.
so then I look at my app structure
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-project.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
zipAlignEnabled true
}
}
proguard-project.txt is in the same folder as this build.gradle file in this module.
Not sure what is broken now, I guess there is something else that nobody told me about when I was required to update to Build Tools 21.1.1 to make other things work. any insight appreciated.
My solution was to copy all of my rules into proguard-rules.pro which the IDE had previously automatically generated for me, and then proguard worked as expected
I still don't know where getDefaultProguardFile('proguard-project.txt') is supposed to be located, but it is not being read, I moved it within my module and in the root folder of the project.

Categories

Resources