質問

As we are hitting the dreaded method count limit we are forced to use Proguard during development to compile and dex our code with gradle. Although Proguard does its job pretty well and deploying the app works now, code changes doesn't seem to get picked up any more.

It always builds and deploys the very first build after having enabled Proguard for the first time. The only workaround is doing a clean (i.e. executing the gradle clean task) before building. Then all changes are picked up. However cleaning and doing a full build takes about 5 minutes, so this is no real alternative. Andriod Gradle Plugin is at version 0.9.2.

I couldn't find anything regarding this problem, so maybe someone here can help us.

EDIT: Strange thing is, that the compileDebugJava task is actually executed as the changes are detected, but they somehow don't land in the resulting APK:

Executing task ':MyApp:compileDebugJava' (up-to-date check took 0.03 secs) due to:
Input file /Users/ubuntudroid/projects/git/myapp/code/MyApp/build/exploded-aar/code/CoreLib/unspecified/classes.jar has changed.
Compiling with JDK Java compiler API.
:MyApp:compileDebugJava (Thread[Daemon,5,main]) completed. Took 0.529 secs.
:MyApp:proguardDebug (Thread[Daemon,5,main]) started.
:MyApp:proguardDebug
Skipping task ':MyApp:proguardDebug' as it is up-to-date (took 0.011 secs).
:MyApp:proguardDebug UP-TO-DATE
:MyApp:proguardDebug (Thread[Daemon,5,main]) completed. Took 0.013 secs.
:MyApp:dexDebug (Thread[Daemon,5,main]) started.
:MyApp:dexDebug
Skipping task ':MyApp:dexDebug' as it is up-to-date (took 0.0010 secs).
:MyApp:dexDebug UP-TO-DATE
:MyApp:dexDebug (Thread[Daemon,5,main]) completed. Took 0.0030 secs.

I think this is due to the proguardDebug task which is not executed and which eventually prevents the dexDebug task from running as the optimized code resulting from the proguardDebug task is taken from the cache. But why is the proguardDebug task already up-to-date?

役に立ちましたか?

解決

Okay, got it working by making sure, that the Proguard generated files are always cleared before assembling. This is necessary as the -forceprocessing flag supplied by the Proguard Gradle plugin unfortunately didn't have any effect.

android.buildTypes.all{ buildType ->
    task "${buildType.name}CleanProguardCache" (type: Delete)
    "${buildType.name}CleanProguardCache" {
        description = 'Cleans the Proguard cache...'
        delete 'build/classes-proguard', 'build/proguard'
    }

    tasks.getByPath(":${project.name}:assemble${buildType.name.capitalize()}").dependsOn "${buildType.name}CleanProguardCache"
}

The clean task is applied to all build types like explained here.

EDIT: As Xavier Ducrohet points out here there seems to be a bug in the Proguard task setup which causes the described problem. The fix will be part of the next Android Gradle Plugin version.

EDIT 2: As promised this bug is fixed in the Android Gradle Plugin 0.10.0. Therefore the workaround is obsolete for this plugin version.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top