Android Studio 1.0 'runProguard' vs 'minifyEnabled'
Asked Answered
D

0

16

During migration from Android Studio 0.9 to 1.0, I had to change the clause

buildTypes {
  release {
-     runProguard true
+     minifyEnabled true
}

as recommended here.

My app is running a standard Sync Adapter

public class SyncAdptr extends AbstractThreadedSyncAdapter {
  private static Context mCtx;

  public SyncAdptr(Context ctx, boolean autoInit) { 
    super(ctx, autoInit); mCtx = ctx; 
  }

  static void syncStart(Account gooAcct, String authority) {
    ...
    ContentResolver.setSyncAutomatically(gooAcct, authority, true);
    ...
  }
  ...
}

as a service:

public class SyncService extends Service {
  private static final Object sSyncAdapterLock = new Object();
  private static SyncAdptr sAndyScanSyncAdapter = null;

  @Override
  public void onCreate() {
    synchronized (sSyncAdapterLock) {
      if (sAndyScanSyncAdapter == null) {
        sAndyScanSyncAdapter = new SyncAdptr(getApplicationContext(), true);
      }
    }
  }
  @Override
  public IBinder onBind(Intent intent) {
    return sAndyScanSyncAdapter.getSyncAdapterBinder();
  }
}

It is a pretty standard boilerplate code that always worked.

By adding the 'minifyEnabled' clause as stated above, the synchronization stopped working with no error indication. I have tested it by removing the clause; the APK's size remained about the same as my debug version and sync was working. As soon as I plugged the 'minifyEnabled' in, the APK shrunk significantly (as expected) but the sync adapter quit again.

Any opinions? Suggestions?

UPDATE (3 months later):

I have progressed to 'Android Studio 1.1.0 AI-135.1740770 02/18/2015', but still no difference. The 'minifyEnabled = true' has an effect that the service never starts. Anybody knows where to find 'ProgGuard configuration dump' as suggesed in the comments?

Diva answered 22/12, 2014 at 15:34 Comment(11)
Any StackTrace or a ProgGuard configuration dump?Heroics
whats is your gradle version?Bab
I see 'Android Studio 1.0.2, build 135.1653844, don't know what Gradle ver is in it.Diva
in build.gradle you can see something like: dependencies { classpath 'com.android.tools.build:gradle:1.0.0' }Yearbook
yes, it is "classpath 'com.android.tools.build:gradle:1.0.0'"Diva
got any error code for the service?Rolf
@NickJian Sorry I dropped the problem some time ago and did not get back to it (doing other things). So it kind-of hangs in the air, or it may be gone since there are at least 2 more Android Studio releases since. Will report when I get back to it.Diva
Is Proguard removing or renaming a class or method required for your service? Look in the Proguard map output file.Stenophagous
Does the file have a name?Diva
Have you tried adding -keep class <package-name>.SyncService { public <methods> } to your proguard-rules.pro file to stop proguard from removing it. Also I eventually found the proguard output files. They are project-directory/proguard/ My build:grade has: release { minifyEnabled true proguardFiles 'proguard-rules.pro' }Sennet
That project is on back burner now, I will try it and will report back, Thanks.Diva

© 2022 - 2024 — McMap. All rights reserved.