Skip to content

Android build is failed after set the enableProguardInReleaseBuilds to true #21638

Description

@hamidhadi

Environment

React Native Environment Info:
Binaries:
Node: 8.10.0
Yarn: 1.3.2
npm: 5.6.0
Watchman: 4.7.0
SDKs:
iOS SDK:
Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
Android SDK:
Build Tools: 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.0, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.1, 27.0.3
API Levels: 17, 20, 21, 23, 25, 26, 27
npmPackages:
react: 16.5.0 => 16.5.0
react-native: 0.57.1 => 0.57.1
npmGlobalPackages:
react-native-git-upgrade: 0.2.7

Description

I want to use ProGuard in my project so I enabled it by setting enableProguardInReleaseBuilds to true in build.gradle.
After trying to run assembleRelease task on AndroidStudio I get this error

Note: therewere11duplicateclassdefinitions.(http://proguard.sourceforge.net/manual/troubleshooting.html#duplicateclass)Initializing...Note: theconfigurationreferstotheunknownclass'com.facebook.react.ReactInstanceManagerImpl'
Note: theconfigurationreferstotheunknownclass'com.facebook.react.XReactInstanceManagerImpl'
Note: theconfigurationreferstotheunknownclass'com.google.android.gms.common.api.internal.BasePendingResult.ReleasableResultGuardian'
Note: theconfigurationreferstotheunknownclass'com.facebook.react.uimanager.UIProp'
Note: theconfigurationreferstotheunknownclass'sun.misc.Unsafe'
Note: theconfigurationreferstotheunknownclass'com.google.android.gms.common.internal.safeparcel.SafeParcelable'Warning: com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactoryImpl: can't find superclass or interface com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedImageFactoryImpl: can't find superclass or interface com.facebook.imagepipeline.animated.factory.AnimatedImageFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedImageFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedImageFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedImageFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedDrawableFactory
Warning: com.facebook.imagepipeline.animated.factory.AnimatedImageFactoryImpl: can't find referenced class com.facebook.imagepipeline.animated.factory.AnimatedImageFactory
Warning: com.facebook.imagepipeline.nativecode.StaticWebpNativeLoader: can't find referenced class com.facebook.common.soloader.SoLoaderShim
Warning: com.facebook.imagepipeline.nativecode.StaticWebpNativeLoader: can't find referenced class com.facebook.common.soloader.SoLoaderShim

and at the end I get this error

Note: therewere6referencestounknownclasses.Youshouldcheckyourconfigurationfortypos.(http://proguard.sourceforge.net/manual/troubleshooting.html#unknownclass)
Note: therewere1referencestounknownclassmembers.Youshouldcheckyourconfigurationfortypos.Note: therewere817unkeptdescriptorclassesinkeptclassmembers.Youshouldconsiderexplicitlykeepingthementionedclasses(using'-keep').(http://proguard.sourceforge.net/manual/troubleshooting.html#descriptorclass)
Note: therewere18unresolveddynamicreferencestoclassesorinterfaces.Youshouldcheckifyouneedtospecifyadditionalprogramjars.(http://proguard.sourceforge.net/manual/troubleshooting.html#dynamicalclass)
Warning: therewere13unresolvedreferencestoclassesorinterfaces.Youmayneedtoaddmissinglibraryjarsorupdatetheirversions.Ifyourcodeworksfinewithoutthemissingclasses,youcansuppressthewarningswith'-dontwarn'options.(http://proguard.sourceforge.net/manual/troubleshooting.html#unresolvedclass)
Warning: Exceptionwhileprocessingtaskjava.io.IOException: Pleasecorrecttheabovewarningsfirst.Thread(Taskslimiter_1): destruction
:app:transformClassesAndResourcesWithProguardForReleaseFAILED
FAILURE: Buildfailedwithanexception.*Whatwentwrong:
Executionfailedfortask':app:transformClassesAndResourcesWithProguardForRelease'.>Jobfailed,seelogsfordetails*Try:
Runwith--stacktraceoptiontogetthestacktrace.Runwith--infoor--debugoptiontogetmorelogoutput.Runwith--scantogetfullinsights.*Getmorehelpathttps://help.gradle.orgBUILDFAILEDin4m46s280actionable tasks: 8executed,272up-to-date12:33:16: Taskexecutionfinished'assembleRelease'.

Here is my proguard-rules:

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/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 *;
#}
-dontwarn com.microsoft.appcenter.push.**

Reproducible Demo

I just set enableProguardInReleaseBuilds to true and this issue appears.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions