New issue
Advanced search Search tips

Issue 716143 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: May 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 2
Type: Bug


Participants' hotlists:
Hotlist-1


Sign in to add a comment

ClassNotFound exception with multidex on pre 21 android

Reported by patterso...@gmail.com, Apr 27 2017

Issue description

Steps to reproduce the problem:
1. Go over the 64k method limit
2. Build with multidex using a pre 21 android device
3. 

What is the expected behavior?
Not to crash on start up

What went wrong?
Crashes on start up due to ClassNotFoundExceptions.

Did this work before? N/A 

Does this work in other browsers? Yes

Chrome version: 54.0.2840.9  Channel: stable
OS Version: 20 and below
Flash Version:
 
Hello,

Currently I am developing off of the chromium open source project.  We added some library sdks and now the app is hitting the 64k method limit, even with proguard enabled.  Unfortunetly the multidexing support library (API < 21) causes the app to crash on start up due to ClassNotFoundExceptions.  We are currently building off of chromium version 54.0.2840.9.  I am aware of another similar issue that was solved https://bugs.chromium.org/p/chromium/issues/detail?id=712852#makechanges, although this was for chromes public test apks.  Is this a possible solution to my problem, or perhaps proguard needs to be fixed.

Our current proguard flags are below just in case.

<---release_proguard_config.flags--->

# Allows Proguard freedom in removing these log related calls. We ask for debug
# and verbose logs to be stripped out in base.Log, so we are just ensuring we
# get rid of all other debug/verbose logs.
-assumenosideeffects class android.util.Log {
  static *** d(...);
  static *** v(...);
  static *** isLoggable(...);
}

# The following chart was created on July 20, 2016, to decide on 3 optimization
# passes for Chrome.
# optimization passes | time | .dex size | dirty memory per process
# -----------------------------------------------------------------
#          1          | 0:48 |  5805676  |         488972
#          2          | 1:07 |  5777376  |         487092
#          3          | 1:24 |  5772192  |         486596
#          4          | 1:42 |  5771124  |         486484
#          5          | 1:56 |  5770504  |         486432
-optimizationpasses 3

