title: Android Gradle Plugin warnings when building the release APK
body: <p>I'm getting the following Android Gradle Plugin warnings when I try to build the release APK from Android Studio:</p>
  
  <pre><code>library class android.content.res.XmlResourceParser extends or implements program class org.xmlpull.v1.XmlPullParser    
  library class android.content.Intent depends on program class org.xmlpull.v1.XmlPullParser  
  library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlSerializer    
  library class android.content.IntentFilter depends on program class org.xmlpull.v1.XmlPullParser    
  library class android.content.res.ColorStateList depends on program class org.xmlpull.v1.XmlPullParser  
  library class android.graphics.drawable.AnimatedVectorDrawable depends on program class org.xmlpull.v1.XmlPullParser    
  library class android.graphics.drawable.AnimationDrawable depends on program class org.xmlpull.v1.XmlPullParser 
  library class android.graphics.drawable.BitmapDrawable depends on program class org.xmlpull.v1.XmlPullParser    
  library class android.graphics.drawable.ClipDrawable depends on program class org.xmlpull.v1.XmlPullParser  
  library class android.graphics.drawable.ColorDrawable depends on program class org.xmlpull.v1.XmlPullParser 
  library class android.graphics.drawable.Drawable depends on program class org.xmlpull.v1.XmlPullParser  
  library class android.graphics.drawable.DrawableWrapper depends on program class org.xmlpull.v1.XmlPullParser   
  library class android.graphics.drawable.GradientDrawable depends on program class org.xmlpull.v1.XmlPullParser  
  library class android.graphics.drawable.InsetDrawable depends on program class org.xmlpull.v1.XmlPullParser 
  library class android.graphics.drawable.LayerDrawable depends on program class org.xmlpull.v1.XmlPullParser 
  library class android.graphics.drawable.RippleDrawable depends on program class org.xmlpull.v1.XmlPullParser    
  library class android.graphics.drawable.ScaleDrawable depends on program class org.xmlpull.v1.XmlPullParser 
  library class android.graphics.drawable.ShapeDrawable depends on program class org.xmlpull.v1.XmlPullParser 
  library class android.graphics.drawable.StateListDrawable depends on program class org.xmlpull.v1.XmlPullParser 
  library class android.graphics.drawable.VectorDrawable depends on program class org.xmlpull.v1.XmlPullParser    
  library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser    
  library class android.util.Xml depends on program class org.xmlpull.v1.XmlSerializer    
  library class android.util.Xml depends on program class org.xmlpull.v1.XmlPullParser    
  library class android.view.LayoutInflater depends on program class org.xmlpull.v1.XmlPullParser 
  there were 32 instances of library classes depending on program classes.    
  Exception while processing task java.io.IOException: Please correct the above warnings first.   
  </code></pre>
  
  <p><strong>Here is the build error:</strong></p>
  
  <pre><code>org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:103)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:73)
      at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
      at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:59)
      at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
      at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:59)
      at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:101)
      at org.gradle.api.internal.tasks.execution.FinalizeInputFilePropertiesTaskExecuter.execute(FinalizeInputFilePropertiesTaskExecuter.java:44)
      at org.gradle.api.internal.tasks.execution.CleanupStaleOutputsExecuter.execute(CleanupStaleOutputsExecuter.java:91)
      at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:62)
      at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:59)
      at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
      at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
      at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.run(DefaultTaskGraphExecuter.java:256)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:249)
      at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:238)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.processTask(DefaultTaskPlanExecutor.java:123)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.access$200(DefaultTaskPlanExecutor.java:79)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:104)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker$1.execute(DefaultTaskPlanExecutor.java:98)
      at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.execute(DefaultTaskExecutionPlan.java:663)
      at org.gradle.execution.taskgraph.DefaultTaskExecutionPlan.executeWithTask(DefaultTaskExecutionPlan.java:597)
      at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$TaskExecutorWorker.run(DefaultTaskPlanExecutor.java:98)
      at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
      at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.RuntimeException: Job failed, see logs for details
      at com.android.build.gradle.internal.transforms.ProGuardTransform.transform(ProGuardTransform.java:207)
      at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:239)
      at com.android.build.gradle.internal.pipeline.TransformTask$2.call(TransformTask.java:235)
      at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:102)
      at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:230)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
      at org.gradle.api.internal.project.taskfactory.IncrementalTaskAction.doExecute(IncrementalTaskAction.java:50)
      at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:39)
      at org.gradle.api.internal.project.taskfactory.StandardTaskAction.execute(StandardTaskAction.java:26)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$1.run(ExecuteActionsTaskExecuter.java:124)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:336)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor$RunnableBuildOperationWorker.execute(DefaultBuildOperationExecutor.java:328)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.execute(DefaultBuildOperationExecutor.java:199)
      at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:110)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:113)
      at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:95)
      ... 33 more
  Caused by: java.io.IOException: Please correct the above warnings first.
      at proguard.Initializer.execute(Initializer.java:485)
      at proguard.ProGuard.initialize(ProGuard.java:271)
      at proguard.ProGuard.execute(ProGuard.java:113)
      at com.android.build.gradle.internal.transforms.BaseProguardAction.runProguard(BaseProguardAction.java:64)
      at com.android.build.gradle.internal.transforms.ProGuardTransform.doMinification(ProGuardTransform.java:262)
      at com.android.build.gradle.internal.transforms.ProGuardTransform.access$000(ProGuardTransform.java:65)
      at com.android.build.gradle.internal.transforms.ProGuardTransform$1.run(ProGuardTransform.java:176)
      at com.android.builder.tasks.Job.runTask(Job.java:47)
      at com.android.build.gradle.tasks.SimpleWorkQueue$EmptyThreadContext.runTask(SimpleWorkQueue.java:41)
      at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:282)
      ... 1 more
  </code></pre>
  
  <p>I'm unable to create the release APK as a result of these errors. But I'm able to test my app and also create the debug APK successfully. I then tried to create the release APK of the OLD version of my code which worked without any issues back then, but I'm still getting the same errors.</p>
  
  <p><strong>Here's my build.gradle (app) file:</strong> </p>
  
  <pre><code>apply plugin: 'com.android.application'
  
  android {
      compileSdkVersion 28
      defaultConfig {
          applicationId "com.cg.lrceditor"
          minSdkVersion 21
          targetSdkVersion 28
          versionCode 24
          versionName "2.2.3"
          testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
          vectorDrawables.useSupportLibrary = true
      }
      buildTypes {
          release {
              shrinkResources true
              minifyEnabled true
  
              proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
          }
          debug {
              minifyEnabled false
              proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
          }
      }
      productFlavors {
      }
  }
  
  dependencies {
      implementation fileTree(include: ['*.jar'], dir: 'libs')
      implementation 'com.android.support:appcompat-v7:28.0.0'
      implementation 'com.android.support:design:28.0.0'
      implementation 'com.android.billingclient:billing:1.1'
      testImplementation 'junit:junit:4.12'
      implementation 'com.android.support.test:runner:1.0.2'
      androidTestImplementation 'org.testng:testng:6.9.6'
  }
  </code></pre>
  
  <p>Not sure why, but if I set both <code>minifyEnabled</code> and <code>shrinkResources</code> to false, I am able to create the release APK successfully. But then the app size won't be optimized.</p>
  
  <p>I've tried ignoring the warnings using <code>-dontwarn org.xmlpull.v1.**</code> or <code>-ignorewarnings</code> in <code>proguard-rules.pro</code> and I'm able to generate the release APK, but then when I launch the app, it crashes. Here's the relevant stack trace of the crash:</p>
  
  <pre><code>2019-03-26 10:46:28.413 19982-19982/? E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.cg.lrceditor, PID: 19982
      java.lang.NoSuchMethodError: No static method asAttributeSet(Lorg/a/a/a;)Landroid/util/AttributeSet; in class Landroid/util/Xml; or its super classes (declaration of 'android.util.Xml' appears in /system/framework/framework.jar:classes2.dex)
          at android.support.v7.view.g.inflate(SupportMenuInflater.java:125)
          at com.cg.lrceditor.HomePage.onCreateOptionsMenu(HomePage.java:294)
          at android.app.Activity.onCreatePanelMenu(Activity.java:3315)
          at android.support.v4.app.h.onCreatePanelMenu(FragmentActivity.java:364)
          at android.support.v7.view.i.onCreatePanelMenu(WindowCallbackWrapper.java:93)
          at android.support.v7.app.f$a.onCreatePanelMenu(AppCompatDelegateImplBase.java:332)
          at android.support.v7.view.i.onCreatePanelMenu(WindowCallbackWrapper.java:93)
          at android.support.v7.app.m$1.run(ToolbarActionBar.java:1454)
          at android.os.Handler.handleCallback(Handler.java:754)
          at android.os.Handler.dispatchMessage(Handler.java:95)
          at android.os.Looper.loop(Looper.java:163)
          at android.app.ActivityThread.main(ActivityThread.java:6238)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
  </code></pre>
  
  <p><code>HomePage.java:294</code> is <code>getMenuInflater().inflate(R.menu.menu_home_page, menu);</code>.</p>
  
  <hr>
  
  <p>How do I fix these issues with <code>minifyEnabled</code> and <code>shrinkResources</code> on?</p>