# Class merging messes up stacktraces beyond the point of them being
# deobfuscatable. If turned on, it would give us a 2% reduction in .dex size.
-optimizations !class/merging/*

# Allowing Proguard to change modifiers. This change shrinks the .dex size by
# ~1%, and reduces the method count by ~4%.
-allowaccessmodification

# The support library contains references to newer platform versions.
# Don't warn about those in case this app is linking against an older
# platform version.  We know about them, and they are safe.
-dontwarn android.support.**

<-- base_proguard_config.flags -->
# Keep line number information, useful for stack traces.
-keepattributes SourceFile,LineNumberTable

# Keep all annotation related attributes that can affect runtime
-keepattributes RuntimeVisible*Annotations
-keepattributes AnnotationDefault

# Keep the annotations, because if we don't, the ProGuard rules that use them
# will not be respected. These classes then show up in our final dex, which we
# do not want - see crbug.com/628226.
-keep @interface org.chromium.base.annotations.AccessedByNative
-keep @interface org.chromium.base.annotations.CalledByNative
-keep @interface org.chromium.base.annotations.CalledByNativeUnchecked
-keep @interface org.chromium.base.annotations.RemovableInRelease
-keep @interface org.chromium.base.annotations.UsedByReflection

# Keeps for class level annotations.
-keep @org.chromium.base.annotations.UsedByReflection class *

# Keeps for method level annotations.
-keepclassmembers class * {
  @android.webkit.JavascriptInterface <methods>;
}
-keepclasseswithmembers class * {
  @org.chromium.base.annotations.AccessedByNative <fields>;
}
-keepclasseswithmembers,includedescriptorclasses class * {
  @org.chromium.base.annotations.CalledByNative <methods>;
}
-keepclasseswithmembers,includedescriptorclasses class * {
  @org.chromium.base.annotations.CalledByNativeUnchecked <methods>;
}
-keepclasseswithmembers class * {
  @org.chromium.base.annotations.UsedByReflection <methods>;
}
-keepclasseswithmembers,includedescriptorclasses class * {
  native <methods>;
}

# Keep all CREATOR fields within Parcelable that are kept.
-keepclassmembers class * implements android.os.Parcelable {
  public static *** CREATOR;
}

# Don't obfuscate Parcelables as they might be marshalled outside Chrome.
-keepnames class * implements android.os.Parcelable

# Keep all Parcelables, since Play Services has some that are used only by
# reflection.
# TODO(agrieve): Remove this once proguard flags provided by play services via
#     .aars are used.   https://crbug.com/640836 
-keep class * implements android.os.Parcelable

# Remove methods annotated with this if their return value is unused
-assumenosideeffects class ** {
  @org.chromium.base.annotations.RemovableInRelease <methods>;
}

# Keep all enum values and valueOf methods. See
# http://proguard.sourceforge.net/index.html#manual/examples.html
# for the reason for this. Also, see http://crbug.com/248037.
-keepclassmembers enum * {
    public static **[] values();
}

<--proguard1.flags -->
# As of August 11, 2016, obfuscation was tested and passed on the trybots,
# saving us 660kb on our .dex size and 53kb memory/process. Enable obfuscation
# as soon as Crash supports ReTrace's deobfuscation of stack traces.
#
# To enable obfuscation, remove the -keepnames rule for
# com.google.android.apps.chrome.** and org.chromium.**, and uncomment the
# following two lines:
# -renamesourcefileattribute PG
# -repackageclasses ""

# Disable obfuscation for the following two packages.
-keepnames,allowoptimization class com.google.android.apps.chrome.**,org.chromium.** {
  *;
}

# Fragments are loaded using reflection via Fragment.instantiate(Context,String)
# This can be improved upon - see  crbug.com/622023 .
-keep public class com.google.android.apps.chrome** extends android.app.Fragment
-keep public class org.chromium** extends android.app.Fragment

# These classes aren't themselves referenced, but __ProcessService[0,1,2...] are
# referenced, and we look up these services by appending a number onto the name
# of the base class. Thus, we need to keep the base class name around so that
# the child classes can be looked up.
-keep class org.chromium.content.app.SandboxedProcessService
-keep class org.chromium.content.app.PrivilegedProcessService

# SearchView is used in website_preferences_menu.xml and is constructed by
# Android using reflection.
-keep class android.support.v7.widget.SearchView {
  public <init>(...);
}

# Google Play Services warnings are about its resources.
-dontwarn com.google.android.gms.R**

<--proguard2.flags-->
-verbose

# Disable obfuscation for the following two packages.
-keep class com.** {
  *;
}
-keep class org.** {
  *;
}

-keep class com.apptimize.** { *; }

-keepclassmembers class * {
    @com.browser.inject.** *;
}

-keepclassmembers class * extends com.apptimize.ApptimizeTest {
    <methods>;
}

-keepattributes *Annotation*
-dontskipnonpubliclibraryclassmembers
-dontwarn com.**
-dontwarn org.**

-keep public class com.browser.bus.**






Components: Internals>Core
Labels: -Hotlist-Interop
Labels: Stability-Crash
Labels: TE-NeedsTriageHelp
Labels: -TE-NeedsTriageHelp Needs-Feedback
pattersondan2011@ Are you still seeing this issue in latest chrome version - 62.0.3202.84?
I ended up resolving this problem by adding efficient proguard rules for the chromium google library classes.  I was adding support for google mobile ads, and had added the line -keep public class com.google.android.gms.ads.** { *;} to the src/third_party/android_tools/proguard.flags.  This worked in dev mode because multidexing is enabled, but a release build would fail because multidexing is disabled, having this line caused the app to go well above the 64k limit with the other sdks we had added to the project.  So instead I ended up figuring out the direct classes that I needed for google mobile ads.  

-keep public class com.google.android.gms.common.api.Api* {*;}
-keep public class com.google.android.gms.common.api.CommonStatusCodes {*;}
-keep public class com.google.android.gms.common.api.GoogleApiClient* {*;}
-keep public class com.google.android.gms.common.api.PendingResult {*;}
-keep public class com.google.android.gms.common.api.ResultCallback {*;}
-keep public class com.google.android.gms.common.api.Status {*;}
-keep public class com.google.android.gms.common.ConnectionResult {*;}
-keep public class com.google.android.gms.common.GoogleApiAvailability {*;}
-keep public class com.google.android.gms.common.GooglePlayServicesUtil {*;}
-keep public class com.google.android.gms.common.GooglePlayServicesNotAvailableException {*;}
-keep public class com.google.android.gms.common.GooglePlayServicesRepairableException {*;}
-keep public class com.google.android.gms.ads.identifier.** {*;}

The above are the new lines I added, although not sure I need them all just for ads.  The last line might be all I needed, or last 5 lines, not sure anymore.  

By replacing -keep public class com.google.android.gms.ads.** { *;} with that last block of proguard rules I was able to knock off 10k or so methods, and it built.  

Unfortunately we are still on 54.0.2840.9 and will need to upgrade at some point... 
Project Member

Comment 7 by sheriffbot@chromium.org, Dec 1 2017

Cc: ligim...@chromium.org
Labels: -Needs-Feedback
Thank you for providing more feedback. Adding requester "ligimole@chromium.org" to the cc list and removing "Needs-Feedback" label.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Cc: pnangunoori@chromium.org
Labels: Needs-Feedback
pattersondan2011@ -- Request you to update your Chrome to latest #65.0.3325.109 and let us know your observations.
We upgraded to 65.0.3317.0, not running into any size limit errors, but we are close to hitting it with the third party sdks we are using.
Project Member

Comment 10 by sheriffbot@chromium.org, Apr 5 2018

Labels: -Needs-Feedback
Thank you for providing more feedback. Adding the requester to the cc list.

For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
Labels: TE-NeedsTriageHelp Needs-triage-Mobile Triaged-Mobile
Adding the label 'TE-NeedsTriageHelp' as the issue seems to be out of TE's scope.

Thanks!
Labels: -TE-NeedsTriageHelp Stability-Sheriff-Android
Looping to sheriff for further updates.

Comment 13 by ssid@chromium.org, May 25 2018

Status: WontFix (was: Unconfirmed)
There were lot of fixes made in chrome to not hit dex method limit:
https://bugs.chromium.org/p/chromium/issues/detail?id=820570

I suggest you start with updating your chromium branch.

Sign in to add a comment